Class TrivialArcRepositoryClient
- java.lang.Object
-
- dk.netarkivet.common.arcrepository.TrivialArcRepositoryClient
-
- All Implemented Interfaces:
ArcRepositoryClient
,HarvesterArcRepositoryClient
,PreservationArcRepositoryClient
,ViewerArcRepositoryClient
,AutoCloseable
- Direct Known Subclasses:
TestArcRepositoryClient
public class TrivialArcRepositoryClient extends Object implements ArcRepositoryClient
A minimal implementation of ArcRepositoryClient that just has one local directory that it keeps its files in, no checking no nothing.
-
-
Constructor Summary
Constructors Constructor Description TrivialArcRepositoryClient()
Constructor for this class.
-
Method Summary
All 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.void
close()
Call on shutdown to release external resources.File
correct(String replicaId, String checksum, File file, String credentials)
Method for correcting a file in a replica.BitarchiveRecord
get(String arcfile, long index)
Gets a single ARC record out of the ArcRepository.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)
Retrieves a file from an ArcRepository and places it in a local file.File
removeAndGetFile(String fileName, String bitarchiveId, String checksum, String credentials)
Remove a file from one part of the ArcRepository, retrieving a copy for security purposes.void
store(File file)
Store the given file in the ArcRepository.void
updateAdminChecksum(String filename, String checksum)
Updates the checksum kept in the ArcRepository for a given file.void
updateAdminData(String fileName, String bitarchiveId, ReplicaStoreState newval)
Updates the administrative data in the ArcRepository for a given file and replica.
-
-
-
Method Detail
-
close
public void close()
Call on shutdown to release external resources.- 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
-
store
public void store(File file) throws IOFailure, ArgumentNotValid
Store the given file in the ArcRepository. After storing, the file is 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 after the store operation.ArgumentNotValid
- if file parameter is null or file is not an existing file.
-
get
public BitarchiveRecord get(String arcfile, long index) throws ArgumentNotValid
Gets a single ARC record out of the ArcRepository.- Specified by:
get
in interfaceArcRepositoryClient
- Specified by:
get
in interfacePreservationArcRepositoryClient
- Specified by:
get
in interfaceViewerArcRepositoryClient
- 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
- if arcfile is null or empty, or index is negativeIOFailure
- If the get operation failed.
-
getFile
public void getFile(String arcfilename, Replica replica, File toFile)
Retrieves a file from an ArcRepository and places it in a local file.- 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 (not used in this implementation)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.
-
batch
public BatchStatus batch(FileBatchJob job, String replicaId, String... args)
Runs a batch batch job on each file in the ArcRepository.- 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 (not used in this implementation)args
- The arguments for the batchjob.- Returns:
- The status of the batch job after it ended.
-
updateAdminData
public void updateAdminData(String fileName, String bitarchiveId, ReplicaStoreState newval)
Updates the administrative data in the ArcRepository for a given file and replica. (not implemented)- Specified by:
updateAdminData
in interfaceArcRepositoryClient
- Specified by:
updateAdminData
in interfacePreservationArcRepositoryClient
- 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(String filename, 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 interfaceArcRepositoryClient
- Specified by:
updateAdminChecksum
in interfacePreservationArcRepositoryClient
- Parameters:
filename
- The name of a file stored in the ArcRepository.checksum
- The new checksum.
-
removeAndGetFile
public File removeAndGetFile(String fileName, String bitarchiveId, String checksum, 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 interfaceArcRepositoryClient
- Specified by:
removeAndGetFile
in interfacePreservationArcRepositoryClient
- Parameters:
fileName
- The name of the file to remove.bitarchiveId
- The id of the replica from which to remove the file (not used)checksum
- The checksum of the file to be removed (not used)credentials
- A string that shows that the user is allowed to perform this operation (not used)- Returns:
- A local copy of the file removed.
-
getAllChecksums
public File getAllChecksums(String replicaId)
Description copied from interface:PreservationArcRepositoryClient
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 list of ChecksumEntries which is the results of the GetAllChecksumMessage.
- See Also:
GetAllChecksumsMessage
-
getAllFilenames
public File getAllFilenames(String replicaId)
Description copied from interface:PreservationArcRepositoryClient
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 list of all the filenames within the archive of the given replica.
- See Also:
GetAllFilenamesMessage
-
correct
public File correct(String replicaId, String checksum, File file, String credentials)
Description copied from interface:PreservationArcRepositoryClient
Method for correcting a file in a replica.This is the checksum archive method for correcting a file entry in the archive. The bitarchive uses 'removeAndGetFile' followed by a 'store'.
- Specified by:
correct
in interfacePreservationArcRepositoryClient
- Parameters:
replicaId
- The identification of the replica.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 new file to replace the old one.credentials
- The password for allowing to remove a file entry in the archive.- Returns:
- The corrupted file from the archive.
-
getChecksum
public String getChecksum(String replicaId, String filename)
Description copied from interface:PreservationArcRepositoryClient
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 name 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. Or null if an error occurred.
-
-