@ThreadSafe public class AkkaRpcService extends Object implements RpcService
RpcService implementation. The RPC service starts an Akka actor to receive
RPC invocations from a RpcGateway.| Constructor and Description |
|---|
AkkaRpcService(akka.actor.ActorSystem actorSystem,
AkkaRpcServiceConfiguration configuration) |
| Modifier and Type | Method and Description |
|---|---|
<C extends RpcGateway> |
connect(String address,
Class<C> clazz)
Connect to a remote rpc server under the provided address.
|
<F extends Serializable,C extends FencedRpcGateway<F>> |
connect(String address,
F fencingToken,
Class<C> clazz)
Connect to a remote fenced rpc server under the provided address.
|
<T> CompletableFuture<T> |
execute(Callable<T> callable)
Execute the given callable and return its result as a
CompletableFuture. |
void |
execute(Runnable runnable)
Execute the given runnable in the executor of the RPC service.
|
<F extends Serializable> |
fenceRpcServer(RpcServer rpcServer,
F fencingToken)
Fence the given RpcServer with the given fencing token.
|
akka.actor.ActorSystem |
getActorSystem() |
String |
getAddress()
Return the hostname or host address under which the rpc service can be reached.
|
Executor |
getExecutor()
Gets the executor, provided by this RPC service.
|
int |
getPort()
Return the port under which the rpc service is reachable.
|
ScheduledExecutor |
getScheduledExecutor()
Gets a scheduled executor from the RPC service.
|
CompletableFuture<Void> |
getTerminationFuture()
Returns a future indicating when the RPC service has been shut down.
|
protected int |
getVersion() |
ScheduledFuture<?> |
scheduleRunnable(Runnable runnable,
long delay,
TimeUnit unit)
Execute the runnable in the execution context of this RPC Service, as returned by
RpcService.getExecutor(), after a scheduled delay. |
<C extends RpcEndpoint & RpcGateway> |
startServer(C rpcEndpoint)
Start a rpc server which forwards the remote procedure calls to the provided rpc endpoint.
|
void |
stopServer(RpcServer selfGateway)
Stop the underlying rpc server of the provided self gateway.
|
CompletableFuture<Void> |
stopService()
Trigger the asynchronous stopping of the
RpcService. |
public AkkaRpcService(akka.actor.ActorSystem actorSystem,
AkkaRpcServiceConfiguration configuration)
public akka.actor.ActorSystem getActorSystem()
protected int getVersion()
public String getAddress()
RpcServicegetAddress in interface RpcServicepublic int getPort()
RpcServicegetPort in interface RpcServicepublic <C extends RpcGateway> CompletableFuture<C> connect(String address, Class<C> clazz)
RpcServiceRpcConnectionException.connect in interface RpcServiceC - Type of the rpc gateway to returnaddress - Address of the remote rpc serverclazz - Class of the rpc gateway to returnRpcConnectionException if the
connection attempt failedpublic <F extends Serializable,C extends FencedRpcGateway<F>> CompletableFuture<C> connect(String address, F fencingToken, Class<C> clazz)
RpcServiceRpcConnectionException.connect in interface RpcServiceF - Type of the fencing tokenC - Type of the rpc gateway to returnaddress - Address of the remote rpc serverfencingToken - Fencing token to be used when communicating with the serverclazz - Class of the rpc gateway to returnRpcConnectionException if the
connection attempt failedpublic <C extends RpcEndpoint & RpcGateway> RpcServer startServer(C rpcEndpoint)
RpcServicestartServer in interface RpcServiceC - Type of the rpc endpointrpcEndpoint - Rpc protocol to dispatch the rpcs topublic <F extends Serializable> RpcServer fenceRpcServer(RpcServer rpcServer, F fencingToken)
RpcServiceFencing the RpcServer means that we fix the fencing token to the provided value.
All RPCs will then be enriched with this fencing token. This expects that the receiving
RPC endpoint extends FencedRpcEndpoint.
fenceRpcServer in interface RpcServiceF - type of the fencing tokenrpcServer - to fence with the given fencing tokenfencingToken - to fence the RpcServer withpublic void stopServer(RpcServer selfGateway)
RpcServicestopServer in interface RpcServiceselfGateway - Self gateway describing the underlying rpc serverpublic CompletableFuture<Void> stopService()
RpcServiceRpcService.stopService in interface RpcServiceRpcService has been
fully stopped.public CompletableFuture<Void> getTerminationFuture()
RpcServicegetTerminationFuture in interface RpcServicepublic Executor getExecutor()
RpcServicehandleAsync(...) or thenAcceptAsync(...) methods of futures.
IMPORTANT: This executor does not isolate the method invocations against
any concurrent invocations and is therefore not suitable to run completion methods of futures
that modify state of an RpcEndpoint. For such operations, one needs to use the
MainThreadExecutionContext of that
RpcEndpoint.
getExecutor in interface RpcServicepublic ScheduledExecutor getScheduledExecutor()
RpcServiceIMPORTANT: This executor does not isolate the method invocations against
any concurrent invocations and is therefore not suitable to run completion methods of futures
that modify state of an RpcEndpoint. For such operations, one needs to use the
MainThreadExecutionContext of that
RpcEndpoint.
getScheduledExecutor in interface RpcServicepublic ScheduledFuture<?> scheduleRunnable(Runnable runnable, long delay, TimeUnit unit)
RpcServiceRpcService.getExecutor(), after a scheduled delay.scheduleRunnable in interface RpcServicerunnable - Runnable to be executeddelay - The delay after which the runnable will be executedpublic void execute(Runnable runnable)
RpcServiceRpcEndpoint.
IMPORTANT: This executor does not isolate the method invocations against
any concurrent invocations and is therefore not suitable to run completion methods of futures
that modify state of an RpcEndpoint. For such operations, one needs to use the
MainThreadExecutionContext of that
RpcEndpoint.
execute in interface RpcServicerunnable - to executepublic <T> CompletableFuture<T> execute(Callable<T> callable)
RpcServiceCompletableFuture. This method can be used
to run code outside of the main thread of a RpcEndpoint.
IMPORTANT: This executor does not isolate the method invocations against
any concurrent invocations and is therefore not suitable to run completion methods of futures
that modify state of an RpcEndpoint. For such operations, one needs to use the
MainThreadExecutionContext of that
RpcEndpoint.
execute in interface RpcServiceT - is the return value typecallable - to executeCopyright © 2014–2020 The Apache Software Foundation. All rights reserved.