dk.netarkivet.common.distribute
Class Synchronizer

java.lang.Object
  extended by dk.netarkivet.common.distribute.Synchronizer
All Implemented Interfaces:
javax.jms.MessageListener
Direct Known Subclasses:
JMSArcRepositoryClient

public class Synchronizer
extends java.lang.Object
implements javax.jms.MessageListener

Converts an asynchronous call to a synchronous call. The method sendAndWaitForOneReply() is a blocking call which responds when a reply is received or returns null on timeout.


Constructor Summary
Synchronizer()
          Initialise maps containing requests and replies.
 
Method Summary
 void onMessage(javax.jms.Message msg)
          Receives replies from a message queue and triggers the blocked call in sendAndWaitForOneReply().
 NetarkivetMessage sendAndWaitForOneReply(NetarkivetMessage msg, long timeout)
          Sends a message to a message queue and blocks the method invocation until a reply arrives.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Synchronizer

public Synchronizer()
Initialise maps containing requests and replies.

Method Detail

onMessage

public void onMessage(javax.jms.Message msg)
Receives replies from a message queue and triggers the blocked call in sendAndWaitForOneReply().

Specified by:
onMessage in interface javax.jms.MessageListener
Parameters:
msg - an ObjectMessage containing a NetarkivetMessage.

sendAndWaitForOneReply

public NetarkivetMessage sendAndWaitForOneReply(NetarkivetMessage msg,
                                                long timeout)
Sends a message to a message queue and blocks the method invocation until a reply arrives. If it times out a null is returned. If a spurious wakeup is received and a timeout is set, the method will carry on waiting for the reply until the total timeout time has been used up. If a spurious wakeup is received and no timeout is set the method will just go back to waiting

Parameters:
msg - the request message
timeout - the timeout in milliseconds (or zero for no timeout)
Returns:
a reply message from the receiver of the request or null if timed out.