001/*
002 * #%L
003 * Netarchivesuite - common
004 * %%
005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library,
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023package dk.netarkivet.common.distribute.arcrepository;
024
025import java.io.File;
026
027import dk.netarkivet.common.exceptions.ArgumentNotValid;
028import dk.netarkivet.common.exceptions.IOFailure;
029import dk.netarkivet.common.utils.batch.FileBatchJob;
030
031/**
032 * Implements the Facade pattern to shield off the methods in JMSArcRepositoryClient not to be used by the bit
033 * preservation system.
034 */
035public interface ViewerArcRepositoryClient {
036
037    /** Call on shutdown to release external resources. */
038    void close();
039
040    /**
041     * Gets a single ARC record out of the ArcRepository.
042     *
043     * @param arcfile The name of a file containing the desired record.
044     * @param index The offset of the desired record in the file
045     * @return a BitarchiveRecord-object, or null if request times out or object is not found.
046     * @throws ArgumentNotValid If the get operation failed.
047     */
048    BitarchiveRecord get(String arcfile, long index) throws ArgumentNotValid;
049
050    /**
051     * Retrieves a file from an ArcRepository and places it in a local file.
052     *
053     * @param arcfilename Name of the arcfile to retrieve.
054     * @param replica The bitarchive to retrieve the data from.
055     * @param toFile Filename of a place where the file fetched can be put.
056     * @throws IOFailure if there are problems getting a reply or the file could not be found.
057     */
058    void getFile(String arcfilename, Replica replica, File toFile);
059
060    /**
061     * Runs a batch batch job on each file in the ArcRepository.
062     *
063     * @param job An object that implements the FileBatchJob interface. The initialize() method will be called before
064     * processing and the finish() method will be called afterwards. The process() method will be called with each File
065     * entry. An optional function postProcess() allows handling the combined results of the batchjob, e.g. summing the
066     * results, sorting, etc.
067     * @param replicaId The archive to execute the job on.
068     * @param args The arguments for the batchjob.
069     * @return The status of the batch job after it ended.
070     */
071    BatchStatus batch(FileBatchJob job, String replicaId, String... args);
072
073}