|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.javagroups.blocks.RequestCorrelator
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).
Nested Class Summary | |
static class |
RequestCorrelator.Header
The header for RequestCorrelator messages |
Field Summary | |
protected java.util.Stack |
call_stack
This field is used only if deadlock detection is enabled. |
protected org.javagroups.blocks.RequestCorrelator.CallStackSetter |
call_stack_setter
This field is used only if deadlock detection is enabled. |
protected boolean |
deadlock_detection
Whether to perform deadlock detection is synchronous calls |
protected Address |
local_addr
The address of this group member |
protected java.lang.String |
name
makes the instance unique (together with IDs) |
protected RequestHandler |
request_handler
The handler for the incoming requests. |
protected java.util.HashMap |
requests
The table of pending requests (keys=Long (request IDs), values=RequestEntry) |
protected Scheduler |
scheduler
The dispatching thread pool |
protected java.lang.Object |
transport
The protocol layer to use to pass up/down messages. |
Constructor Summary | |
RequestCorrelator(java.lang.String name,
java.lang.Object transport,
RequestHandler handler)
Constructor. |
|
RequestCorrelator(java.lang.String name,
java.lang.Object transport,
RequestHandler handler,
Address local_addr)
|
|
RequestCorrelator(java.lang.String name,
java.lang.Object transport,
RequestHandler handler,
boolean deadlock_detection)
Constructor. |
|
RequestCorrelator(java.lang.String name,
java.lang.Object transport,
RequestHandler handler,
boolean deadlock_detection,
Address local_addr)
|
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()
Stop the dispatch thread pool |
void |
receive(Event evt)
Callback. |
boolean |
receiveMessage(Message msg)
Handles a message coming from a layer below |
void |
receiveSuspect(Address mbr)
Event.SUSPECT event received from a layer below |
void |
receiveView(View new_view)
Event.VIEW_CHANGE event received from a layer below |
void |
sendRequest(long id,
java.util.List dest_mbrs,
Message msg,
RspCollector coll)
Send a request to a group. |
void |
sendRequest(long id,
Message msg,
RspCollector coll)
Helper method for sendRequest(long,List,Message,RspCollector) . |
void |
setDeadlockDetection(boolean flag)
Switch the deadlock detection mechanism on/off |
void |
setLocalAddress(Address local_addr)
|
void |
setRequestHandler(RequestHandler handler)
??? |
void |
start()
|
void |
stop()
|
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.Object transport
protected java.util.HashMap requests
protected RequestHandler request_handler
protected java.lang.String name
protected Scheduler scheduler
protected Address local_addr
protected java.util.Stack call_stack
protected boolean deadlock_detection
protected org.javagroups.blocks.RequestCorrelator.CallStackSetter call_stack_setter
Constructor Detail |
public RequestCorrelator(java.lang.String name, java.lang.Object transport, RequestHandler handler)
handler
is not null, all incoming requests will be dispatched to it (via
handle(Message)
).
name
- Used to differentiate between different RequestCorrelators
(e.g. in different protocol layers). Has to be unique if multiple
request correlators are used.transport
- Used to send/pass up requests. Can be either a Transport (only send() will be
used then), or a Protocol (passUp()/passDown() will be used)handler
- Request handler. Method handle(Message)
will be called when a request is received.public RequestCorrelator(java.lang.String name, java.lang.Object transport, RequestHandler handler, Address local_addr)
public RequestCorrelator(java.lang.String name, java.lang.Object transport, RequestHandler handler, boolean deadlock_detection)
handler
is not null, all incoming requests will be dispatched to it (via
handle(Message)
).
name
- Used to differentiate between different RequestCorrelators
(e.g. in different protocol layers). Has to be unique if multiple
request correlators are used.transport
- Used to send/pass up requests. Can be either a Transport (only send() will be
used then), or a Protocol (passUp()/passDown() will be used)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.public RequestCorrelator(java.lang.String name, java.lang.Object transport, RequestHandler handler, boolean deadlock_detection, Address local_addr)
Method Detail |
public void finalize()
public void setDeadlockDetection(boolean flag)
flag
- the deadlock detection flagpublic void setRequestHandler(RequestHandler handler)
public void sendRequest(long id, Message msg, RspCollector coll)
sendRequest(long,List,Message,RspCollector)
.
public void sendRequest(long id, java.util.List dest_mbrs, Message msg, RspCollector coll)
id
- The request ID. Must be unique for this JVM (e.g. current
time in millisecs)dest_mbrs
- The list of members who should receive the call. Usually a group RPC
is sent via multicast, but a receiver drops the request if its own address
is not in this list. Will not be used if it is null.msg
- The request to be sent. The body of the message carries
the request datacoll
- 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.public void done(long id)
public void receive(Event evt)
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.
public void start()
public void stop()
public void receiveSuspect(Address mbr)
All response collectors currently registered will
be notified that mbr
may have crashed, so they won't
wait for its response.
public void receiveView(View new_view)
Mark all responses from members that are not in new_view as NOT_RECEIVED.
public boolean receiveMessage(Message msg)
public void setLocalAddress(Address local_addr)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |