Class JMSArcRepositoryClient
- java.lang.Object
-
- dk.netarkivet.common.distribute.Synchronizer
-
- dk.netarkivet.archive.arcrepository.distribute.JMSArcRepositoryClient
-
- All Implemented Interfaces:
ArcRepositoryClient
,HarvesterArcRepositoryClient
,PreservationArcRepositoryClient
,ViewerArcRepositoryClient
,AutoCloseable
,javax.jms.MessageListener
public class JMSArcRepositoryClient extends Synchronizer implements ArcRepositoryClient
Client side usage of an arc repository. All requests are forwarded to the ArcRepositoryServer over the network. get and store messages are retried a number of time before giving up, and will timeout after a specified time.
-
-
Field Summary
Fields Modifier and Type Field Description static String
ARCREPOSITORY_GET_TIMEOUT
settings.common.arcrepositoryClient.getTimeout:
The setting for how many milliseconds we will wait before giving up on a lookup request to the Arcrepository.static String
ARCREPOSITORY_STORE_RETRIES
settings.common.arcrepositoryClient.storeRetries:
The setting for the number of times to try sending a store message before failing, including the first attempt.static String
ARCREPOSITORY_STORE_TIMEOUT
settings.common.arcrepositoryClient.storeTimeout:
the setting for the timeout in milliseconds before retrying when callingArcRepositoryClient.store(File)
.protected static org.slf4j.Logger
log
Logging output place.
-
Constructor Summary
Constructors Modifier Constructor Description protected
JMSArcRepositoryClient()
Adds this Synchronizer as listener on a jms connection.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BatchStatus
batch(FileBatchJob job, String replicaId, String... args)
Runs a batch batch job on each file in the ArcRepository.BatchStatus
batch(FileBatchJob job, String replicaId, String batchId, String... args)
Runs a batch job on each file in the ArcRepository.void
close()
Removes this object as a JMS listener.File
correct(String replicaId, String checksum, File file, String credentials)
Method for correcting an entry in a replica.BitarchiveRecord
get(String arcfile, long index)
Sends a GetMessage on the "TheArcrepos" queue and waits for a reply.File
getAllChecksums(String replicaId)
Retrieves all the checksum from the replica through a GetAllChecksumMessage.File
getAllFilenames(String replicaId)
Retrieves the names of all the files in the replica through a GetAllFilenamesMessage.String
getChecksum(String replicaId, String filename)
Retrieves the checksum of a specific file.void
getFile(String arcfilename, Replica replica, File toFile)
Synchronously retrieves a file from a bitarchive and places it in a local file.static JMSArcRepositoryClient
getInstance()
Get an JMSArcRepositoryClient instance.File
removeAndGetFile(String fileName, String bitarchiveId, String checksum, String credentials)
Removes a file from the bitarchives, if given credentials and checksum are correct.void
store(File file)
Sends a StoreMessage via the synchronized JMS connection method sendAndWaitForOneReply().void
updateAdminChecksum(String filename, String checksum)
Request update of admin data to specific checksum.void
updateAdminData(String fileName, String replicaId, ReplicaStoreState newval)
Request update of admin data to specific state.-
Methods inherited from class dk.netarkivet.common.distribute.Synchronizer
onMessage, sendAndWaitForOneReply
-
-
-
-
Field Detail
-
log
protected static final org.slf4j.Logger log
Logging output place.
-
ARCREPOSITORY_GET_TIMEOUT
public static final String ARCREPOSITORY_GET_TIMEOUT
settings.common.arcrepositoryClient.getTimeout:
The setting for how many milliseconds we will wait before giving up on a lookup request to the Arcrepository.- See Also:
- Constant Field Values
-
ARCREPOSITORY_STORE_RETRIES
public static final String ARCREPOSITORY_STORE_RETRIES
settings.common.arcrepositoryClient.storeRetries:
The setting for the number of times to try sending a store message before failing, including the first attempt.- See Also:
- Constant Field Values
-
ARCREPOSITORY_STORE_TIMEOUT
public static final String ARCREPOSITORY_STORE_TIMEOUT
settings.common.arcrepositoryClient.storeTimeout:
the setting for the timeout in milliseconds before retrying when callingArcRepositoryClient.store(File)
.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static JMSArcRepositoryClient getInstance()
Get an JMSArcRepositoryClient instance. This is guaranteed to be a singleton.- Returns:
- an JMSArcRepositoryClient instance.
-
close
public void close()
Removes this object as a JMS listener.- Specified by:
close
in interfaceArcRepositoryClient
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceHarvesterArcRepositoryClient
- Specified by:
close
in interfacePreservationArcRepositoryClient
- Specified by:
close
in interfaceViewerArcRepositoryClient
-
get
public BitarchiveRecord get(String arcfile, long index) throws ArgumentNotValid, IOFailure
Sends a GetMessage on the "TheArcrepos" queue and waits for a reply. This is a blocking call. Returns null if no message is returned within Settings.ARCREPOSITORY_GET_TIMEOUT- Specified by:
get
in interfaceArcRepositoryClient
- Specified by:
get
in interfacePreservationArcRepositoryClient
- Specified by:
get
in interfaceViewerArcRepositoryClient
- Parameters:
arcfile
- The name of a file.index
- The offset of the wanted record in the file- Returns:
- a BitarchiveRecord-object or null if request times out or object is not found.
- Throws:
ArgumentNotValid
- If the given arcfile is null or empty, or the given index is negative.IOFailure
- If a wrong message is returned or the get operation failed.
-
getFile
public void getFile(String arcfilename, Replica replica, File toFile) throws ArgumentNotValid, IOFailure
Synchronously retrieves a file from a bitarchive and places it in a local file. This is the interface for sending GetFileMessage on the "TheArcrepos" queue. This is a blocking call.- Specified by:
getFile
in interfaceArcRepositoryClient
- Specified by:
getFile
in interfacePreservationArcRepositoryClient
- Specified by:
getFile
in interfaceViewerArcRepositoryClient
- Parameters:
arcfilename
- Name of the arcfile to retrieve.replica
- The bitarchive to retrieve the data from.toFile
- Filename of a place where the file fetched can be put.- Throws:
ArgumentNotValid
- If the arcfilename are null or empty, or if either replica or toFile is null.IOFailure
- if there are problems getting a reply or the file could not be found.
-
store
public void store(File file) throws IOFailure, ArgumentNotValid
Sends a StoreMessage via the synchronized JMS connection method sendAndWaitForOneReply(). After a successful storage operation, both the local copy of the file and the copy on the ftp server are deleted.- Specified by:
store
in interfaceArcRepositoryClient
- Specified by:
store
in interfaceHarvesterArcRepositoryClient
- Specified by:
store
in interfacePreservationArcRepositoryClient
- Parameters:
file
- A file to be stored. Must exist.- Throws:
IOFailure
- thrown if store is unsuccessful, or failed to clean up files locally or on the ftp server after the store operation.ArgumentNotValid
- if file parameter is null or file is not an existing file.
-
batch
public BatchStatus batch(FileBatchJob job, String replicaId, String... args)
Runs a batch batch job on each file in the ArcRepository.Note: The id for the batchjob is the empty string, which removes the possibility of terminating the batchjob remotely while it is running.
- Specified by:
batch
in interfaceArcRepositoryClient
- Specified by:
batch
in interfacePreservationArcRepositoryClient
- Specified by:
batch
in interfaceViewerArcRepositoryClient
- Parameters:
job
- An object that implements the FileBatchJob interface. The initialize() method will be called before processing and the finish() method will be called afterwards. The process() method will be called with each File entry. An optional function postProcess() allows handling the combined results of the batchjob, e.g. summing the results, sorting, etc.replicaId
- The archive to execute the job on.args
- The arguments for the batchjob.- Returns:
- The status of the batch job after it ended.
-
batch
public BatchStatus batch(FileBatchJob job, String replicaId, String batchId, String... args) throws IOFailure, ArgumentNotValid
Runs a batch job on each file in the ArcRepository.- Parameters:
job
- An object that implements the FileBatchJob interface. The initialize() method will be called before processing and the finish() method will be called afterwards. The process() method will be called with each File entry. An optional function postProcess() allows handling the combined results of the batchjob, e.g. summing the results, sorting, etc.replicaId
- The archive to execute the job on.args
- The arguments for the batchjob. This is allowed to be null.batchId
- The id for the batch process.- Returns:
- The status of the batch job after it ended.
- Throws:
ArgumentNotValid
- If the job is null or the replicaId is either null or the empty string.IOFailure
- If no result file is returned.
-
updateAdminData
public void updateAdminData(String fileName, String replicaId, ReplicaStoreState newval) throws ArgumentNotValid, IOFailure
Request update of admin data to specific state.- Specified by:
updateAdminData
in interfaceArcRepositoryClient
- Specified by:
updateAdminData
in interfacePreservationArcRepositoryClient
- Parameters:
fileName
- The file for which admin data should be updated.replicaId
- The id if the replica that the administrative data for fileName is wrong for.newval
- The new value in admin data.- Throws:
ArgumentNotValid
- If one of the arguments are invalid (null or empty string).IOFailure
- If the reply to the request update timed out.
-
updateAdminChecksum
public void updateAdminChecksum(String filename, String checksum)
Request update of admin data to specific checksum.- Specified by:
updateAdminChecksum
in interfaceArcRepositoryClient
- Specified by:
updateAdminChecksum
in interfacePreservationArcRepositoryClient
- Parameters:
filename
- The file for which admin data should be updated.checksum
- The new checksum for the file
-
removeAndGetFile
public File removeAndGetFile(String fileName, String bitarchiveId, String checksum, String credentials) throws IOFailure, ArgumentNotValid
Removes a file from the bitarchives, if given credentials and checksum are correct.- Specified by:
removeAndGetFile
in interfaceArcRepositoryClient
- Specified by:
removeAndGetFile
in interfacePreservationArcRepositoryClient
- Parameters:
fileName
- The name of the file to deletebitarchiveId
- The id of the bitarchive to delete the file inchecksum
- The checksum of the deleted filecredentials
- The credentials used to delete the file- Returns:
- The file that was removed
- Throws:
ArgumentNotValid
- if arguments are null or equal to the empty stringIOFailure
- if we could not delete the remote file, or there was no response to our RemoveAndGetFileMessage within the allotted time defined by the settingARCREPOSITORY_STORE_TIMEOUT
.
-
getAllChecksums
public File getAllChecksums(String replicaId) throws IOFailure, ArgumentNotValid
Retrieves all the checksum from the replica through a GetAllChecksumMessage.This is the checksum archive alternative to running a ChecksumBatchJob.
- Specified by:
getAllChecksums
in interfacePreservationArcRepositoryClient
- Parameters:
replicaId
- The id of the replica from which the checksums should be retrieved.- Returns:
- A file containing filename and checksum of all the files in an archive in the same format as a ChecksumJob.
- Throws:
IOFailure
- If the reply is not of type GetAllChecksumsMessage or if the file could not properly be retrieved from the reply message or if the message timed out.ArgumentNotValid
- If the replicaId is null or empty.- See Also:
GetAllChecksumsMessage
-
getAllFilenames
public File getAllFilenames(String replicaId) throws ArgumentNotValid, IOFailure
Retrieves the names of all the files in the replica through a GetAllFilenamesMessage.This is the checksum archive alternative to running a FilelistBatchJob.
- Specified by:
getAllFilenames
in interfacePreservationArcRepositoryClient
- Parameters:
replicaId
- The id of the replica from which the list of filenames should be retrieved.- Returns:
- A file with all the filenames within the archive of the given replica. A null is returned if the message timeout.
- Throws:
IOFailure
- If the reply is not of type GetAllFilenamesMessage or if the file could not properly be retrieved from the reply messageArgumentNotValid
- If the replicaId is null or empty.- See Also:
GetAllFilenamesMessage
-
getChecksum
public String getChecksum(String replicaId, String filename) throws ArgumentNotValid, IOFailure
Retrieves the checksum of a specific file.This is the checksum archive alternative to running a ChecksumJob limited to a specific file.
- Specified by:
getChecksum
in interfacePreservationArcRepositoryClient
- Parameters:
replicaId
- The ID of the replica to send the message.filename
- The name of the file for whom the checksum should be retrieved.- Returns:
- The checksum of the file in the replica.
- Throws:
IOFailure
- If the reply is not of type GetChecksumMessage. Or if the message timed out.ArgumentNotValid
- If either the replicaId of the filename is null or empty.
-
correct
public File correct(String replicaId, String checksum, File file, String credentials) throws IOFailure, ArgumentNotValid
Method for correcting an entry in a replica. This is done by sending a correct message to the replica.The file which is removed from the replica is put into the tempDir.
- Specified by:
correct
in interfacePreservationArcRepositoryClient
- Parameters:
replicaId
- The id of the replica to send the message.checksum
- The checksum of the corrupt entry in the archive. It is important to validate that the checksum actually is wrong before correcting the entry.file
- The file to correct the entry in the archive of the replica.credentials
- A string with the password for allowing changes inside an archive. If it does not correspond to the credentials of the archive, the correction will not be allowed.- Returns:
- The corrupted file from the archive.
- Throws:
IOFailure
- If the message is not handled properly.ArgumentNotValid
- If the replicaId, the checksum or the credentials are either null or empty, or if file is null.
-
-