Class RequestCorrelator
- Direct Known Subclasses:
MuxRequestCorrelator
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).
- Author:
- Bela Ban
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe header for RequestCorrelator messagesstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected shortmakes the instance unique (together with IDs)protected AddressThe address of this group memberprotected static final Logprotected RpcDispatcher.Marshaller2Possibility for an external marshaller to marshal/unmarshal responsesprotected RequestHandlerThe handler for the incoming requests.protected final ConcurrentMap<Long, RspCollector> The table of pending requests (keys=Long (request IDs), values=RequestEntry)protected booleanprotected ObjectThe protocol layer to use to pass up/down messages. -
Constructor Summary
ConstructorsConstructorDescriptionRequestCorrelator(short id, Object transport, RequestHandler handler, Address local_addr) RequestCorrelator(Object transport, RequestHandler handler, Address local_addr) RequestCorrelator(String name, Object transport, RequestHandler handler) Deprecated.RequestCorrelator(String name, Object transport, RequestHandler handler, boolean deadlock_detection) Deprecated.RequestCorrelator(String name, Object transport, RequestHandler handler, boolean deadlock_detection, boolean concurrent_processing) Deprecated.RequestCorrelator(String name, Object transport, RequestHandler handler, boolean deadlock_detection, Address local_addr) Deprecated.RequestCorrelator(String name, Object transport, RequestHandler handler, boolean deadlock_detection, Address local_addr, boolean concurrent_processing) Deprecated.RequestCorrelator(String name, Object transport, RequestHandler handler, Address local_addr) Deprecated.RequestCorrelator(String name, Object transport, RequestHandler handler, Address local_addr, boolean concurrent_processing) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoiddone(long id) Used to signal that a certain request may be garbage collected as all responses have been received.protected voidhandleRequest(Message req, RequestCorrelator.Header hdr) Handle a request msg for this correlatorprotected voidprepareResponse(Message rsp) booleanCallback.booleanreceiveMessage(Message msg) Handles a message coming from a layer belowvoidreceiveSuspect(Address mbr) Event.SUSPECT event received from a layer below.voidreceiveView(View new_view) Event.VIEW_CHANGE event received from a layer below.voidregisterProbeHandler(TP transport) voidsendRequest(long id, Collection<Address> dest_mbrs, Message msg, RspCollector coll, RequestOptions options) Sends a request to a group.voidsendRequest(long id, List<Address> dest_mbrs, Message msg, RspCollector coll) voidsendRequest(long id, Message msg, RspCollector coll) Deprecated.voidsendUnicastRequest(long id, Address target, Message msg, RspCollector coll) Sends a request to a single destinationvoidsetConcurrentProcessing(boolean concurrent_processing) Deprecated.Not needed since the introduction of the concurrent stackvoidsetDeadlockDetection(boolean flag) Deprecated.deadlock detection is not needed with a concurrent stackvoidsetLocalAddress(Address local_addr) voidsetMarshaller(RpcDispatcher.Marshaller marshaller) voidsetRequestHandler(RequestHandler handler) final voidstart()voidstop()voidunregisterProbeHandler(TP transport)
-
Field Details
-
transport
The protocol layer to use to pass up/down messages. Can be either a Protocol or a Transport -
requests
The table of pending requests (keys=Long (request IDs), values=RequestEntry) -
request_handler
The handler for the incoming requests. It is called from inside the dispatcher thread -
marshaller
Possibility for an external marshaller to marshal/unmarshal responses -
id
protected short idmakes the instance unique (together with IDs) -
local_addr
The address of this group member -
started
protected boolean started -
log
-
-
Constructor Details
-
RequestCorrelator
Deprecated.Constructor. Uses transport to send messages. Ifhandleris not null, all incoming requests will be dispatched to it (viahandle(Message)).- Parameters:
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 (up_prot.up()/down_prot.down() will be used)handler- Request handler. Methodhandle(Message)will be called when a request is received.
-
RequestCorrelator
@Deprecated public RequestCorrelator(String name, Object transport, RequestHandler handler, Address local_addr) Deprecated. -
RequestCorrelator
-
RequestCorrelator
-
RequestCorrelator
@Deprecated public RequestCorrelator(String name, Object transport, RequestHandler handler, boolean deadlock_detection) Deprecated.Constructor. Uses transport to send messages. Ifhandleris not null, all incoming requests will be dispatched to it (viahandle(Message)).- Parameters:
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 (up_prot.up()/down_prot.down() will be used)handler- Request handler. Methodhandle(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.
-
RequestCorrelator
@Deprecated public RequestCorrelator(String name, Object transport, RequestHandler handler, boolean deadlock_detection, boolean concurrent_processing) Deprecated. -
RequestCorrelator
@Deprecated public RequestCorrelator(String name, Object transport, RequestHandler handler, boolean deadlock_detection, Address local_addr) Deprecated. -
RequestCorrelator
@Deprecated public RequestCorrelator(String name, Object transport, RequestHandler handler, boolean deadlock_detection, Address local_addr, boolean concurrent_processing) Deprecated. -
RequestCorrelator
@Deprecated public RequestCorrelator(String name, Object transport, RequestHandler handler, Address local_addr, boolean concurrent_processing) Deprecated.
-
-
Method Details
-
setDeadlockDetection
public void setDeadlockDetection(boolean flag) Deprecated.deadlock detection is not needed with a concurrent stackSwitch the deadlock detection mechanism on/off- Parameters:
flag- the deadlock detection flag
-
setRequestHandler
-
setConcurrentProcessing
public void setConcurrentProcessing(boolean concurrent_processing) Deprecated.Not needed since the introduction of the concurrent stack- Parameters:
concurrent_processing-
-
sendRequest
Deprecated.Helper method forsendRequest(long,List,Message,RspCollector).- Throws:
Exception
-
getMarshaller
-
setMarshaller
-
sendRequest
public void sendRequest(long id, List<Address> dest_mbrs, Message msg, RspCollector coll) throws Exception - Throws:
Exception
-
sendRequest
public void sendRequest(long id, Collection<Address> dest_mbrs, Message msg, RspCollector coll, RequestOptions options) throws Exception Sends 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)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 methodsreceiveResponse()andsuspect()will be invoked when a message has been received or a member is suspected, respectively.- Throws:
Exception
-
sendUnicastRequest
public void sendUnicastRequest(long id, Address target, Message msg, RspCollector coll) throws Exception Sends a request to a single destination- Parameters:
id-target-msg-coll-- Throws:
Exception
-
done
public void done(long id) Used to signal that a certain request may be garbage collected as all responses have been received. -
receive
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
-
start
public final void start() -
stop
public void stop() -
registerProbeHandler
-
unregisterProbeHandler
-
receiveSuspect
Event.SUSPECT event received from a layer below.All response collectors currently registered will be notified that
mbrmay have crashed, so they won't wait for its response. -
receiveView
Event.VIEW_CHANGE event received from a layer below.Mark all responses from members that are not in new_view as NOT_RECEIVED.
-
receiveMessage
Handles a message coming from a layer below- Returns:
- true if the message was consumed, don't pass it further up, else false
-
getLocalAddress
-
setLocalAddress
-
handleRequest
Handle a request msg for this correlator- Parameters:
req- the request msg
-
prepareResponse
-