org.jgroups.blocks
Class RpcDispatcher

java.lang.Object
  extended by org.jgroups.blocks.MessageDispatcher
      extended by org.jgroups.blocks.RpcDispatcher
All Implemented Interfaces:
RequestHandler, ChannelListener
Direct Known Subclasses:
MuxRpcDispatcher

public class RpcDispatcher
extends MessageDispatcher

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

Nested Class Summary
static interface RpcDispatcher.Marshaller
           
 
Field Summary
protected  MethodLookup method_lookup
           
protected  RpcDispatcher.Marshaller req_marshaller
          Marshaller to marshall requests at the caller and unmarshal requests at the receiver(s)
protected  RpcDispatcher.Marshaller rsp_marshaller
          Marshaller to marshal responses at the receiver(s) and unmarshal responses at the caller
protected  java.lang.Object server_obj
           
 
Fields inherited from class org.jgroups.blocks.MessageDispatcher
async_anycasts, async_multicasts, async_unicasts, channel, channel_listeners, corr, hardware_multicast_supported, local_addr, log, members, membership_listener, msg_listener, probe_handler, prot_adapter, req_handler, sync_anycasts, sync_multicasts, sync_unicasts
 
Constructor Summary
RpcDispatcher()
           
RpcDispatcher(Channel channel, MessageListener l, MembershipListener l2, java.lang.Object server_obj)
           
RpcDispatcher(Channel channel, java.lang.Object server_obj)
           
 
Method Summary
<T> T
callRemoteMethod(Address dest, MethodCall call, RequestOptions options)
          Invokes a method in a cluster member and - if blocking - returns the result
<T> T
callRemoteMethod(Address dest, java.lang.String method_name, java.lang.Object[] args, java.lang.Class[] types, RequestOptions options)
          Invokes a method in a cluster member and - if blocking - returns the result
<T> RspList<T>
callRemoteMethods(java.util.Collection<Address> dests, MethodCall method_call, RequestOptions options)
          Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null).
<T> RspList<T>
callRemoteMethods(java.util.Collection<Address> dests, java.lang.String method_name, java.lang.Object[] args, java.lang.Class[] types, RequestOptions options)
          Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null).
<T> NotifyingFuture<RspList<T>>
callRemoteMethodsWithFuture(java.util.Collection<Address> dests, MethodCall method_call, RequestOptions options)
          Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null).
<T> NotifyingFuture<T>
callRemoteMethodWithFuture(Address dest, MethodCall call, RequestOptions options)
          Invokes a method in a cluster member and - if blocking - returns the result
protected  void correlatorStarted()
           
 RpcDispatcher.Marshaller getMarshaller()
           
 MethodLookup getMethodLookup()
           
static java.lang.String getName()
           
 RpcDispatcher.Marshaller getRequestMarshaller()
           
 RpcDispatcher.Marshaller getResponseMarshaller()
           
 java.lang.Object getServerObject()
           
 java.lang.Object handle(Message req)
          Message contains MethodCall.
 void setMarshaller(RpcDispatcher.Marshaller m)
           
 void setMethodLookup(MethodLookup method_lookup)
           
 void setRequestMarshaller(RpcDispatcher.Marshaller m)
           
 void setResponseMarshaller(RpcDispatcher.Marshaller m)
           
 void setServerObject(java.lang.Object server_obj)
           
 
Methods inherited from class org.jgroups.blocks.MessageDispatcher
addChannelListener, cast, castMessage, castMessageWithFuture, channelClosed, channelConnected, channelDisconnected, createRequestCorrelator, done, getChannel, getMessageListener, getProtocolAdapter, handleUpEvent, installUpHandler, removeChannelListener, sendMessage, sendMessageWithFuture, setChannel, setMembers, setMembershipListener, setMessageListener, setRequestHandler, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server_obj

protected java.lang.Object server_obj

req_marshaller

protected RpcDispatcher.Marshaller req_marshaller
Marshaller to marshall requests at the caller and unmarshal requests at the receiver(s)


rsp_marshaller

protected RpcDispatcher.Marshaller rsp_marshaller
Marshaller to marshal responses at the receiver(s) and unmarshal responses at the caller


method_lookup

protected MethodLookup method_lookup
Constructor Detail

RpcDispatcher

public RpcDispatcher()

RpcDispatcher

public RpcDispatcher(Channel channel,
                     MessageListener l,
                     MembershipListener l2,
                     java.lang.Object server_obj)

RpcDispatcher

public RpcDispatcher(Channel channel,
                     java.lang.Object server_obj)
Method Detail

getName

public static java.lang.String getName()

getRequestMarshaller

public RpcDispatcher.Marshaller getRequestMarshaller()

setRequestMarshaller

public void setRequestMarshaller(RpcDispatcher.Marshaller m)

getResponseMarshaller

public RpcDispatcher.Marshaller getResponseMarshaller()

setResponseMarshaller

public void setResponseMarshaller(RpcDispatcher.Marshaller m)

getMarshaller

public RpcDispatcher.Marshaller getMarshaller()

setMarshaller

public void setMarshaller(RpcDispatcher.Marshaller m)

getServerObject

public java.lang.Object getServerObject()

setServerObject

public void setServerObject(java.lang.Object server_obj)

getMethodLookup

public MethodLookup getMethodLookup()

setMethodLookup

public void setMethodLookup(MethodLookup method_lookup)

callRemoteMethods

public <T> RspList<T> callRemoteMethods(java.util.Collection<Address> dests,
                                        java.lang.String method_name,
                                        java.lang.Object[] args,
                                        java.lang.Class[] types,
                                        RequestOptions options)
                             throws java.lang.Exception
Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null).

Parameters:
dests - A list of addresses. If null, we'll wait for responses from all cluster members
method_name - The name of the target method
args - The arguments to be passed
types - The types of the arguments
options - A collection of call options, e.g. sync versus async, timeout etc
Returns:
RspList A response list with results, one for each member in dests
Throws:
java.lang.Exception - If the sending of the message threw an exception. Note that no exception will be thrown if any of the target members threw an exception, but this exception will be in the Rsp object for the particular member in the RspList

callRemoteMethods

public <T> RspList<T> callRemoteMethods(java.util.Collection<Address> dests,
                                        MethodCall method_call,
                                        RequestOptions options)
                             throws java.lang.Exception
Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null).

Parameters:
dests - A list of addresses. If null, we'll wait for responses from all cluster members
method_call - The method (plus args) to be invoked
options - A collection of call options, e.g. sync versus async, timeout etc
Returns:
RspList A list of return values and flags (suspected, not received) per member
Throws:
java.lang.Exception - If the sending of the message threw an exception. Note that no exception will be thrown if any of the target members threw an exception, but this exception will be in the Rsp object for the particular member in the RspList
Since:
2.9

callRemoteMethodsWithFuture

public <T> NotifyingFuture<RspList<T>> callRemoteMethodsWithFuture(java.util.Collection<Address> dests,
                                                                   MethodCall method_call,
                                                                   RequestOptions options)
                                                        throws java.lang.Exception
Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null).

Parameters:
dests - A list of addresses. If null, we'll wait for responses from all cluster members
method_call - The method (plus args) to be invoked
options - A collection of call options, e.g. sync versus async, timeout etc
Returns:
NotifyingFuture A future from which the results can be fetched
Throws:
java.lang.Exception - If the sending of the message threw an exception. Note that no exception will be thrown if any of the target members threw an exception; such an exception will be in the Rsp element for the particular member in the RspList

callRemoteMethod

public <T> T callRemoteMethod(Address dest,
                              java.lang.String method_name,
                              java.lang.Object[] args,
                              java.lang.Class[] types,
                              RequestOptions options)
                   throws java.lang.Exception
Invokes a method in a cluster member and - if blocking - returns the result

Parameters:
dest - The target member on which to invoke the method
method_name - The name of the method
args - The arguments
types - The types of the arguments
options - The options (e.g. blocking, timeout etc)
Returns:
The result
Throws:
java.lang.Exception - Thrown if the method invocation threw an exception, either at the caller or the callee

callRemoteMethod

public <T> T callRemoteMethod(Address dest,
                              MethodCall call,
                              RequestOptions options)
                   throws java.lang.Exception
Invokes a method in a cluster member and - if blocking - returns the result

Parameters:
dest - The target member on which to invoke the method
call - The call to be invoked, including method are arguments
options - The options (e.g. blocking, timeout etc)
Returns:
The result
Throws:
java.lang.Exception - Thrown if the method invocation threw an exception, either at the caller or the callee

callRemoteMethodWithFuture

public <T> NotifyingFuture<T> callRemoteMethodWithFuture(Address dest,
                                                         MethodCall call,
                                                         RequestOptions options)
                                              throws java.lang.Exception
Invokes a method in a cluster member and - if blocking - returns the result

Parameters:
dest - The target member on which to invoke the method
call - The call to be invoked, including method are arguments
options - The options (e.g. blocking, timeout etc)
Returns:
A future from which the result can be fetched. If the callee threw an invocation, an ExecutionException will be thrown on calling Future.get().
Throws:
java.lang.Exception - Thrown if the method invocation threw an exception

correlatorStarted

protected void correlatorStarted()
Overrides:
correlatorStarted in class MessageDispatcher

handle

public java.lang.Object handle(Message req)
                        throws java.lang.Exception
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
Throws:
java.lang.Exception


Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.