public class MessageDispatcher extends java.lang.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.
Modifier and Type | Field and Description |
---|---|
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 org.jgroups.blocks.MessageDispatcher.PullPushHandler |
handler |
protected java.io.Serializable |
id |
protected Address |
local_addr |
protected org.apache.commons.logging.Log |
log |
protected java.util.Collection |
members |
protected MembershipListener |
membership_listener |
protected MessageListener |
msg_listener |
protected org.jgroups.blocks.MessageDispatcher.ProtocolAdapter |
prot_adapter |
protected RequestHandler |
req_handler |
protected org.jgroups.blocks.MessageDispatcher.TransportAdapter |
transport_adapter |
Modifier and Type | Method and Description |
---|---|
void |
castMessage(java.util.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. |
RspList |
castMessage(java.util.Vector dests,
Message msg,
int mode,
long timeout) |
RspList |
castMessage(java.util.Vector dests,
Message msg,
int mode,
long timeout,
boolean use_anycasting)
Cast a message to all members, and wait for
mode responses. |
protected void |
correlatorStarted() |
void |
done(long req_id) |
Channel |
getChannel()
Offers access to the underlying Channel.
|
protected java.util.Collection |
getMembers()
Returns a copy of members
|
MessageListener |
getMessageListener()
Gives access to the currently configured MessageListener.
|
java.lang.Object |
handle(Message msg) |
void |
send(Message msg) |
java.lang.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() |
protected Channel channel
protected RequestCorrelator corr
protected MessageListener msg_listener
protected MembershipListener membership_listener
protected RequestHandler req_handler
protected org.jgroups.blocks.MessageDispatcher.ProtocolAdapter prot_adapter
protected org.jgroups.blocks.MessageDispatcher.TransportAdapter transport_adapter
protected final java.util.Collection members
protected Address local_addr
protected boolean deadlock_detection
protected PullPushAdapter adapter
protected org.jgroups.blocks.MessageDispatcher.PullPushHandler handler
protected java.io.Serializable id
protected final org.apache.commons.logging.Log log
protected boolean concurrent_processing
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2)
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, boolean deadlock_detection)
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, boolean deadlock_detection, boolean concurrent_processing)
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler)
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler, boolean deadlock_detection)
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler, boolean deadlock_detection, boolean concurrent_processing)
public MessageDispatcher(PullPushAdapter adapter, java.io.Serializable id, MessageListener l, MembershipListener l2)
public MessageDispatcher(PullPushAdapter adapter, java.io.Serializable id, MessageListener l, MembershipListener l2, RequestHandler req_handler)
public MessageDispatcher(PullPushAdapter adapter, java.io.Serializable id, MessageListener l, MembershipListener l2, RequestHandler req_handler, boolean concurrent_processing)
protected java.util.Collection getMembers()
public void setDeadlockDetection(boolean flag)
public void setConcurrentProcessing(boolean flag)
public final void start()
protected void correlatorStarted()
public void stop()
public final void setMessageListener(MessageListener l)
public MessageListener getMessageListener()
public final void setMembershipListener(MembershipListener l)
public final void setRequestHandler(RequestHandler rh)
public Channel getChannel()
public void send(Message msg) throws ChannelNotConnectedException, ChannelClosedException
public RspList castMessage(java.util.Vector dests, Message msg, int mode, long timeout, boolean use_anycasting)
mode
responses. The responses are returned in a response
list, where each response is associated with its sender. Uses GroupRequest
.
dests
- The members to which the message is to be sent. If it is null, then the message is sent to all
membersmsg
- The message to be sent to n membersmode
- Defined in GroupRequest
. The number of responses to wait for: timeout
- If 0: wait forever. Otherwise, wait for mode
responses or timeout time.Object
and associated to its sender.public void castMessage(java.util.Vector dests, long req_id, Message msg, RspCollector coll)
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.dests
- The list of members from which to receive responses. Null means all membersreq_id
- The ID of the request. Used by the underlying RequestCorrelator to correlate responses with
requestsmsg
- The request to be sentcoll
- The sender needs to provide this interface to collect responses. Call will return immediately if
this is nullpublic void done(long req_id)
public java.lang.Object sendMessage(Message msg, int mode, long timeout) throws TimeoutException, SuspectedException
TimeoutException
SuspectedException
public java.lang.Object handle(Message msg)
handle
in interface RequestHandler
Copyright ? 1998-2006 Bela Ban. All Rights Reserved.