|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jgroups.blocks.MessageDispatcher
public class MessageDispatcher
Provides synchronous and asynchronous message sending with request-response correlation; i.e., matching responses with the original request. It also offers push-style message reception (by internally using the PullPushAdapter).
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 java.util.concurrent.atomic.AtomicInteger |
async_anycasts
|
protected java.util.concurrent.atomic.AtomicInteger |
async_multicasts
|
protected java.util.concurrent.atomic.AtomicInteger |
async_unicasts
|
protected Channel |
channel
|
protected java.util.Set<ChannelListener> |
channel_listeners
|
protected RequestCorrelator |
corr
|
protected boolean |
hardware_multicast_supported
|
protected Address |
local_addr
|
protected Log |
log
|
protected java.util.Collection<Address> |
members
|
protected MembershipListener |
membership_listener
|
protected MessageListener |
msg_listener
|
protected DiagnosticsHandler.ProbeHandler |
probe_handler
|
protected org.jgroups.blocks.MessageDispatcher.ProtocolAdapter |
prot_adapter
|
protected RequestHandler |
req_handler
|
protected java.util.concurrent.atomic.AtomicInteger |
sync_anycasts
|
protected java.util.concurrent.atomic.AtomicInteger |
sync_multicasts
|
protected java.util.concurrent.atomic.AtomicInteger |
sync_unicasts
|
Constructor Summary | |
---|---|
MessageDispatcher()
|
|
MessageDispatcher(Channel channel,
MessageListener l,
MembershipListener l2)
|
|
MessageDispatcher(Channel channel,
MessageListener l,
MembershipListener l2,
RequestHandler req_handler)
|
Method Summary | ||
---|---|---|
void |
addChannelListener(ChannelListener l)
Adds a new channel listener to be notified on the channel's state change. |
|
protected
|
cast(java.util.Collection<Address> dests,
Message msg,
RequestOptions options,
boolean block_for_results)
|
|
|
castMessage(java.util.Collection<Address> dests,
Message msg,
RequestOptions options)
Sends a message to all members and expects responses from members in dests (if non-null). |
|
|
castMessageWithFuture(java.util.Collection<Address> dests,
Message msg,
RequestOptions options)
Sends a message to all members and expects responses from members in dests (if non-null). |
|
void |
channelClosed(Channel channel)
Channel has been closed notification callback |
|
void |
channelConnected(Channel channel)
Channel has been connected notification callback |
|
void |
channelDisconnected(Channel channel)
Channel has been disconnected notification callback |
|
protected void |
correlatorStarted()
|
|
protected RequestCorrelator |
createRequestCorrelator(Protocol transport,
RequestHandler handler,
Address local_addr)
|
|
void |
done(long req_id)
|
|
Channel |
getChannel()
|
|
MessageListener |
getMessageListener()
|
|
UpHandler |
getProtocolAdapter()
|
|
java.lang.Object |
handle(Message msg)
|
|
protected java.lang.Object |
handleUpEvent(Event evt)
|
|
protected void |
installUpHandler(UpHandler handler,
boolean canReplace)
Sets the given UpHandler as the UpHandler for the channel, or, if the channel already has a Muxer installed as it's UpHandler, sets the given handler as the Muxer's default handler . |
|
void |
removeChannelListener(ChannelListener l)
|
|
|
sendMessage(Message msg,
RequestOptions opts)
Sends a unicast message and - depending on the options - returns a result |
|
|
sendMessageWithFuture(Message msg,
RequestOptions options)
Sends a unicast message to the target defined by msg.getDest() and returns a future |
|
void |
setChannel(Channel ch)
|
|
protected void |
setMembers(java.util.List<Address> new_mbrs)
If this dispatcher is using a user-provided PullPushAdapter, then need to set the members from the adapter initially since viewChange has most likely already been called in PullPushAdapter. |
|
void |
setMembershipListener(MembershipListener l)
|
|
void |
setMessageListener(MessageListener l)
|
|
void |
setRequestHandler(RequestHandler rh)
|
|
void |
start()
|
|
void |
stop()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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 volatile java.util.Collection<Address> members
protected Address local_addr
protected final Log log
protected boolean hardware_multicast_supported
protected final java.util.concurrent.atomic.AtomicInteger sync_unicasts
protected final java.util.concurrent.atomic.AtomicInteger async_unicasts
protected final java.util.concurrent.atomic.AtomicInteger sync_multicasts
protected final java.util.concurrent.atomic.AtomicInteger async_multicasts
protected final java.util.concurrent.atomic.AtomicInteger sync_anycasts
protected final java.util.concurrent.atomic.AtomicInteger async_anycasts
protected final java.util.Set<ChannelListener> channel_listeners
protected final DiagnosticsHandler.ProbeHandler probe_handler
Constructor Detail |
---|
public MessageDispatcher()
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2)
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler)
Method Detail |
---|
public UpHandler getProtocolAdapter()
protected void setMembers(java.util.List<Address> new_mbrs)
public void addChannelListener(ChannelListener l)
public void removeChannelListener(ChannelListener l)
public void start()
protected RequestCorrelator createRequestCorrelator(Protocol transport, RequestHandler handler, Address local_addr)
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 setChannel(Channel ch)
protected void installUpHandler(UpHandler handler, boolean canReplace)
default handler
.
If the relevant handler is already installed, the canReplace
controls whether this method replaces it (after logging a WARN) or simply
leaves handler
uninstalled.
Passing false
as the canReplace
value allows
callers to use this method to install defaults without concern about
inadvertently overriding
handler
- the UpHandler to installcanReplace
- true
if an existing Channel upHandler or
Muxer default upHandler can be replaced; false
if this method shouldn't installpublic <T> RspList<T> castMessage(java.util.Collection<Address> dests, Message msg, RequestOptions options) throws java.lang.Exception
dests
- A list of group members from which to expect responses (if the call is blocking).msg
- The message to be sentoptions
- A set of options that govern the call. See RequestOptions
for details
java.lang.Exception
- If the request cannot be sentpublic <T> NotifyingFuture<RspList<T>> castMessageWithFuture(java.util.Collection<Address> dests, Message msg, RequestOptions options) throws java.lang.Exception
dests
- A list of group members from which to expect responses (if the call is blocking).msg
- The message to be sentoptions
- A set of options that govern the call. See RequestOptions
for details
java.lang.Exception
- If the request cannot be sentprotected <T> GroupRequest<T> cast(java.util.Collection<Address> dests, Message msg, RequestOptions options, boolean block_for_results) throws java.lang.Exception
java.lang.Exception
public void done(long req_id)
public <T> T sendMessage(Message msg, RequestOptions opts) throws java.lang.Exception
msg
- the message to be sent. The destination needs to be non-nullopts
- the options to be used
java.lang.Exception
- If there was problem sending the request, processing it at the receiver, or processing
it at the sender.
TimeoutException
- If the call didn't succeed within the timeout defined in options (if set)public <T> NotifyingFuture<T> sendMessageWithFuture(Message msg, RequestOptions options) throws java.lang.Exception
msg
- The unicast message to be sent. msg.getDest() must not be nulloptions
-
java.lang.Exception
- If there was problem sending the request, processing it at the receiver, or processing
it at the sender. Future.get()
will throw this exception
TimeoutException
- If the call didn't succeed within the timeout defined in options (if set)public java.lang.Object handle(Message msg) throws java.lang.Exception
handle
in interface RequestHandler
java.lang.Exception
public void channelConnected(Channel channel)
ChannelListener
channelConnected
in interface ChannelListener
channel
- the channel that has been connectedpublic void channelDisconnected(Channel channel)
ChannelListener
channelDisconnected
in interface ChannelListener
channel
- the disconnected channelpublic void channelClosed(Channel channel)
ChannelListener
channelClosed
in interface ChannelListener
channel
- the closed channelprotected java.lang.Object handleUpEvent(Event evt) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |