Package org.jgroups.blocks
Class RpcDispatcher
java.lang.Object
org.jgroups.blocks.MessageDispatcher
org.jgroups.blocks.RpcDispatcher
- All Implemented Interfaces:
Closeable,AutoCloseable,RequestHandler,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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jgroups.blocks.MessageDispatcher
MessageDispatcher.ProtocolAdapter -
Field Summary
FieldsFields 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 -
Method Summary
Modifier and TypeMethodDescription<T> TcallRemoteMethod(Address dest, String meth, Object[] args, Class<?>[] types, RequestOptions opts) Invokes a method in a cluster member and - if blocking - returns the result<T> TcallRemoteMethod(Address dest, MethodCall call, RequestOptions options) Invokes a method in a cluster member and - if blocking - returns the result<T> RspList<T> callRemoteMethods(Collection<Address> dests, String method_name, Object[] args, 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(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> CompletableFuture<RspList<T>> callRemoteMethodsWithFuture(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> CompletableFuture<T> callRemoteMethodWithFuture(Address dest, MethodCall call, RequestOptions opts) Invokes a method in a cluster member and - if blocking - returns the resultMessage contains MethodCall.setServerObject(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, wrapExceptionsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jgroups.ChannelListener
channelConnected
-
Field Details
-
server_obj
-
method_lookup
-
method_invoker
-
-
Constructor Details
-
RpcDispatcher
public RpcDispatcher() -
RpcDispatcher
-
-
Method Details
-
getServerObject
-
setServerObject
-
setReceiver
- Overrides:
setReceiverin classMessageDispatcher
-
getMethodLookup
-
setMethodLookup
-
getMethodInvoker
-
setMethodInvoker
-
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 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:
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 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:
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 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:
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 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:
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 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:
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 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:
Exception- Thrown if the method invocation threw an exception
-
handle
Message contains MethodCall. Execute it against *this* object and return result. Use MethodCall.invoke() to do this. Return result.- Specified by:
handlein interfaceRequestHandler- Overrides:
handlein classMessageDispatcher- Parameters:
req- the message containing the request- Returns:
- the object, rceeived as result, or null (void method)
- Throws:
Exception
-