public class MessageDispatcher extends java.lang.Object implements AsyncRequestHandler, ChannelListener
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.
限定符和类型 | 字段和说明 |
---|---|
protected java.util.concurrent.atomic.AtomicInteger |
async_anycasts |
protected boolean |
async_dispatching |
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 com.fr.third.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 |
构造器和说明 |
---|
MessageDispatcher() |
MessageDispatcher(Channel channel,
MessageListener l,
MembershipListener l2) |
MessageDispatcher(Channel channel,
MessageListener l,
MembershipListener l2,
RequestHandler req_handler) |
MessageDispatcher(Channel channel,
RequestHandler req_handler) |
限定符和类型 | 方法和说明 |
---|---|
void |
addChannelListener(ChannelListener l)
Adds a new channel listener to be notified on the channel's state change.
|
boolean |
asyncDispatching() |
MessageDispatcher |
asyncDispatching(boolean flag) |
protected <T> GroupRequest<T> |
cast(java.util.Collection<Address> dests,
Message msg,
RequestOptions options,
boolean block_for_results) |
protected <T> GroupRequest<T> |
cast(java.util.Collection<Address> dests,
Message msg,
RequestOptions options,
boolean block_for_results,
FutureListener<RspList<T>> listener) |
<T> RspList<T> |
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).
|
<T> NotifyingFuture<RspList<T>> |
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).
|
<T> NotifyingFuture<RspList<T>> |
castMessageWithFuture(java.util.Collection<Address> dests,
Message msg,
RequestOptions options,
FutureListener<RspList<T>> listener)
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) |
void |
handle(Message request,
Response response)
Invokes a request.
|
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) |
<T> T |
sendMessage(Message msg,
RequestOptions opts)
Sends a unicast message and - depending on the options - returns a result
|
<T> NotifyingFuture<T> |
sendMessageWithFuture(Message msg,
RequestOptions options)
Sends a unicast message to the target defined by msg.getDest() and returns a future
|
<T> NotifyingFuture<T> |
sendMessageWithFuture(Message msg,
RequestOptions options,
FutureListener<T> listener)
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() |
protected Channel channel
protected RequestCorrelator corr
protected MessageListener msg_listener
protected MembershipListener membership_listener
protected RequestHandler req_handler
protected boolean async_dispatching
protected com.fr.third.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
public MessageDispatcher()
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2)
public MessageDispatcher(Channel channel, RequestHandler req_handler)
public MessageDispatcher(Channel channel, MessageListener l, MembershipListener l2, RequestHandler req_handler)
public boolean asyncDispatching()
public MessageDispatcher asyncDispatching(boolean flag)
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 detailsjava.lang.Exception
- If the request cannot be sentpublic <T> NotifyingFuture<RspList<T>> castMessageWithFuture(java.util.Collection<Address> dests, Message msg, RequestOptions options, FutureListener<RspList<T>> listener) 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 detailslistener
- A FutureListener which will be registered (if non null) with the future before the call is invokedjava.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 detailsjava.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, FutureListener<RspList<T>> listener) throws java.lang.Exception
java.lang.Exception
protected <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 usedjava.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, FutureListener<T> listener) throws java.lang.Exception
msg
- The unicast message to be sent. msg.getDest() must not be nulloptions
- listener
- A FutureListener which will be registered (if non null) with the future before the call is invokedjava.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 exceptionTimeoutException
- 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 exceptionTimeoutException
- 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
在接口中 RequestHandler
java.lang.Exception
public void handle(Message request, Response response) throws java.lang.Exception
AsyncRequestHandler
Response.send(Object, boolean)
should
be called.handle
在接口中 AsyncRequestHandler
request
- The requestresponse
- The response implementation. Contains information needed to send the reply (e.g. a request ID).
If no response is required, e.g. because this is an asynchronous RPC, then response will be null.java.lang.Exception
- If an exception is thrown (e.g. in case of an issue submitting the request to a thread pool,
the exception will be taken as return value and will be sent as a response. In this case,
Response.send(Object, boolean)
must not be calledpublic void channelConnected(Channel channel)
ChannelListener
channelConnected
在接口中 ChannelListener
channel
- the channel that has been connectedpublic void channelDisconnected(Channel channel)
ChannelListener
channelDisconnected
在接口中 ChannelListener
channel
- the disconnected channelpublic void channelClosed(Channel channel)
ChannelListener
channelClosed
在接口中 ChannelListener
channel
- the closed channelprotected java.lang.Object handleUpEvent(Event evt) throws java.lang.Exception
java.lang.Exception