Package dk.netarkivet.common.distribute
Class Synchronizer
- java.lang.Object
-
- dk.netarkivet.common.distribute.Synchronizer
-
- All Implemented Interfaces:
javax.jms.MessageListener
- Direct Known Subclasses:
BitmagArcRepositoryClient
,JMSArcRepositoryClient
public class Synchronizer extends 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
Constructors Constructor Description Synchronizer()
Initialise maps containing requests and replies.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
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 interfacejavax.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 messagetimeout
- the timeout in milliseconds (or zero for no timeout)- Returns:
- a reply message from the receiver of the request or null if timed out.
-
-