Package org.jgroups.blocks
Class RequestCorrelator
- java.lang.Object
- 
- org.jgroups.blocks.RequestCorrelator
 
- 
 public class RequestCorrelator extends java.lang.ObjectFramework to send requests and receive matching responses (on request ID). Multiple requests can be sent at a time. Whenever a response is received, the correctRequestis looked up (key = id) and its methodreceiveResponse()invoked.- Author:
- Bela Ban
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classRequestCorrelator.HeaderThe header for RequestCorrelator messagesstatic classRequestCorrelator.MultiDestinationHeaderprotected classRequestCorrelator.MyProbeHandlerprotected classRequestCorrelator.ResponseImpl
 - 
Field SummaryFields Modifier and Type Field Description protected booleanasync_dispatchingWhether or not to use async dispatcherprotected shortcorr_idmakes the instance unique (together with IDs)protected Addresslocal_addrThe address of this group memberprotected static Loglogprotected MarshallermarshallerPossibility for an external marshaller to marshal/unmarshal responsesprotected RequestCorrelator.MyProbeHandlerprobe_handlerprotected RequestHandlerrequest_handlerThe handler for the incoming requests.protected static java.util.concurrent.atomic.AtomicLongREQUEST_IDTo generate unique request IDsprotected java.util.concurrent.ConcurrentMap<java.lang.Long,Request>requestsThe table of pending requests (keys=Long (request IDs), values=RequestEntry)protected RpcStatsrpc_statsprotected booleanstartedprotected ProtocoltransportThe protocol layer to use to pass up/down messages.protected Viewviewprotected booleanwrap_exceptions
 - 
Constructor SummaryConstructors Constructor Description RequestCorrelator(short corr_id, Protocol transport, RequestHandler handler, Address local_addr)Constructor.RequestCorrelator(Protocol transport, RequestHandler handler, Address local_addr)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanasyncDispatching()RequestCorrelatorasyncDispatching(boolean flag)protected voiddispatch(Message msg, RequestCorrelator.Header hdr)voiddone(long id)Used to signal that a certain request may be garbage collected as all responses have been received.AddressgetLocalAddress()MarshallergetMarshaller()protected voidhandleRequest(Message req, RequestCorrelator.Header hdr)Handle a request msg for this correlatorprotected voidhandleResponse(Request req, Address sender, byte[] buf, int offset, int length, boolean is_exception)booleanreceive(Event evt)Callback.booleanreceiveMessage(Message msg)Handles a message coming from a layer belowvoidreceiveMessageBatch(MessageBatch batch)voidreceiveView(View new_view)View received: mark all responses from members that are not in new_view as suspectedvoidregisterProbeHandler(TP transport)protected RequestCorrelatorremoveEntry(long id)protected static java.lang.ObjectreplyFromBuffer(byte[] buf, int offset, int length, Marshaller marshaller)protected static BufferreplyToBuffer(java.lang.Object obj, Marshaller marshaller)protected voidsendReply(Message req, long req_id, java.lang.Object reply, boolean is_exception)voidsendRequest(java.util.Collection<Address> dest_mbrs, Buffer data, Request req, RequestOptions opts)Sends a request to a group.protected voidsendResponse(Message rsp, long req_id, boolean is_exception)voidsendUnicastRequest(Address dest, Buffer data, Request req, RequestOptions opts)Sends a request to a single destinationRequestCorrelatorsetLocalAddress(Address a)RequestCorrelatorsetMarshaller(Marshaller m)voidsetRequestHandler(RequestHandler handler)voidsetSiteUnreachable(java.lang.String site)An entire site is down; mark all requests that point to that site as unreachable (used by RELAY2)voidstart()voidstop()voidunregisterProbeHandler(TP transport)booleanwrapExceptions()RequestCorrelatorwrapExceptions(boolean flag)
 
- 
- 
- 
Field Detail- 
transportprotected Protocol transport The protocol layer to use to pass up/down messages. Can be either a Protocol or a Transport
 - 
requestsprotected final java.util.concurrent.ConcurrentMap<java.lang.Long,Request> requests The table of pending requests (keys=Long (request IDs), values=RequestEntry)
 - 
REQUEST_IDprotected static final java.util.concurrent.atomic.AtomicLong REQUEST_ID To generate unique request IDs
 - 
request_handlerprotected RequestHandler request_handler The handler for the incoming requests. It is called from inside the dispatcher thread
 - 
marshallerprotected Marshaller marshaller Possibility for an external marshaller to marshal/unmarshal responses
 - 
corr_idprotected short corr_id makes the instance unique (together with IDs)
 - 
local_addrprotected Address local_addr The address of this group member
 - 
viewprotected volatile View view 
 - 
startedprotected boolean started 
 - 
async_dispatchingprotected boolean async_dispatching Whether or not to use async dispatcher
 - 
wrap_exceptionsprotected boolean wrap_exceptions 
 - 
probe_handlerprotected final RequestCorrelator.MyProbeHandler probe_handler 
 - 
rpc_statsprotected final RpcStats rpc_stats 
 - 
logprotected static final Log log 
 
- 
 - 
Constructor Detail- 
RequestCorrelatorpublic RequestCorrelator(short corr_id, Protocol transport, RequestHandler handler, Address local_addr)Constructor. Uses transport to send messages. Ifhandleris not null, all incoming requests will be dispatched to it (viahandle(Message)).- Parameters:
- corr_id- 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.
- handler- Request handler. Method- handle(Message)will be called when a request is received.
 
 - 
RequestCorrelatorpublic RequestCorrelator(Protocol transport, RequestHandler handler, Address local_addr) 
 
- 
 - 
Method Detail- 
setRequestHandlerpublic void setRequestHandler(RequestHandler handler) 
 - 
getLocalAddresspublic Address getLocalAddress() 
 - 
setLocalAddresspublic RequestCorrelator setLocalAddress(Address a) 
 - 
getMarshallerpublic Marshaller getMarshaller() 
 - 
setMarshallerpublic RequestCorrelator setMarshaller(Marshaller m) 
 - 
asyncDispatchingpublic boolean asyncDispatching() 
 - 
asyncDispatchingpublic RequestCorrelator asyncDispatching(boolean flag) 
 - 
wrapExceptionspublic boolean wrapExceptions() 
 - 
wrapExceptionspublic RequestCorrelator wrapExceptions(boolean flag) 
 - 
sendRequestpublic void sendRequest(java.util.Collection<Address> dest_mbrs, Buffer data, Request req, RequestOptions opts) throws java.lang.Exception Sends a request to a group. If no response collector is given, no responses are expected (making the call asynchronous)- Parameters:
- 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.
- data- the data to be sent.
- req- A request (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.
- Throws:
- java.lang.Exception
 
 - 
sendUnicastRequestpublic void sendUnicastRequest(Address dest, Buffer data, Request req, RequestOptions opts) throws java.lang.Exception Sends a request to a single destination- Throws:
- java.lang.Exception
 
 - 
donepublic void done(long id) Used to signal that a certain request may be garbage collected as all responses have been received.
 - 
receivepublic boolean 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.- Parameters:
- evt- The event to be received
- Returns:
- Whether or not the event was consumed. If true, don't pass message up, else pass it up
 
 - 
startpublic final void start() 
 - 
stoppublic void stop() 
 - 
registerProbeHandlerpublic void registerProbeHandler(TP transport) 
 - 
unregisterProbeHandlerpublic void unregisterProbeHandler(TP transport) 
 - 
setSiteUnreachablepublic void setSiteUnreachable(java.lang.String site) An entire site is down; mark all requests that point to that site as unreachable (used by RELAY2)
 - 
receiveViewpublic void receiveView(View new_view) View received: mark all responses from members that are not in new_view as suspected
 - 
receiveMessagepublic boolean receiveMessage(Message msg) Handles a message coming from a layer below- Returns:
- true if the message was consumed, don't pass it further up, else false
 
 - 
receiveMessageBatchpublic void receiveMessageBatch(MessageBatch batch) 
 - 
removeEntryprotected RequestCorrelator removeEntry(long id) 
 - 
dispatchprotected void dispatch(Message msg, RequestCorrelator.Header hdr) 
 - 
handleRequestprotected void handleRequest(Message req, RequestCorrelator.Header hdr) Handle a request msg for this correlator
 - 
handleResponseprotected void handleResponse(Request req, Address sender, byte[] buf, int offset, int length, boolean is_exception) 
 - 
sendReplyprotected void sendReply(Message req, long req_id, java.lang.Object reply, boolean is_exception) 
 - 
sendResponseprotected void sendResponse(Message rsp, long req_id, boolean is_exception) 
 - 
replyToBufferprotected static Buffer replyToBuffer(java.lang.Object obj, Marshaller marshaller) throws java.lang.Exception - Throws:
- java.lang.Exception
 
 - 
replyFromBufferprotected static java.lang.Object replyFromBuffer(byte[] buf, int offset, int length, Marshaller marshaller) throws java.lang.Exception- Throws:
- java.lang.Exception
 
 
- 
 
-