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     */
086    void sendUploadMessage(RemoteFile rf);
087
088    /**
089     * Retrieves the checksum for a specific arc file. The GetChecksumMessage is sent along to the archive.
090     *
091     * @param msg The GetChecksumMessage to be send to the replica.
092     */
093    void sendGetChecksumMessage(GetChecksumMessage msg);
094
095    /**
096     * Retrieves the checksum for a specific file. The method creates and sends the GetChecksumMessage to the archive.
097     *
098     * @param replyChannel The channel where the reply should be sent.
099     * @param filename The name of the file to retrieve the checksum from.
100     * @return The message, after it has been sent.
101     */
102    GetChecksumMessage sendGetChecksumMessage(ChannelID replyChannel, String filename);
103
104    /**
105     * Retrieves the names of all the arc file in the replica archive.
106     *
107     * @param msg The GetAllFilenamesMessage to sent to the replica.
108     */
109    void sendGetAllFilenamesMessage(GetAllFilenamesMessage msg);
110
111    /**
112     * Retrieves the checksum for all the arc files in the replica archive. This method is the ChecksumReplica
113     * equivalent to running a ChecksumJob.
114     * <p>
115     * The message is sent from this method.
116     *
117     * @param msg The message for retrieving all the checksums.
118     */
119    void sendGetAllChecksumsMessage(GetAllChecksumsMessage msg);
120
121    /**
122     * For correcting an erroneous entry in the archive. The message is sent the replica for correcting the 'bad' entry.
123     *
124     * @param msg The correct message to correct the bad entry in the archive.
125     */
126    void sendCorrectMessage(CorrectMessage msg);
127
128    /**
129     * For retrieving the type of archive. This will either be 'bitArchive' or 'checksumArchive'.
130     *
131     * @return The type of archive.
132     */
133    ReplicaType getType();
134
135    /**
136     * Close the replica client.
137     */
138    void close();
139}