All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class JavaGroups.RequestCorrelator

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

public class RequestCorrelator
extends 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 Index

 o RequestCorrelator(String, Protocol, RequestHandler)
Constructor.
 o RequestCorrelator(String, Protocol, RequestHandler, boolean)
Constructor.

Method Index

 o Done(long)
Used to signal that a certain request may be garbage collected as all responses have been received.
 o finalize()
 o main(String[])
 o Receive(Event)
Callback.
 o SendRequest(long, Message, RspCollector)
Send a request to a group.
 o SetDeadlockDetection(boolean)
 o SetRequestHandler(RequestHandler)
 o Start()
 o Stop()

Constructors

 o RequestCorrelator
 public RequestCorrelator(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.
 o RequestCorrelator
 public RequestCorrelator(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.

Methods

 o finalize
 public void finalize()
Overrides:
finalize in class Object
 o SetDeadlockDetection
 public void SetDeadlockDetection(boolean flag)
 o SetRequestHandler
 public void SetRequestHandler(RequestHandler handler)
 o 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.
 o Done
 public void Done(long id)
Used to signal that a certain request may be garbage collected as all responses have been received.

 o 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.

 o Start
 public void Start()
 o Stop
 public void Stop()
 o main
 public static void main(String args[])

All Packages  Class Hierarchy  This Package  Previous  Next  Index