Package alluxio

Class AbstractClient

  • All Implemented Interfaces:
    Client, java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    AbstractMasterClient

    @ThreadSafe
    public abstract class AbstractClient
    extends java.lang.Object
    implements Client
    AbstractClient is the base class for all the grpc clients in alluxio. It provides framework methods for the grpc workflow like connection, version checking and automatic retrying for rpc calls.

    Concrete Child classes extend this class by filling in the missing component, like where to find the actual server address queryGrpcServerAddress(), and rpc callables to retryRPC(RpcCallable, Logger, String, String, Object...) that carries actual logic.

    • Field Detail

      • mServerAddress

        protected GrpcServerAddress mServerAddress
        Grpc Address of the remote server. This field is lazily initialized by queryGrpcServerAddress(), and could only be null right after instantiation and before use.
      • mChannel

        protected GrpcChannel mChannel
        Underlying channel to the target service.
      • mVersionService

        protected alluxio.grpc.ServiceVersionClientServiceGrpc.ServiceVersionClientServiceBlockingStub mVersionService
      • mConnected

        protected boolean mConnected
        Is true if this client is currently connected.
      • mClosed

        protected volatile boolean mClosed
        Is true if this client was closed by the user. No further actions are possible after the client is closed.
      • mServiceVersion

        protected long mServiceVersion
        Stores the actual remote service version, used to compare with expected local version.
      • mContext

        protected ClientContext mContext
        Context of the client.
    • Constructor Detail

      • AbstractClient

        protected AbstractClient​(ClientContext context)
        Creates a new client base with default retry policy supplier.
        Parameters:
        context - information required to connect to Alluxio
      • AbstractClient

        protected AbstractClient​(ClientContext context,
                                 java.util.function.Supplier<RetryPolicy> retryPolicySupplier)
        Creates a new client base with specified retry policy supplier.
        Parameters:
        context - information required to connect to Alluxio
        retryPolicySupplier - factory for retry policies to be used when performing RPCs
    • Method Detail

      • getRemoteServiceType

        protected abstract alluxio.grpc.ServiceType getRemoteServiceType()
        Returns:
        the expected type of remote service
      • getServiceName

        protected abstract java.lang.String getServiceName()
        Returns:
        a string representing the specific service
      • getServiceVersion

        protected abstract long getServiceVersion()
        Returns:
        the client service version
      • checkVersion

        protected void checkVersion​(long clientVersion)
                             throws java.io.IOException
        Checks that the service version is compatible with the client.
        Parameters:
        clientVersion - the client version
        Throws:
        java.io.IOException
      • afterConnect

        protected void afterConnect()
                             throws java.io.IOException
        This method is called after the connection is made to the remote. Implementations should create internal state to finish the connection process.
        Throws:
        java.io.IOException
      • beforeConnect

        protected void beforeConnect()
                              throws java.io.IOException
        This method is called before the connection is connected. Implementations should add any additional operations before the connection is connected. loading the cluster defaults
        Throws:
        java.io.IOException
      • afterDisconnect

        protected void afterDisconnect()
        This method is called after the connection is disconnected. Implementations should clean up any additional state created for the connection.
      • beforeDisconnect

        protected void beforeDisconnect()
        This method is called before the connection is disconnected. Implementations should add any additional operations before the connection is disconnected.
      • connectWithRuntimeException

        public void connectWithRuntimeException()
        Connects with the remote server.
        Throws:
        AlluxioRuntimeException - network connection error
      • disconnect

        public void disconnect()
        Description copied from interface: Client
        Closes the connection with the Alluxio remote and does the necessary cleanup. It should be used if the client has not connected with the remote for a while, for example.
        Specified by:
        disconnect in interface Client
      • isConnected

        public boolean isConnected()
        Description copied from interface: Client
        Returns the connected status of the client.
        Specified by:
        isConnected in interface Client
        Returns:
        true if this client is connected to the remote
      • close

        public void close()
        Closes the connection with the remote permanently. This instance should be not be reused after closing.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • getConfAddress

        public java.net.InetSocketAddress getConfAddress()
                                                  throws UnavailableException
        By default, return the same underlying address as getRemoteSockAddress(). Child classes should override this implementation if they intend to have different address to fetch configuration.
        Specified by:
        getConfAddress in interface Client
        Returns:
        the remote address of the configuration server
        Throws:
        UnavailableException - if address cannot be determined
      • retryRPC

        protected <V> V retryRPC​(AbstractClient.RpcCallable<V> rpc,
                                 org.slf4j.Logger logger,
                                 java.lang.String rpcName,
                                 java.lang.String description,
                                 java.lang.Object... args)
                          throws AlluxioStatusException
        Tries to execute an RPC defined as a AbstractClient.RpcCallable. Metrics will be recorded based on the provided rpc name. If a UnavailableException occurs, a reconnection will be tried through connect() and the action will be re-executed.
        Type Parameters:
        V - type of return value of the RPC call
        Parameters:
        rpc - the RPC call to be executed
        logger - the logger to use for this call
        rpcName - the human-readable name of the RPC call
        description - the format string of the description, used for logging
        args - the arguments for the description
        Returns:
        the return value of the RPC call
        Throws:
        AlluxioStatusException - status exception
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface Client
        Returns:
        whether the client is closed