org.jgroups.blocks
public class MessageDispatcher extends Object implements RequestHandler
Channels are simple patterns to asynchronously send a receive messages. However, a significant number of communication patterns in group communication require synchronous communication. For example, a sender would like to send a message to the group and wait for all responses. Or another application would like to send a message to the group and wait only until the majority of the receivers have sent a response, or until a timeout occurred. MessageDispatcher offers a combination of the above pattern with other patterns.
Used on top of channel to implement group requests. Client's handle()
method is called when request is received. Is the equivalent of RpcProtocol on
the application instead of protocol level.
Field Summary | |
---|---|
protected PullPushAdapter | adapter |
protected Channel | channel |
protected boolean | concurrent_processing
Process items on the queue concurrently (RequestCorrelator). |
protected RequestCorrelator | corr |
protected boolean | deadlock_detection |
protected Serializable | id |
protected Address | local_addr |
protected Log | log |
protected Collection | members |
protected MembershipListener | membership_listener |
protected MessageListener | msg_listener |
protected MessageDispatcher.ProtocolAdapter | prot_adapter |
protected RequestHandler | req_handler |
protected MessageDispatcher.TransportAdapter | transport_adapter |
Method Summary | |
---|---|
RspList | castMessage(Vector dests, Message msg, int mode, long timeout)
Cast a message to all members, and wait for mode responses. |
void | castMessage(Vector dests, long req_id, Message msg, RspCollector coll)
Multicast a message request to all members in dests and receive responses via the RspCollector
interface. |
void | done(long req_id) |
Channel | getChannel()
Offers access to the underlying Channel. |
MessageListener | getMessageListener()
Gives access to the currently configured MessageListener. |
Object | handle(Message msg) |
void | send(Message msg) |
Object | sendMessage(Message msg, int mode, long timeout)
Sends a message to a single member (destination = msg.dest) and returns the response. |
void | setConcurrentProcessing(boolean flag) |
void | setDeadlockDetection(boolean flag) |
void | setMembershipListener(MembershipListener l) |
void | setMessageListener(MessageListener l) |
void | setRequestHandler(RequestHandler rh) |
void | start() |
void | stop() |
mode
responses. The responses are returned in a response
list, where each response is associated with its sender. Uses GroupRequest
.
Parameters: dests The members to which the message is to be sent. If it is null, then the message is sent to all
members msg The message to be sent to n members mode Defined in GroupRequest
. The number of responses to wait for:
timeout If 0: wait forever. Otherwise, wait for mode
responses or timeout time.
Returns: RspList A list of responses. Each response is an Object
and associated to its sender.
dests
and receive responses via the RspCollector
interface. When done receiving the required number of responses, the caller has to call done(req_id) on the
underlyinh RequestCorrelator, so that the resources allocated to that request can be freed.
Parameters: dests The list of members from which to receive responses. Null means all members req_id The ID of the request. Used by the underlying RequestCorrelator to correlate responses with requests msg The request to be sent coll The sender needs to provide this interface to collect responses. Call will return immediately if this is null
Returns: a reference to the underlying Channel.