Class BitarchiveMonitor

  • All Implemented Interfaces:
    CleanupIF

    public class BitarchiveMonitor
    extends Observable
    implements CleanupIF
    Class representing the monitor for bitarchives. The monitor is used for sending out and combining the results of executing batch jobs.

    Registers outgoing batchjobs to bitarchives, and handles replies from bitarchives, finally notifying observers when all bitarchives have replied, or when the batch times out, after a time specified in settings.

    We wait for replies from bitarchives that are considered live when the batch begins. A bitarchive is considered live if we have heard any activity from it within a time specified in settings.

    • Field Detail

      • batchTimer

        protected final Timer batchTimer
        The timer for keeping track of running batchjobs.
    • Method Detail

      • getInstance

        public static BitarchiveMonitor getInstance()
        Method for retrieving the current instance. If no instance has been instantiated, then a new one will be created.
        Returns:
        The current instance of the BitarchiveMonitor.
      • signOfLife

        public void signOfLife​(String appID)
        Registers a sign of life from a bitarchive. This method logs when new bit archives present themselves.
        Parameters:
        appID - the ID of the bitarchive that generated the life sign
      • registerBatch

        public void registerBatch​(String requestID,
                                  ChannelID requestReplyTo,
                                  String bitarchiveBatchID,
                                  long timeout)
                           throws ArgumentNotValid
        Register a new batch sent to the bitarchives.

        This registers a new batchstatus object, with a list of live bitarchives awaiting reply, and a timer task letting the job time out after the specified time.

        Parameters:
        requestID - The ID of the batch request.
        requestReplyTo - The replyTo channel of the batch request.
        bitarchiveBatchID - The ID of the batch job sent on to the bit archives.
        timeout - Timeout of specific batch job.
        Throws:
        ArgumentNotValid - If any argument is null, or either string is empty.
      • bitarchiveReply

        public void bitarchiveReply​(String bitarchiveBatchID,
                                    String bitarchiveID,
                                    int noOfFilesProcessed,
                                    Collection<File> filesFailed,
                                    RemoteFile remoteFile,
                                    String errMsg,
                                    List<FileBatchJob.ExceptionOccurrence> exceptions)
                             throws ArgumentNotValid
        Handle a reply received from a bitarchive.

        This method registers the information from the bitarchive in the batch status for this job, if any (otherwise logs and quits).

        If this is the last bitarchive we were missing replies from, notify observers with the batch status for this job.

        TODO why are the 'exceptions' argument not used?

        Parameters:
        bitarchiveBatchID - The ID of the batch job sent on to the bit archives.
        bitarchiveID - The ID of the replying bitarchive.
        noOfFilesProcessed - The number of files the bitarchive has processed.
        filesFailed - A collection of filenames of failed files in that bitarchive. Might be null if no files failed.
        remoteFile - A remote pointer to a file with results from that bitarchive. Might be null if job was not OK.
        errMsg - An error message, if the job was not successful on the bitarchive, or null for none.
        exceptions - A list of exceptions caught during batch processing.
        Throws:
        ArgumentNotValid - If either ID is null.
      • cleanup

        public void cleanup()
        Closes this BitarchiveMonitor cleanly. Currently does nothing.
        Specified by:
        cleanup in interface CleanupIF