dk.netarkivet.archive.arcrepository.bitpreservation
Class DatabasePreservationState

java.lang.Object
  extended by dk.netarkivet.archive.arcrepository.bitpreservation.DatabasePreservationState
All Implemented Interfaces:
PreservationState

public class DatabasePreservationState
extends java.lang.Object
implements PreservationState

This class contains the preservation data based on the database data of a given filename. Contains the ReplicaFileInfos corresponding to the file.


Constructor Summary
DatabasePreservationState(java.lang.String fileName, java.util.List<ReplicaFileInfo> rfis)
          Constructor.
 
Method Summary
 boolean fileIsMissing(Replica replica)
          Check if the file is missing from a replica.
 java.lang.String getAdminChecksum()
          Get the MD5 checksum stored in the admin data.
 java.lang.String getAdminReplicaState(Replica replica)
          Get the status of the file in a replica, according to the admin data.
 java.lang.String getFilename()
          Get the filename, this FilePreservationState is about.
 Replica getReferenceBitarchive()
          Returns a reference to a replica that contains a version of the file with the correct checksum.
 java.lang.String getReferenceCheckSum()
          THIS IS VOTING! Retrieve checksum that the majority of checksum references replicas agree upon.
 java.util.List<java.lang.String> getReplicaChecksum(Replica replica)
          Get the checksum of this file in a specific replica.
 java.lang.String getUniqueChecksum(Replica replica)
          Get a checksum that the whole replica agrees upon, or else "".
 boolean isAdminCheckSumOk()
          Returns true if the checksum reported by admin data is equal to the majority checksum.
 boolean isAdminDataOk()
          INHERITED DUMMY FUNCTION!
 java.lang.String toString()
          Returns a human-readable representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DatabasePreservationState

public DatabasePreservationState(java.lang.String fileName,
                                 java.util.List<ReplicaFileInfo> rfis)
                          throws ArgumentNotValid
Constructor.

Parameters:
fileName - The name of the file.
rfis - A list of the ReplicaFileInfo entries in the database for the given file.
Throws:
ArgumentNotValid - If the filename is null or the empty string, or if the list of ReplicaFileInfos are null or empty.
Method Detail

getReplicaChecksum

public java.util.List<java.lang.String> getReplicaChecksum(Replica replica)
                                                    throws ArgumentNotValid
Get the checksum of this file in a specific replica.

Specified by:
getReplicaChecksum in interface PreservationState
Parameters:
replica - The replica to get the checksum from.
Returns:
A list of the checksums for the file within the replica (only more than one if there is duplicates in a bitarchive replica). An empty list is returned if no file is present or if an error occurred.
Throws:
ArgumentNotValid - If the replica is null.

getAdminChecksum

public java.lang.String getAdminChecksum()
Get the MD5 checksum stored in the admin data. Inherited dummy function. No admin data for database instance, thus no admin data checksum.

Specified by:
getAdminChecksum in interface PreservationState
Returns:
Checksum value as found in the admin data given at creation.

getAdminReplicaState

public java.lang.String getAdminReplicaState(Replica replica)
                                      throws ArgumentNotValid
Get the status of the file in a replica, according to the admin data. This returns the status as a string for presentation purposes only.

Specified by:
getAdminReplicaState in interface PreservationState
Parameters:
replica - The replica to get status for
Returns:
Status that the admin data knows for this file in the replica.
Throws:
ArgumentNotValid - If the replica is null.

isAdminDataOk

public boolean isAdminDataOk()
INHERITED DUMMY FUNCTION!

Specified by:
isAdminDataOk in interface PreservationState
Returns:
true, since a non-existing admin.data is OK for the database instance.

getReferenceBitarchive

public Replica getReferenceBitarchive()
Returns a reference to a replica that contains a version of the file with the correct checksum. The correct checksum is defined as the checksum that the majority of the replica and admin data agree upon. If no replica exists with a correct version of the file null is returned.

Specified by:
getReferenceBitarchive in interface PreservationState
Returns:
the name of the reference replica or null if no reference exists.

getUniqueChecksum

public java.lang.String getUniqueChecksum(Replica replica)
                                   throws ArgumentNotValid
Get a checksum that the whole replica agrees upon, or else "".

Specified by:
getUniqueChecksum in interface PreservationState
Parameters:
replica - A replica to get checksum for this file from
Returns:
The checksum for this file in the replica, if all machines that have that file agree, otherwise "". If no checksums are found, also returns "".
Throws:
ArgumentNotValid - If the replica is null.

fileIsMissing

public boolean fileIsMissing(Replica replica)
                      throws ArgumentNotValid
Check if the file is missing from a replica.

Specified by:
fileIsMissing in interface PreservationState
Parameters:
replica - the replica to check
Returns:
true if the file is missing from the replica
Throws:
ArgumentNotValid - If the replica is null.

getReferenceCheckSum

public java.lang.String getReferenceCheckSum()
THIS IS VOTING! Retrieve checksum that the majority of checksum references replicas agree upon. TODO Voting is already done by the DatabasedActiveBitPreservation. Thus replace with finding an entry with checksum-status = OK.

Specified by:
getReferenceCheckSum in interface PreservationState
Returns:
the reference checksum or "" if no majority exists

isAdminCheckSumOk

public boolean isAdminCheckSumOk()
Returns true if the checksum reported by admin data is equal to the majority checksum. If no majority checksum exists true is also returned. When this method returns false it is possible to correct the admin checksum using the majority checksum - when true is returned no better checksum exists for admin data.

Specified by:
isAdminCheckSumOk in interface PreservationState
Returns:
true, if the checksum reported by admin data is equal to the majority checksum

toString

public java.lang.String toString()
Returns a human-readable representation of this object. Do not depend on this format for anything automated, as it may change at any time.

Specified by:
toString in interface PreservationState
Overrides:
toString in class java.lang.Object
Returns:
Description of this object.

getFilename

public java.lang.String getFilename()
Get the filename, this FilePreservationState is about. Needed to get at the filename given to constructor, and allow for a better datastructure.

Specified by:
getFilename in interface PreservationState
Returns:
the filename