org.jgroups.blocks
Class RpcDispatcher
java.lang.Object
org.jgroups.blocks.MessageDispatcher
org.jgroups.blocks.RpcDispatcher
- All Implemented Interfaces:
- ChannelListener, RequestHandler
- public class RpcDispatcher
- extends MessageDispatcher
- implements ChannelListener
This class allows a programmer to invoke remote methods in all (or single)
group members and optionally wait for the return value(s).
An application will typically create a channel and layer the
RpcDispatcher building block on top of it, which allows it to
dispatch remote methods (client role) and at the same time be
called by other members (server role).
This class is derived from MessageDispatcher.
Is the equivalent of RpcProtocol on the application rather than protocol level.
- Author:
- Bela Ban
Fields inherited from class org.jgroups.blocks.MessageDispatcher |
adapter, channel, concurrent_processing, corr, deadlock_detection, id, local_addr, log, members, membership_listener, msg_listener, prot_adapter, req_handler, transport_adapter |
Constructor Summary |
RpcDispatcher(Channel channel,
MessageListener l,
MembershipListener l2,
java.lang.Object server_obj)
|
RpcDispatcher(Channel channel,
MessageListener l,
MembershipListener l2,
java.lang.Object server_obj,
boolean deadlock_detection)
|
RpcDispatcher(Channel channel,
MessageListener l,
MembershipListener l2,
java.lang.Object server_obj,
boolean deadlock_detection,
boolean concurrent_processing)
|
RpcDispatcher(PullPushAdapter adapter,
java.io.Serializable id,
MessageListener l,
MembershipListener l2,
java.lang.Object server_obj)
|
Method Summary |
boolean |
addChannelListener(ChannelListener l)
Add a new channel listener to be notified on the channel's state change. |
java.lang.Object |
callRemoteMethod(Address dest,
MethodCall method_call,
int mode,
long timeout)
|
java.lang.Object |
callRemoteMethod(Address dest,
java.lang.String method_name,
java.lang.Object[] args,
java.lang.Class[] types,
int mode,
long timeout)
|
java.lang.Object |
callRemoteMethod(Address dest,
java.lang.String method_name,
java.lang.Object[] args,
java.lang.String[] signature,
int mode,
long timeout)
|
RspList |
callRemoteMethods(java.util.Vector dests,
MethodCall method_call,
int mode,
long timeout)
|
RspList |
callRemoteMethods(java.util.Vector dests,
java.lang.String method_name,
java.lang.Object[] args,
java.lang.Class[] types,
int mode,
long timeout)
|
RspList |
callRemoteMethods(java.util.Vector dests,
java.lang.String method_name,
java.lang.Object[] args,
java.lang.String[] signature,
int mode,
long timeout)
|
RspList |
castMessage(java.util.Vector dests,
Message msg,
int mode,
long timeout)
Cast a message to all members, and wait for mode responses. |
void |
channelClosed(Channel channel)
|
void |
channelConnected(Channel channel)
|
void |
channelDisconnected(Channel channel)
|
void |
channelReconnected(Address new_addr)
|
void |
channelShunned()
|
RpcDispatcher.Marshaller |
getMarshaller()
|
MethodLookup |
getMethodLookup()
|
java.lang.String |
getName()
|
java.lang.Object |
getServerObject()
|
java.lang.Object |
handle(Message req)
Message contains MethodCall. |
boolean |
removeChannelListener(ChannelListener l)
|
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 |
setMarshaller(RpcDispatcher.Marshaller m)
|
void |
setMethodLookup(MethodLookup method_lookup)
|
Methods inherited from class org.jgroups.blocks.MessageDispatcher |
castMessage, done, getChannel, getMessageListener, send, setConcurrentProcessing, setDeadlockDetection, setMembershipListener, setMessageListener, setRequestHandler, start, stop |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
server_obj
protected java.lang.Object server_obj
marshaller
protected RpcDispatcher.Marshaller marshaller
additionalChannelListeners
protected java.util.List additionalChannelListeners
method_lookup
protected MethodLookup method_lookup
RpcDispatcher
public RpcDispatcher(Channel channel,
MessageListener l,
MembershipListener l2,
java.lang.Object server_obj)
RpcDispatcher
public RpcDispatcher(Channel channel,
MessageListener l,
MembershipListener l2,
java.lang.Object server_obj,
boolean deadlock_detection)
RpcDispatcher
public RpcDispatcher(Channel channel,
MessageListener l,
MembershipListener l2,
java.lang.Object server_obj,
boolean deadlock_detection,
boolean concurrent_processing)
RpcDispatcher
public RpcDispatcher(PullPushAdapter adapter,
java.io.Serializable id,
MessageListener l,
MembershipListener l2,
java.lang.Object server_obj)
getName
public java.lang.String getName()
setMarshaller
public void setMarshaller(RpcDispatcher.Marshaller m)
getMarshaller
public RpcDispatcher.Marshaller getMarshaller()
getServerObject
public java.lang.Object getServerObject()
getMethodLookup
public MethodLookup getMethodLookup()
setMethodLookup
public void setMethodLookup(MethodLookup method_lookup)
castMessage
public RspList castMessage(java.util.Vector dests,
Message msg,
int mode,
long timeout)
- Description copied from class:
MessageDispatcher
- Cast a message to all members, and wait for
mode
responses. The responses are returned in a response
list, where each response is associated with its sender. Uses GroupRequest
.
- Overrides:
castMessage
in class MessageDispatcher
- Parameters:
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: - GET_FIRST:
return the first response received.
- GET_ALL: wait for all responses (minus the ones from
suspected members)
- GET_MAJORITY: wait for a majority of all responses (relative to the grp
size)
- GET_ABS_MAJORITY: wait for majority (absolute, computed once)
- GET_N: wait for n
responses (may block if n > group size)
- GET_NONE: wait for no responses, return immediately
(non-blocking)
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.
sendMessage
public java.lang.Object sendMessage(Message msg,
int mode,
long timeout)
throws TimeoutException,
SuspectedException
- Description copied from class:
MessageDispatcher
- Sends a message to a single member (destination = msg.dest) and returns the response. The message's destination
must be non-zero !
- Overrides:
sendMessage
in class MessageDispatcher
- Throws:
TimeoutException
SuspectedException
callRemoteMethods
public RspList callRemoteMethods(java.util.Vector dests,
java.lang.String method_name,
java.lang.Object[] args,
java.lang.Class[] types,
int mode,
long timeout)
callRemoteMethods
public RspList callRemoteMethods(java.util.Vector dests,
java.lang.String method_name,
java.lang.Object[] args,
java.lang.String[] signature,
int mode,
long timeout)
callRemoteMethods
public RspList callRemoteMethods(java.util.Vector dests,
MethodCall method_call,
int mode,
long timeout)
callRemoteMethod
public java.lang.Object callRemoteMethod(Address dest,
java.lang.String method_name,
java.lang.Object[] args,
java.lang.Class[] types,
int mode,
long timeout)
throws TimeoutException,
SuspectedException
- Throws:
TimeoutException
SuspectedException
callRemoteMethod
public java.lang.Object callRemoteMethod(Address dest,
java.lang.String method_name,
java.lang.Object[] args,
java.lang.String[] signature,
int mode,
long timeout)
throws TimeoutException,
SuspectedException
- Throws:
TimeoutException
SuspectedException
callRemoteMethod
public java.lang.Object callRemoteMethod(Address dest,
MethodCall method_call,
int mode,
long timeout)
throws TimeoutException,
SuspectedException
- Throws:
TimeoutException
SuspectedException
handle
public java.lang.Object handle(Message req)
- Message contains MethodCall. Execute it against *this* object and return result.
Use MethodCall.invoke() to do this. Return result.
- Specified by:
handle
in interface RequestHandler
- Overrides:
handle
in class MessageDispatcher
addChannelListener
public boolean addChannelListener(ChannelListener l)
- Add a new channel listener to be notified on the channel's state change.
- Returns:
- true if the listener was added or false if the listener was already in the list.
removeChannelListener
public boolean removeChannelListener(ChannelListener l)
- Returns:
- true if the channel was removed indeed.
channelConnected
public void channelConnected(Channel channel)
- Specified by:
channelConnected
in interface ChannelListener
channelDisconnected
public void channelDisconnected(Channel channel)
- Specified by:
channelDisconnected
in interface ChannelListener
channelClosed
public void channelClosed(Channel channel)
- Specified by:
channelClosed
in interface ChannelListener
channelShunned
public void channelShunned()
- Specified by:
channelShunned
in interface ChannelListener
channelReconnected
public void channelReconnected(Address new_addr)
- Specified by:
channelReconnected
in interface ChannelListener
Copyright ? 1998-2005 Bela Ban. All Rights Reserved.