Package org.jgroups.blocks
Class RpcDispatcher
- java.lang.Object
-
- org.jgroups.blocks.MessageDispatcher
-
- org.jgroups.blocks.RpcDispatcher
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.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.- Author:
- Bela Ban
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jgroups.blocks.MessageDispatcher
MessageDispatcher.ProtocolAdapter
-
-
Field Summary
Fields Modifier and Type Field Description protected MethodInvoker
method_invoker
protected MethodLookup
method_lookup
protected java.lang.Object
server_obj
-
Fields inherited from class org.jgroups.blocks.MessageDispatcher
async_dispatching, async_rsp_handling, channel, corr, empty_group_request, empty_rsplist, local_addr, log, members, prot_adapter, receiver, req_handler, wrap_exceptions
-
-
Constructor Summary
Constructors Constructor Description RpcDispatcher()
RpcDispatcher(JChannel channel, java.lang.Object server_obj)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
callRemoteMethod(Address dest, java.lang.String meth, java.lang.Object[] args, java.lang.Class<?>[] types, RequestOptions opts)
Invokes a method in a cluster member and - if blocking - returns the result<T> T
callRemoteMethod(Address dest, MethodCall call, RequestOptions options)
Invokes a method in a cluster member and - if blocking - returns the result<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> RspList<T>
callRemoteMethods(java.util.Collection<Address> dests, MethodCall method_call, RequestOptions opts)
Invokes a method in all members and expects responses from members contained in dests (or all members if dests is null).<T> java.util.concurrent.CompletableFuture<RspList<T>>
callRemoteMethodsWithFuture(java.util.Collection<Address> dests, MethodCall 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> java.util.concurrent.CompletableFuture<T>
callRemoteMethodWithFuture(Address dest, MethodCall call, RequestOptions opts)
Invokes a method in a cluster member and - if blocking - returns the resultMethodInvoker
getMethodInvoker()
MethodLookup
getMethodLookup()
java.lang.Object
getServerObject()
java.lang.Object
handle(Message req)
Message contains MethodCall.RpcDispatcher
setMethodInvoker(MethodInvoker mi)
RpcDispatcher
setMethodLookup(MethodLookup ml)
RpcDispatcher
setReceiver(Receiver r)
RpcDispatcher
setServerObject(java.lang.Object obj)
-
Methods inherited from class org.jgroups.blocks.MessageDispatcher
_sendMessage, asyncDispatching, asyncDispatching, asyncRspHandling, asyncRspHandling, cast, castMessage, castMessageWithFuture, channelClosed, channelDisconnected, close, correlator, correlator, createRequestCorrelator, getAsyncDispatching, getChannel, getCorrelator, getProtocolAdapter, getState, getWrapExceptions, handle, handleUpEvent, installUpHandler, protocolAdapter, rpcStats, sendMessage, sendMessageWithFuture, setAsynDispatching, setChannel, setCorrelator, setMembers, setRequestHandler, setState, setWrapExceptions, start, stop, wrapExceptions, wrapExceptions
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgroups.ChannelListener
channelConnected
-
-
-
-
Field Detail
-
server_obj
protected java.lang.Object server_obj
-
method_lookup
protected MethodLookup method_lookup
-
method_invoker
protected MethodInvoker method_invoker
-
-
Constructor Detail
-
RpcDispatcher
public RpcDispatcher()
-
RpcDispatcher
public RpcDispatcher(JChannel channel, java.lang.Object server_obj)
-
-
Method Detail
-
getServerObject
public java.lang.Object getServerObject()
-
setServerObject
public RpcDispatcher setServerObject(java.lang.Object obj)
-
setReceiver
public RpcDispatcher setReceiver(Receiver r)
- Overrides:
setReceiver
in classMessageDispatcher
-
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(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 membersmethod_name
- The name of the target methodargs
- The arguments to be passedtypes
- The types of the argumentsoptions
- 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:
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 opts) 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 membersmethod_call
- The method (plus args) to be invokedopts
- 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:
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> java.util.concurrent.CompletableFuture<RspList<T>> callRemoteMethodsWithFuture(java.util.Collection<Address> dests, MethodCall 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 memberscall
- The method (plus args) to be invokedoptions
- 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:
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 meth, java.lang.Object[] args, java.lang.Class<?>[] types, RequestOptions opts) 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 methodmeth
- The name of the methodargs
- The argumentstypes
- The types of the argumentsopts
- 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:
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 methodcall
- The call to be invoked, including method are argumentsoptions
- 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:
java.lang.Exception
- Thrown if the method invocation threw an exception, either at the caller or the callee
-
callRemoteMethodWithFuture
public <T> java.util.concurrent.CompletableFuture<T> callRemoteMethodWithFuture(Address dest, MethodCall call, RequestOptions opts) 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 methodcall
- The call to be invoked, including method are argumentsopts
- 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:
java.lang.Exception
- Thrown if the method invocation threw an exception
-
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 interfaceRequestHandler
- Overrides:
handle
in classMessageDispatcher
- Parameters:
req
- the message containing the request- Returns:
- the object, rceeived as result, or null (void method)
- Throws:
java.lang.Exception
-
-