Interface RpcService

  • All Superinterfaces:
    AutoCloseable, org.apache.flink.util.AutoCloseableAsync

    public interface RpcService
    extends org.apache.flink.util.AutoCloseableAsync
    Interface for rpc services. An rpc service is used to start and connect to a RpcEndpoint. Connecting to a rpc server will return a RpcGateway which can be used to call remote procedures.
    • 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 RpcGatewayCompletableFuture<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 a RpcConnectionException.
        Type Parameters:
        C - Type of the rpc gateway to return
        Parameters:
        address - Address of the remote rpc server
        clazz - Class of the rpc gateway to return
        Returns:
        Future containing the rpc gateway or an RpcConnectionException if 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 a RpcConnectionException.
        Type Parameters:
        F - Type of the fencing token
        C - Type of the rpc gateway to return
        Parameters:
        address - Address of the remote rpc server
        fencingToken - Fencing token to be used when communicating with the server
        clazz - Class of the rpc gateway to return
        Returns:
        Future containing the fenced rpc gateway or an RpcConnectionException if the connection attempt failed
      • startServer

        <C extends RpcEndpoint & RpcGatewayRpcServer 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 to
        loggingContext -
        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 the MainThreadExecutionContext of that RpcEndpoint.

        Returns:
        The RPC service provided scheduled executor