Package org.apache.flink.runtime.rpc
Interface RpcService
-
- All Superinterfaces:
AutoCloseable,org.apache.flink.util.AutoCloseableAsync
public interface RpcService extends org.apache.flink.util.AutoCloseableAsyncInterface for rpc services. An rpc service is used to start and connect to aRpcEndpoint. Connecting to a rpc server will return aRpcGatewaywhich can be used to call remote procedures.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <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.StringgetAddress()Return the hostname or host address under which the rpc service can be reached.intgetPort()Return the port under which the rpc service is reachable.org.apache.flink.util.concurrent.ScheduledExecutorgetScheduledExecutor()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.<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.voidstopServer(RpcServer selfGateway)Stop the underlying rpc server of the provided self gateway.
-
-
-
Method Detail
-
getAddress
String getAddress()
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.- Returns:
- Address of the rpc service or empty string if local rpc service
-
getPort
int getPort()
Return the port under which the rpc service is reachable. If the rpc service cannot be contacted remotely, then it will return -1.- Returns:
- Port of the rpc service or -1 if local rpc service
-
getSelfGateway
<C extends RpcGateway> C getSelfGateway(Class<C> selfGatewayType, RpcServer rpcServer)
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.
- 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
<C extends RpcGateway> CompletableFuture<C> connect(String address, Class<C> clazz)
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.- 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
RpcConnectionExceptionif the connection attempt failed
-
connect
<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. 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.- 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
RpcConnectionExceptionif the connection attempt failed
-
startServer
<C extends RpcEndpoint & RpcGateway> RpcServer startServer(C rpcEndpoint, Map<String,String> loggingContext)
Start a rpc server which forwards the remote procedure calls to the provided rpc endpoint.- Type Parameters:
C- Type of the rpc endpoint- Parameters:
rpcEndpoint- Rpc protocol to dispatch the rpcs tologgingContext-- Returns:
- Self gateway to dispatch remote procedure calls to oneself
-
stopServer
void stopServer(RpcServer selfGateway)
Stop the underlying rpc server of the provided self gateway.- Parameters:
selfGateway- Self gateway describing the underlying rpc server
-
getScheduledExecutor
org.apache.flink.util.concurrent.ScheduledExecutor getScheduledExecutor()
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 theMainThreadExecutionContextof thatRpcEndpoint.- Returns:
- The RPC service provided scheduled executor
-
-