JavaGroups
Class RequestCorrelator

java.lang.Object
  |
  +--JavaGroups.RequestCorrelator

public class RequestCorrelator
extends java.lang.Object

Framework to send requests and receive matching responses (matching on request ID). Multiple requests can be sent at a time. Whenever a response is received, the correct RspCollector is looked up (key = id) and its method ReceiveResponse invoked. A caller may use Done to signal that no more responses are expected, and that the corresponding entry may be removed.

RequestCorrelator can be installed at both client and server sides, it can also switch roles dynamically, i.e. send a request and at the same time process an incoming request (when local delivery is enabled, this is actually the default).


Constructor Summary
RequestCorrelator(java.lang.String name, Protocol transport, RequestHandler handler)
          Constructor.
RequestCorrelator(java.lang.String name, Protocol transport, RequestHandler handler, boolean deadlock_detection)
          Constructor.
 
Method Summary
 void Done(long id)
          Used to signal that a certain request may be garbage collected as all responses have been received.
 void finalize()
           
static void main(java.lang.String[] args)
           
 void Receive(Event evt)
          Callback.
 void SendRequest(long id, Message msg, RspCollector coll)
          Send a request to a group.
 void SetDeadlockDetection(boolean flag)
           
 void SetRequestHandler(RequestHandler handler)
           
 void Start()
           
 void Stop()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestCorrelator

public RequestCorrelator(java.lang.String name,
                         Protocol transport,
                         RequestHandler handler)
Constructor. Uses transport to send messages. If handler is not null, all incoming requests will be dispatched to it (via Handle(Message)).
Parameters:
name - Used to differentiate between diferent RequestCorrelators (e.g. in different protocol layers). Has to be unique if multiple request correlators are used.
transport - Use to send requests. Only Send is used, not Receive !
handler - Request handler. Method Handle(Message) will be called when a request is received.

RequestCorrelator

public RequestCorrelator(java.lang.String name,
                         Protocol transport,
                         RequestHandler handler,
                         boolean deadlock_detection)
Constructor. Uses transport to send messages. If handler is not null, all incoming requests will be dispatched to it (via Handle(Message)).
Parameters:
name - Used to differentiate between diferent RequestCorrelators (e.g. in different protocol layers). Has to be unique if multiple request correlators are used.
transport - Use to send requests. Only Send is used, not Receive !
handler - Request handler. Method Handle(Message) will be called when a request is received.
deadlock_detection - When enabled (true) recursive synchronous message calls will be detected and processed with higher priority in order to solve deadlocks. Slows down processing a little bit when enabled due to runtime checks involved.
Method Detail

finalize

public void finalize()

SetDeadlockDetection

public void SetDeadlockDetection(boolean flag)

SetRequestHandler

public void SetRequestHandler(RequestHandler handler)

SendRequest

public void SendRequest(long id,
                        Message msg,
                        RspCollector coll)
Send a request to a group. If no response collector is given, no responses are expected (making the call asynchronous).
Parameters:
id - The request ID. Must be unique for this JVM (e.g. current time in millisecs)
msg - The request to be sent. The body of the message carries the request data
coll - A response collector (usually the object that invokes this method). Its methods ReceiveResponse and Suspect will be invoked when a message has been received or a member is suspected, respectively.

Done

public void Done(long id)
Used to signal that a certain request may be garbage collected as all responses have been received.

Receive

public void Receive(Event evt)
Callback. Called by the protocol below when a message has been received. The algorithm should test whether the message is destined for us and, if not, pass it up to the next layer. Otherwise, it should remove the header and check whether the message is a request or response. In the first case, the message will be delivered to the request handler registered (calling its Handle method), in the second case, the corresponding response collector is looked up and the message delivered.

Start

public void Start()

Stop

public void Stop()

main

public static void main(java.lang.String[] args)