Class RpcDispatcher

java.lang.Object
org.jgroups.blocks.MessageDispatcher
org.jgroups.blocks.RpcDispatcher
All Implemented Interfaces:
Closeable, AutoCloseable, RequestHandler, ChannelListener

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.

  • Field Details

  • Constructor Details

    • RpcDispatcher

      public RpcDispatcher()
    • RpcDispatcher

      public RpcDispatcher(JChannel channel, Object server_obj)
  • Method Details

    • getServerObject

      public Object getServerObject()
    • setServerObject

      public RpcDispatcher setServerObject(Object obj)
    • setReceiver

      public RpcDispatcher setReceiver(Receiver r)
      Overrides:
      setReceiver in class MessageDispatcher
    • getMethodLookup

      public MethodLookup getMethodLookup()
    • setMethodLookup

      public RpcDispatcher setMethodLookup(MethodLookup ml)
    • getMethodInvoker

      public MethodInvoker getMethodInvoker()
    • setMethodInvoker

      public RpcDispatcher setMethodInvoker(MethodInvoker mi)
    • callRemoteMethods

      public <T> RspList<T> callRemoteMethods(Collection<Address> dests, String method_name, Object[] args, Class<?>[] types, RequestOptions options) throws 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, or null if the RPC is asynchronous
      Throws:
      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(Collection<Address> dests, MethodCall method_call, RequestOptions opts) throws 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
      opts - 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, or null if the RPC is asynchronous
      Throws:
      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> CompletableFuture<RspList<T>> callRemoteMethodsWithFuture(Collection<Address> dests, MethodCall call, RequestOptions options) throws 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
      call - The method (plus args) to be invoked
      options - A collection of call options, e.g. sync versus async, timeout etc
      Returns:
      CompletableFuture A future from which the results can be fetched, or null if the RPC is asynchronous
      Throws:
      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, String meth, Object[] args, Class<?>[] types, RequestOptions opts) throws 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
      meth - The name of the method
      args - The arguments
      types - The types of the arguments
      opts - The options (e.g. blocking, timeout etc)
      Returns:
      The result. Null if the call is asynchronous (non-blocking) or if the method returns void
      Throws:
      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 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. Null if the call is asynchronous (non-blocking) or if the method returns void
      Throws:
      Exception - Thrown if the method invocation threw an exception, either at the caller or the callee
    • callRemoteMethodWithFuture

      public <T> CompletableFuture<T> callRemoteMethodWithFuture(Address dest, MethodCall call, RequestOptions opts) throws 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
      opts - 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(). If the invocation was asynchronous, null will be returned.
      Throws:
      Exception - Thrown if the method invocation threw an exception
    • handle

      public Object handle(Message req) throws 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
      Parameters:
      req - the message containing the request
      Returns:
      the object, rceeived as result, or null (void method)
      Throws:
      Exception