Class PekkoRpcService
- java.lang.Object
-
- org.apache.flink.runtime.rpc.pekko.PekkoRpcService
-
- All Implemented Interfaces:
AutoCloseable
,RpcService
,AutoCloseableAsync
@ThreadSafe public class PekkoRpcService extends Object implements RpcService
Pekko basedRpcService
implementation. The RPC service starts an actor to receive RPC invocations from aRpcGateway
.
-
-
Constructor Summary
Constructors Constructor Description PekkoRpcService(org.apache.pekko.actor.ActorSystem actorSystem, PekkoRpcServiceConfiguration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Void>
closeAsync()
Trigger the closing of the resource and return the corresponding close future.<F extends Serializable,C extends FencedRpcGateway<F>>
CompletableFuture<C>connect(String address, F fencingToken, Class<C> clazz)
Connect to a remote fenced rpc server under the provided address.<C extends RpcGateway>
CompletableFuture<C>connect(String address, Class<C> clazz)
Connect to a remote rpc server under the provided address.org.apache.pekko.actor.ActorSystem
getActorSystem()
String
getAddress()
Return the hostname or host address under which the rpc service can be reached.int
getPort()
Return the port under which the rpc service is reachable.ScheduledExecutor
getScheduledExecutor()
Gets a scheduled executor from the RPC service.<C extends RpcGateway>
CgetSelfGateway(Class<C> selfGatewayType, RpcServer rpcServer)
Returns a self gateway of the specified type which can be used to issue asynchronous calls against the RpcEndpoint.protected int
getVersion()
<C extends RpcEndpoint & RpcGateway>
RpcServerstartServer(C rpcEndpoint, Map<String,String> loggingContext)
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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.util.AutoCloseableAsync
close
-
-
-
-
Constructor Detail
-
PekkoRpcService
@VisibleForTesting public PekkoRpcService(org.apache.pekko.actor.ActorSystem actorSystem, PekkoRpcServiceConfiguration configuration)
-
-
Method Detail
-
getActorSystem
public org.apache.pekko.actor.ActorSystem getActorSystem()
-
getVersion
protected int getVersion()
-
getAddress
public String getAddress()
Description copied from interface:RpcService
Return the hostname or host address under which the rpc service can be reached. If the rpc service cannot be contacted remotely, then it will return an empty string.- Specified by:
getAddress
in interfaceRpcService
- Returns:
- Address of the rpc service or empty string if local rpc service
-
getPort
public int getPort()
Description copied from interface:RpcService
Return the port under which the rpc service is reachable. If the rpc service cannot be contacted remotely, then it will return -1.- Specified by:
getPort
in interfaceRpcService
- Returns:
- Port of the rpc service or -1 if local rpc service
-
getSelfGateway
public <C extends RpcGateway> C getSelfGateway(Class<C> selfGatewayType, RpcServer rpcServer)
Description copied from interface:RpcService
Returns a self gateway of the specified type which can be used to issue asynchronous calls against the RpcEndpoint.IMPORTANT: The self gateway type must be implemented by the RpcEndpoint. Otherwise the method will fail.
- Specified by:
getSelfGateway
in interfaceRpcService
- Type Parameters:
C
- type of the self gateway to create- Parameters:
selfGatewayType
- class of the self gateway type- Returns:
- Self gateway of the specified type which can be used to issue asynchronous rpcs
-
connect
public <C extends RpcGateway> CompletableFuture<C> connect(String address, Class<C> clazz)
Description copied from interface:RpcService
Connect to a remote rpc server under the provided address. Returns a rpc gateway which can be used to communicate with the rpc server. If the connection failed, then the returned future is failed with aRpcConnectionException
.- Specified by:
connect
in interfaceRpcService
- Type Parameters:
C
- Type of the rpc gateway to return- Parameters:
address
- Address of the remote rpc serverclazz
- Class of the rpc gateway to return- Returns:
- Future containing the rpc gateway or an
RpcConnectionException
if the connection attempt failed
-
connect
public <F extends Serializable,C extends FencedRpcGateway<F>> CompletableFuture<C> connect(String address, F fencingToken, Class<C> clazz)
Description copied from interface:RpcService
Connect to a remote fenced rpc server under the provided address. Returns a fenced rpc gateway which can be used to communicate with the rpc server. If the connection failed, then the returned future is failed with aRpcConnectionException
.- Specified by:
connect
in interfaceRpcService
- Type Parameters:
F
- Type of the fencing tokenC
- Type of the rpc gateway to return- Parameters:
address
- Address of the remote rpc serverfencingToken
- Fencing token to be used when communicating with the serverclazz
- Class of the rpc gateway to return- Returns:
- Future containing the fenced rpc gateway or an
RpcConnectionException
if the connection attempt failed
-
startServer
public <C extends RpcEndpoint & RpcGateway> RpcServer startServer(C rpcEndpoint, Map<String,String> loggingContext)
Description copied from interface:RpcService
Start a rpc server which forwards the remote procedure calls to the provided rpc endpoint.- Specified by:
startServer
in interfaceRpcService
- Type Parameters:
C
- Type of the rpc endpoint- Parameters:
rpcEndpoint
- Rpc protocol to dispatch the rpcs to- Returns:
- Self gateway to dispatch remote procedure calls to oneself
-
stopServer
public void stopServer(RpcServer selfGateway)
Description copied from interface:RpcService
Stop the underlying rpc server of the provided self gateway.- Specified by:
stopServer
in interfaceRpcService
- Parameters:
selfGateway
- Self gateway describing the underlying rpc server
-
closeAsync
public CompletableFuture<Void> closeAsync()
Description copied from interface:AutoCloseableAsync
Trigger the closing of the resource and return the corresponding close future.- Specified by:
closeAsync
in interfaceAutoCloseableAsync
- Returns:
- Future which is completed once the resource has been closed
-
getScheduledExecutor
public ScheduledExecutor getScheduledExecutor()
Description copied from interface:RpcService
Gets a scheduled executor from the RPC service. This executor can be used to schedule tasks to be executed in the future.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 theMainThreadExecutionContext
of thatRpcEndpoint
.- Specified by:
getScheduledExecutor
in interfaceRpcService
- Returns:
- The RPC service provided scheduled executor
-
-