dk.netarkivet.common.distribute.arcrepository
Class LocalArcRepositoryClient

java.lang.Object
  extended by dk.netarkivet.common.distribute.arcrepository.LocalArcRepositoryClient
All Implemented Interfaces:
ArcRepositoryClient, HarvesterArcRepositoryClient, PreservationArcRepositoryClient, ViewerArcRepositoryClient

public class LocalArcRepositoryClient
extends java.lang.Object
implements ArcRepositoryClient

A simple implementation of ArcRepositoryClient that just has a number of local directories that it keeps its files in. It doesn't implement credentials checks or checksum storing.


Constructor Summary
LocalArcRepositoryClient()
          Create a new LocalArcRepositoryClient based on current settings.
 
Method Summary
 BatchStatus batch(FileBatchJob job, java.lang.String replicaId, java.lang.String... args)
          Runs a batch job on each file in the ArcRepository.
 void close()
          Call on shutdown to release external resources.
 java.io.File correct(java.lang.String replicaId, java.lang.String checksum, java.io.File file, java.lang.String credentials)
          Method for correcting a bad entry.
 BitarchiveRecord get(java.lang.String arcfile, long index)
          Gets a single ARC record out of the ArcRepository.
 java.io.File getAllChecksums(java.lang.String replicaId)
          Method for retrieving the checksums of all the files of the replica.
 java.io.File getAllFilenames(java.lang.String replicaId)
          Method for retrieving all the filenames of the replica.
 java.lang.String getChecksum(java.lang.String replicaId, java.lang.String filename)
          Method for finding the checksum of a file.
 void getFile(java.lang.String arcfilename, Replica replica, java.io.File toFile)
          Retrieves a file from an ArcRepository and places it in a local file.
 java.io.File removeAndGetFile(java.lang.String fileName, java.lang.String bitarchiveId, java.lang.String checksum, java.lang.String credentials)
          Remove a file from one part of the ArcRepository, retrieving a copy for security purposes.
 void store(java.io.File file)
          Store the given file in the ArcRepository.
 void updateAdminChecksum(java.lang.String filename, java.lang.String checksum)
          Updates the checksum kept in the ArcRepository for a given file.
 void updateAdminData(java.lang.String fileName, java.lang.String bitarchiveId, ReplicaStoreState newval)
          Updates the administrative data in the ArcRepository for a given file and replica.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalArcRepositoryClient

public LocalArcRepositoryClient()
Create a new LocalArcRepositoryClient based on current settings.

Method Detail

close

public void close()
Call on shutdown to release external resources.

Specified by:
close in interface ArcRepositoryClient
Specified by:
close in interface HarvesterArcRepositoryClient
Specified by:
close in interface PreservationArcRepositoryClient
Specified by:
close in interface ViewerArcRepositoryClient

store

public void store(java.io.File file)
           throws IOFailure,
                  ArgumentNotValid
Store the given file in the ArcRepository. After storing, the file is 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 after the store operation.
IllegalState - if file already exists.
ArgumentNotValid - if file parameter is null or file is not an existing file.

get

public BitarchiveRecord get(java.lang.String arcfile,
                            long index)
                     throws ArgumentNotValid
Gets a single ARC record out of the ArcRepository.

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 containing the desired record.
index - The offset of the desired record in the file
Returns:
a BitarchiveRecord-object, or null if request times out or object is not found.
Throws:
ArgumentNotValid - on null or empty filenames, or if index is negative.
IOFailure - If the get operation failed.

getFile

public void getFile(java.lang.String arcfilename,
                    Replica replica,
                    java.io.File toFile)
Retrieves a file from an ArcRepository and places it in a local file.

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:
ArgumentNotValid - if arcfilename is null or empty, or if toFile is null
IOFailure - if there are problems reading or writing file, or the file with the given arcfilename could not be found.

batch

public BatchStatus batch(FileBatchJob job,
                         java.lang.String replicaId,
                         java.lang.String... args)
                  throws ArgumentNotValid,
                         IOFailure
Runs a batch job on each file in the ArcRepository.

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. 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 can be null.
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 a problem occurs during processing the batchjob.

updateAdminData

public void updateAdminData(java.lang.String fileName,
                            java.lang.String bitarchiveId,
                            ReplicaStoreState newval)
Updates the administrative data in the ArcRepository for a given file and replica.

Specified by:
updateAdminData in interface ArcRepositoryClient
Specified by:
updateAdminData in interface PreservationArcRepositoryClient
Parameters:
fileName - The name of a file stored in the ArcRepository.
bitarchiveId - The id of the replica that the administrative data for fileName is wrong for.
newval - What the administrative data will be updated to.

updateAdminChecksum

public void updateAdminChecksum(java.lang.String filename,
                                java.lang.String checksum)
Updates the checksum kept in the ArcRepository for a given file. It is the responsibility of the ArcRepository implementation to ensure that this checksum matches that of the underlying files.

Specified by:
updateAdminChecksum in interface ArcRepositoryClient
Specified by:
updateAdminChecksum in interface PreservationArcRepositoryClient
Parameters:
filename - The name of a file stored in the ArcRepository.
checksum - The new checksum.

removeAndGetFile

public java.io.File removeAndGetFile(java.lang.String fileName,
                                     java.lang.String bitarchiveId,
                                     java.lang.String checksum,
                                     java.lang.String credentials)
Remove a file from one part of the ArcRepository, retrieving a copy for security purposes. This is typically used when repairing a file that has been corrupted.

Specified by:
removeAndGetFile in interface ArcRepositoryClient
Specified by:
removeAndGetFile in interface PreservationArcRepositoryClient
Parameters:
fileName - The name of the file to remove.
bitarchiveId - The id of the replica from which to remove the file. Not used in this implementation, may be null.
checksum - The checksum of the file to be removed.
credentials - A string that shows that the user is allowed to perform this operation.
Returns:
A local copy of the file removed.
Throws:
ArgumentNotValid - On null or empty parameters for fileName, checksum or credentials.
IOFailure - On IO trouble.
PermissionDenied - On wrong MD5 sum or wrong credentials.

getAllChecksums

public java.io.File getAllChecksums(java.lang.String replicaId)
                             throws IOFailure,
                                    ArgumentNotValid
Method for retrieving the checksums of all the files of the replica.

Specified by:
getAllChecksums in interface PreservationArcRepositoryClient
Parameters:
replicaId - Inherited dummy argument.
Returns:
A file containing the names and checksum of all the files in the system.
Throws:
ArgumentNotValid - If the replicaId is either null or the empty string.
IOFailure - If an unexpected IOException is caught.
See Also:
GetAllChecksumsMessage

getAllFilenames

public java.io.File getAllFilenames(java.lang.String replicaId)
                             throws IOFailure,
                                    ArgumentNotValid
Method for retrieving all the filenames of the replica.

Specified by:
getAllFilenames in interface PreservationArcRepositoryClient
Parameters:
replicaId - Inherited dummy argument.
Returns:
A file containing the names of all the files.
Throws:
ArgumentNotValid - If the replicaId is either null or empty.
IOFailure - If an IOException is caught.
See Also:
GetAllFilenamesMessage

correct

public java.io.File correct(java.lang.String replicaId,
                            java.lang.String checksum,
                            java.io.File file,
                            java.lang.String credentials)
                     throws ArgumentNotValid,
                            PermissionDenied
Method for correcting a bad entry. Calls 'removeAndGetFile' followed by 'store'.

Specified by:
correct in interface PreservationArcRepositoryClient
Parameters:
replicaId - Inherited dummy argument.
checksum - The checksum of the bad entry.
file - The new file to replace the bad entry.
credentials - The 'password' to allow changing the archive.
Returns:
The bad entry file.
Throws:
ArgumentNotValid - If one of the arguments are null, or if a string is empty.
PermissionDenied - If the credentials or checksum are invalid.

getChecksum

public java.lang.String getChecksum(java.lang.String replicaId,
                                    java.lang.String filename)
                             throws ArgumentNotValid
Method for finding the checksum of a file.

Specified by:
getChecksum in interface PreservationArcRepositoryClient
Parameters:
replicaId - Inherited dummy variable.
filename - The name of the file to calculate the checksum.
Returns:
The checksum of the file, or the empty string if the file was not found or an error occured.
Throws:
ArgumentNotValid - If the replicaId or the filename is either null or the empty string.