001/*
002 * #%L
003 * Netarchivesuite - archive
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.archive.distribute;
024
025import dk.netarkivet.archive.bitarchive.distribute.BatchMessage;
026import dk.netarkivet.archive.bitarchive.distribute.GetFileMessage;
027import dk.netarkivet.archive.bitarchive.distribute.GetMessage;
028import dk.netarkivet.archive.bitarchive.distribute.RemoveAndGetFileMessage;
029import dk.netarkivet.archive.checksum.distribute.CorrectMessage;
030import dk.netarkivet.archive.checksum.distribute.GetAllChecksumsMessage;
031import dk.netarkivet.archive.checksum.distribute.GetAllFilenamesMessage;
032import dk.netarkivet.archive.checksum.distribute.GetChecksumMessage;
033import dk.netarkivet.common.distribute.ChannelID;
034import dk.netarkivet.common.distribute.RemoteFile;
035import dk.netarkivet.common.distribute.arcrepository.ReplicaType;
036import dk.netarkivet.common.utils.batch.FileBatchJob;
037
038/**
039 * Interface for the replica clients. To be used by the BitarchiveClient and the ChecksumClient.
040 */
041public interface ReplicaClient {
042
043    /**
044     * Method for sending a batch message and retrieving the results. This is only used by the bitarchive replicas.
045     *
046     * @param msg The batch message to sent to the replica.
047     * @return The batch message which has been sent.
048     */
049    BatchMessage sendBatchJob(BatchMessage msg);
050
051    /**
052     * Method for sending batch message and retrieving the results. This will only work for Bitarchive replicas.
053     *
054     * @param replyChannel The channel where the reply should be sent.
055     * @param job The batchjob to execute on the replica.
056     * @return The message which has been sent.
057     */
058    BatchMessage sendBatchJob(ChannelID replyChannel, FileBatchJob job);
059
060    /**
061     * The message for retrieving a record from a arc-file in the replica. This is only used by the bitarchive replicas.
062     *
063     * @param msg The message for retrieving the record in a arc-file.
064     */
065    void sendGetMessage(GetMessage msg);
066
067    /**
068     * The message for retrieving an entire file from the replica. This is only used by the bitarchive replicas.
069     *
070     * @param msg The message for retrieving the file.
071     */
072    void sendGetFileMessage(GetFileMessage msg);
073
074    /**
075     * Message for deleting and retrieving a file from a archive.
076     *
077     * @param msg The message for retrieving the file.
078     */
079    void sendRemoveAndGetFileMessage(RemoveAndGetFileMessage msg);
080
081    /**
082     * Uploads a file to the replica archive. This should create the UploadMessage and send it.
083     *
084     * @param rf The remote file
085     * @param precomputedChecksum A precomputed checksum 
086     */
087    void sendUploadMessage(RemoteFile rf, String precomputedChecksum);
088
089    /**
090     * Retrieves the checksum for a specific arc file. The GetChecksumMessage is sent along to the archive.
091     *
092     * @param msg The GetChecksumMessage to be send to the replica.
093     */
094    void sendGetChecksumMessage(GetChecksumMessage msg);
095
096    /**
097     * Retrieves the checksum for a specific file. The method creates and sends the GetChecksumMessage to the archive.
098     *
099     * @param replyChannel The channel where the reply should be sent.
100     * @param filename The name of the file to retrieve the checksum from.
101     * @return The message, after it has been sent.
102     */
103    GetChecksumMessage sendGetChecksumMessage(ChannelID replyChannel, String filename);
104
105    /**
106     * Retrieves the names of all the arc file in the replica archive.
107     *
108     * @param msg The GetAllFilenamesMessage to sent to the replica.
109     */
110    void sendGetAllFilenamesMessage(GetAllFilenamesMessage msg);
111
112    /**
113     * Retrieves the checksum for all the arc files in the replica archive. This method is the ChecksumReplica
114     * equivalent to running a ChecksumJob.
115     * <p>
116     * The message is sent from this method.
117     *
118     * @param msg The message for retrieving all the checksums.
119     */
120    void sendGetAllChecksumsMessage(GetAllChecksumsMessage msg);
121
122    /**
123     * For correcting an erroneous entry in the archive. The message is sent the replica for correcting the 'bad' entry.
124     *
125     * @param msg The correct message to correct the bad entry in the archive.
126     */
127    void sendCorrectMessage(CorrectMessage msg);
128
129    /**
130     * For retrieving the type of archive. This will either be 'bitArchive' or 'checksumArchive'.
131     *
132     * @return The type of archive.
133     */
134    ReplicaType getType();
135
136    /**
137     * Close the replica client.
138     */
139    void close();
140}