001/*
002 * #%L
003 * Netarchivesuite - common
004 * %%
005 * Copyright (C) 2005 - 2018 The Royal Danish 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 extends AutoCloseable{
036
037    /** Call on shutdown to release external resources. */
038    @Override
039    void close();
040
041    /**
042     * Gets a single ARC record out of the ArcRepository.
043     *
044     * @param arcfile The name of a file containing the desired record.
045     * @param index The offset of the desired record in the file
046     * @return a BitarchiveRecord-object, or null if request times out or object is not found.
047     * @throws ArgumentNotValid If the get operation failed.
048     */
049    BitarchiveRecord get(String arcfile, long index) throws ArgumentNotValid;
050
051    /**
052     * Retrieves a file from an ArcRepository and places it in a local file.
053     *
054     * @param arcfilename Name of the arcfile to retrieve.
055     * @param replica The bitarchive to retrieve the data from.
056     * @param toFile Filename of a place where the file fetched can be put.
057     * @throws IOFailure if there are problems getting a reply or the file could not be found.
058     */
059    void getFile(String arcfilename, Replica replica, File toFile);
060
061    /**
062     * Runs a batch batch job on each file in the ArcRepository.
063     *
064     * @param job An object that implements the FileBatchJob interface. The initialize() method will be called before
065     * processing and the finish() method will be called afterwards. The process() method will be called with each File
066     * entry. An optional function postProcess() allows handling the combined results of the batchjob, e.g. summing the
067     * results, sorting, etc.
068     * @param replicaId The archive to execute the job on.
069     * @param args The arguments for the batchjob.
070     * @return The status of the batch job after it ended.
071     */
072    BatchStatus batch(FileBatchJob job, String replicaId, String... args);
073
074}