dk.netarkivet.archive.indexserver.distribute
Class IndexRequestServer

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

public class IndexRequestServer
extends ArchiveMessageHandler
implements CleanupIF

Index request server singleton. This class contains a singleton that handles requesting an index over JMS. It will ALWAYS reply to such messages, either with the index, a message telling that only a subset is available, and which, or an error message,


Method Summary
 void cleanup()
          Releases the JMS-connection and resets the singleton.
 void close()
          Releases the JMS-connection and resets the singleton.
static IndexRequestServer getInstance()
          Get the unique index request server instance.
 void setHandler(RequestType t, FileBasedCache<java.util.Set<java.lang.Long>> handler)
          Set handler for certain type of index request.
 void start()
          Look for stored messages to be preprocessed, and start processing those.
 void visit(IndexRequestMessage irMsg)
          Given a request for an index over a set of job ids, use a cache to try to create the index, Then reply result.
 
Methods inherited from class dk.netarkivet.archive.distribute.ArchiveMessageHandler
onMessage, visit, visit, visit, visit, 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
 

Method Detail

getInstance

public static IndexRequestServer getInstance()
Get the unique index request server instance.

Returns:
The index request server.

setHandler

public void setHandler(RequestType t,
                       FileBasedCache<java.util.Set<java.lang.Long>> handler)
Set handler for certain type of index request. If called more than once, new handler overwrites old one.

Parameters:
t - The type of index requested
handler - The handler that should handle this request.

visit

public void visit(IndexRequestMessage irMsg)
           throws ArgumentNotValid
Given a request for an index over a set of job ids, use a cache to try to create the index, Then reply result. If for any reason not all requested jobs can be indexed, return the subset. The client can then retry with this subset, in order to get index of that subset. Values read from the message in order to handle this: - Type of index requested - will use the index cache of this type - Set of job IDs - which jobs to generate index for Values written to message before replying: - The subset indexed - may be the entire set. ALWAYS set unless reply !OK - File with index - ONLY if subset is entire set, the index requested. This method should ALWAYS reply. May reply with not OK message if: - Message received was not OK - Request type is null or unknown in message - Set of job ids is null in message - Cache generation throws exception

Specified by:
visit in interface ArchiveMessageVisitor
Overrides:
visit in class ArchiveMessageHandler
Parameters:
irMsg - A message requesting an index.
Throws:
ArgumentNotValid - on null parameter

close

public void close()
Releases the JMS-connection and resets the singleton.


cleanup

public void cleanup()
Releases the JMS-connection and resets the singleton.

Specified by:
cleanup in interface CleanupIF

start

public void start()
Look for stored messages to be preprocessed, and start processing those. And start listening for index-requests.