All Packages Class Hierarchy This Package Previous Next Index
Class JavaGroups.RequestCorrelator
java.lang.Object
|
+----JavaGroups.RequestCorrelator
- public class RequestCorrelator
- extends Object
- implements Runnable
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).
-
RequestCorrelator(Transport, RequestHandler)
- Constructor.
-
Done(long)
- Used to signal that a certain request may be garbage collected as all responses
have been received.
-
finalize()
-
-
main(String[])
-
-
Receive(Message)
- Callback.
-
run()
- Remove requests from mq and invoke request_handler.Handle()
-
SendRequest(long, Message, RspCollector)
- Send a request to a group.
-
SetRequestHandler(RequestHandler)
-
-
Start()
-
-
Stop()
-
-
Suspect(Object)
- Callback.
RequestCorrelator
public RequestCorrelator(Transport 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:
- 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.
finalize
public void finalize()
- Overrides:
- finalize in class Object
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.
Suspect
public void Suspect(Object mbr)
- Callback. All response collectors currently registered will be notified that
mbr may have crashed, so they won't wait for its response.
Receive
public boolean Receive(Message msg)
- 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,
return false. 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.
run
public void run()
- Remove requests from mq and invoke request_handler.Handle()
Start
public void Start()
Stop
public void Stop()
main
public static void main(String args[])
All Packages Class Hierarchy This Package Previous Next Index