dk.netarkivet.archive.arcrepository.distribute
Class JMSArcRepositoryClient

java.lang.Object
  extended by dk.netarkivet.common.distribute.Synchronizer
      extended by dk.netarkivet.archive.arcrepository.distribute.JMSArcRepositoryClient
All Implemented Interfaces:
ArcRepositoryClient, HarvesterArcRepositoryClient, PreservationArcRepositoryClient, ViewerArcRepositoryClient, 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
static java.lang.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 java.lang.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 java.lang.String ARCREPOSITORY_STORE_TIMEOUT
          settings.common.arcrepositoryClient.storeTimeout:
the setting for the timeout in milliseconds before retrying when calling ArcRepositoryClient.store(File).
protected  org.apache.commons.logging.Log log
          Logging output place.
 
Constructor Summary
protected JMSArcRepositoryClient()
          Adds this Synchronizer as listener on a jms connection.
 
Method Summary
 BatchStatus batch(FileBatchJob job, java.lang.String replicaId)
          Sends a BatchMessage to the Arcrepos queue and waits for the BatchReplyMessage reply before returning.
 void close()
          Removes this object as a JMS listener.
 void correct(java.lang.String replicaId, java.lang.String checksum, java.io.File file, java.lang.String credentials)
          Method for correcting an entry in a replica.
 BitarchiveRecord get(java.lang.String arcfile, long index)
          Sends a GetMessage on the "TheArcrepos" queue and waits for a reply.
 java.io.File getAllChecksums(java.lang.String replicaId)
          Retrieves all the checksum from the replica through a GetAllChecksumMessage.
 java.io.File getAllFilenames(java.lang.String replicaId)
          Retrieves the names of all the files in the replica through a GetAllFilenamesMessage.
 void getFile(java.lang.String arcfilename, Replica replica, java.io.File toFile)
          Synchronously retrieves a file from a bitarchive and places it in a local file.
static JMSArcRepositoryClient getInstance()
          Get an JMSArcRepositoryClient instance.
 java.io.File removeAndGetFile(java.lang.String fileName, java.lang.String bitarchiveId, java.lang.String checksum, java.lang.String credentials)
          Removes a file from the bitarchives, if given credentials and checksum are correct.
 void store(java.io.File file)
          Sends a StoreMessage via the synchronized JMS connection method sendAndWaitForOneReply().
 void updateAdminChecksum(java.lang.String filename, java.lang.String checksum)
          Request update of admin data to specific checksum.
 void updateAdminData(java.lang.String fileName, java.lang.String bitarchiveName, ReplicaStoreState newval)
          Request update of admin data to specific state.
 
Methods inherited from class dk.netarkivet.common.distribute.Synchronizer
onMessage, sendAndWaitForOneReply
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log
Logging output place.


ARCREPOSITORY_GET_TIMEOUT

public static final java.lang.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 java.lang.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.


ARCREPOSITORY_STORE_TIMEOUT

public static final java.lang.String ARCREPOSITORY_STORE_TIMEOUT
settings.common.arcrepositoryClient.storeTimeout:
the setting for the timeout in milliseconds before retrying when calling ArcRepositoryClient.store(File).

See Also:
Constant Field Values
Constructor Detail

JMSArcRepositoryClient

protected JMSArcRepositoryClient()
Adds this Synchronizer as listener on a jms connection.

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 interface ArcRepositoryClient
Specified by:
close in interface HarvesterArcRepositoryClient
Specified by:
close in interface PreservationArcRepositoryClient
Specified by:
close in interface ViewerArcRepositoryClient

get

public BitarchiveRecord get(java.lang.String arcfile,
                            long index)
                     throws ArgumentNotValid
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 interface ArcRepositoryClient
Specified by:
get in interface PreservationArcRepositoryClient
Specified by:
get in interface ViewerArcRepositoryClient
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(java.lang.String arcfilename,
                    Replica replica,
                    java.io.File toFile)
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 interface ArcRepositoryClient
Specified by:
getFile in interface PreservationArcRepositoryClient
Specified by:
getFile in interface ViewerArcRepositoryClient
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:
IOFailure - if there are problems getting a reply or the file could not be found.

store

public void store(java.io.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 interface ArcRepositoryClient
Specified by:
store in interface HarvesterArcRepositoryClient
Specified by:
store in interface PreservationArcRepositoryClient
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,
                         java.lang.String replicaId)
Sends a BatchMessage to the Arcrepos queue and waits for the BatchReplyMessage reply before returning.

Specified by:
batch in interface ArcRepositoryClient
Specified by:
batch in interface PreservationArcRepositoryClient
Specified by:
batch in interface ViewerArcRepositoryClient
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.
replicaId - The id of the archive to execute the job on
Returns:
A local batch status
Throws:
IOFailure - if no results can be read at all

updateAdminData

public void updateAdminData(java.lang.String fileName,
                            java.lang.String bitarchiveName,
                            ReplicaStoreState newval)
Request update of admin data to specific state.

Specified by:
updateAdminData in interface ArcRepositoryClient
Specified by:
updateAdminData in interface PreservationArcRepositoryClient
Parameters:
fileName - The file for which admin data should be updated.
bitarchiveName - The bitarchive for which admin data should be updated.
newval - The new value in admin data.
Throws:
IOFailure - If the reply to the request update timed out.

updateAdminChecksum

public void updateAdminChecksum(java.lang.String filename,
                                java.lang.String checksum)
Request update of admin data to specific checksum.

Specified by:
updateAdminChecksum in interface ArcRepositoryClient
Specified by:
updateAdminChecksum in interface PreservationArcRepositoryClient
Parameters:
filename - The file for which admin data should be updated.
checksum - The new checksum for the file
Throws:
IOFailure - If the reply to the request update timed out.

removeAndGetFile

public java.io.File removeAndGetFile(java.lang.String fileName,
                                     java.lang.String bitarchiveId,
                                     java.lang.String checksum,
                                     java.lang.String credentials)
Removes a file from the bitarchives, if given credentials and checksum are correct.

Specified by:
removeAndGetFile in interface ArcRepositoryClient
Specified by:
removeAndGetFile in interface PreservationArcRepositoryClient
Parameters:
fileName - The name of the file to delete
bitarchiveId - The id of the bitarchive to delete the file in
checksum - The checksum of the deleted file
credentials - The credentials used to delete the file
Returns:
The file that was removed
Throws:
ArgumentNotValid - if arguments are null or equal to the empty string
IOFailure - if we could not delete the remote file, ors there was no response to our RemoveAndGetFileMessage within the allotted time defined by the setting ARCREPOSITORY_STORE_TIMEOUT.

getAllChecksums

public java.io.File getAllChecksums(java.lang.String replicaId)
Retrieves all the checksum from the replica through a GetAllChecksumMessage. This is the checksum archive alternative to running a ChecksumBatchJob.

Specified by:
getAllChecksums in interface PreservationArcRepositoryClient
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. Or null if the message had a timeout.
See Also:
GetAllChecksumsMessage

getAllFilenames

public java.io.File getAllFilenames(java.lang.String replicaId)
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 interface PreservationArcRepositoryClient
Parameters:
replicaId - The id of the replica from which the list of filenames should be retrieved.
Returns:
A list of all the filenames within the archive of the given replica.
See Also:
GetAllFilenamesMessage

correct

public void correct(java.lang.String replicaId,
                    java.lang.String checksum,
                    java.io.File file,
                    java.lang.String credentials)
             throws IOFailure
Method for correcting an entry in a replica. This is done by sending a correct message to the replica.

Specified by:
correct in interface PreservationArcRepositoryClient
Parameters:
replicaId - The id of the replica to send the message.
checksum - The checksum of the wrong 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.
Throws:
IOFailure - If the message is not handled properly.