dk.netarkivet.archive.bitarchive.distribute
Class BitarchiveServer

java.lang.Object
  extended by dk.netarkivet.archive.distribute.ArchiveMessageHandler
      extended by dk.netarkivet.archive.bitarchive.distribute.BitarchiveServer
All Implemented Interfaces:
ArchiveMessageVisitor, CleanupIF, javax.jms.MessageListener

public class BitarchiveServer
extends ArchiveMessageHandler
implements CleanupIF

Bitarchive container responsible for processing the different classes of message which can be received by a bitarchive and returning appropriate data.


Field Summary
 java.util.Map<java.lang.String,java.lang.Thread> batchProcesses
          Map between running batchjob processes and their message id.
 
Method Summary
 void cleanup()
          Ends the heartbeat sender before next loop.
 void close()
          Ends the heartbeat sender before next loop and removes the server as listener on allBa and anyBa.
 java.lang.String getBitarchiveAppId()
          Returns a String that identifies this bit archive application (within the bit archive, i.e.
static BitarchiveServer getInstance()
          Returns the unique instance of this class The server creates an instance of the bitarchive it provides access to and starts to listen to JMS messages on the incomming jms queue

Also, heartbeats are sent out at regular intervals to the Bitarchive Monitor, to tell that this bitarchive is alive.

 void visit(BatchMessage msg)
          Process a batch job and send the result back to the client.
 void visit(BatchTerminationMessage msg)
           
 void visit(GetFileMessage msg)
          Process a getFile request and send the result back to the client.
 void visit(GetMessage msg)
          Process a get request and send the result back to the client.
 void visit(RemoveAndGetFileMessage msg)
          Removes an arcfile from the bitarchive and returns the removed file as an remotefile.
 void visit(UploadMessage msg)
          Process a upload request and send the result back to the client.
 
Methods inherited from class dk.netarkivet.archive.distribute.ArchiveMessageHandler
onMessage, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

batchProcesses

public java.util.Map<java.lang.String,java.lang.Thread> batchProcesses
Map between running batchjob processes and their message id.

Method Detail

getInstance

public static BitarchiveServer getInstance()
                                    throws ArgumentNotValid,
                                           UnknownID
Returns the unique instance of this class The server creates an instance of the bitarchive it provides access to and starts to listen to JMS messages on the incomming jms queue

Also, heartbeats are sent out at regular intervals to the Bitarchive Monitor, to tell that this bitarchive is alive.

Returns:
the instance
Throws:
UnknownID - - if there was no heartbeat frequency defined in settings
ArgumentNotValid - - if the heartbeat frequency in settings is invalid or either argument is null

close

public void close()
Ends the heartbeat sender before next loop and removes the server as listener on allBa and anyBa. Closes the bitarchive. Calls cleanup.


cleanup

public void cleanup()
Ends the heartbeat sender before next loop.

Specified by:
cleanup in interface CleanupIF

visit

public void visit(GetMessage msg)
           throws ArgumentNotValid
Process a get request and send the result back to the client. If the arcfile is not found on this bitarchive machine, nothing happens.

Specified by:
visit in interface ArchiveMessageVisitor
Overrides:
visit in class ArchiveMessageHandler
Parameters:
msg - a container for upload request
Throws:
ArgumentNotValid - If the message is null.

visit

public void visit(UploadMessage msg)
           throws ArgumentNotValid
Process a upload request and send the result back to the client. This may be a very time consuming process and is a blocking call.

Specified by:
visit in interface ArchiveMessageVisitor
Overrides:
visit in class ArchiveMessageHandler
Parameters:
msg - a container for upload request
Throws:
ArgumentNotValid - If the message is null.

visit

public void visit(RemoveAndGetFileMessage msg)
           throws ArgumentNotValid
Removes an arcfile from the bitarchive and returns the removed file as an remotefile. Answers OK if the file is actually removed. Answers notOk if the file exists with wrong checksum or wrong credentials Doesn't answer if the file doesn't exist. This method always generates a warning when deleting a file. Before the file is removed it is verified that - the file exists in the bitarchive - the file has the correct checksum - the supplied credentials are correct

Specified by:
visit in interface ArchiveMessageVisitor
Overrides:
visit in class ArchiveMessageHandler
Parameters:
msg - a container for remove request
Throws:
ArgumentNotValid - If the RemoveAndGetFileMessage is null.

visit

public void visit(BatchMessage msg)
           throws ArgumentNotValid
Process a batch job and send the result back to the client.

Specified by:
visit in interface ArchiveMessageVisitor
Overrides:
visit in class ArchiveMessageHandler
Parameters:
msg - a container for batch jobs
Throws:
ArgumentNotValid - If the BatchMessage is null.

visit

public void visit(BatchTerminationMessage msg)
           throws ArgumentNotValid
Throws:
ArgumentNotValid

visit

public void visit(GetFileMessage msg)
           throws ArgumentNotValid
Process a getFile request and send the result back to the client.

Specified by:
visit in interface ArchiveMessageVisitor
Overrides:
visit in class ArchiveMessageHandler
Parameters:
msg - a container for a getfile request
Throws:
ArgumentNotValid - If the GetFileMessage is null.

getBitarchiveAppId

public java.lang.String getBitarchiveAppId()
Returns a String that identifies this bit archive application (within the bit archive, i.e. either with id ONE or TWO)

Returns:
String with IP address of this host and, if specified, the APPLICATION_INSTANCE_ID from settings