Package org.apache.hadoop.ipc

Class Client

java.lang.Object
org.apache.hadoop.ipc.Client
All Implemented Interfaces:
AutoCloseable

@Public @Evolving public class Client extends Object implements AutoCloseable
A client for an IPC service. IPC calls take a single Writable as a parameter, and return a Writable as their value. A service runs on a port and is defined by a parameter class and a value class.
See Also:
  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
  • Constructor Details

    • Client

      public Client(Class<? extends Writable> valueClass, Configuration conf, SocketFactory factory)
      Construct an IPC client whose values are of the given Writable class.
      Parameters:
      valueClass - input valueClass.
      conf - input configuration.
      factory - input factory.
    • Client

      public Client(Class<? extends Writable> valueClass, Configuration conf)
      Construct an IPC client with the default SocketFactory.
      Parameters:
      valueClass - input valueClass.
      conf - input Configuration.
  • Method Details

    • getAsyncRpcResponse

      @Unstable public static <T extends Writable> org.apache.hadoop.util.concurrent.AsyncGet<T,IOException> getAsyncRpcResponse()
    • getResponseFuture

      public static <T extends Writable> CompletableFuture<T> getResponseFuture()
      Retrieves the current response future from the thread-local storage.
      Type Parameters:
      T - The type of the value completed by the returned CompletableFuture. It must be a subclass of Writable.
      Returns:
      A CompletableFuture of type T that represents the asynchronous operation. If no response future is present in the thread-local storage, this method returns null.
      See Also:
    • setCallIdAndRetryCount

      public static void setCallIdAndRetryCount(int cid, int rc, Object externalHandler)
      Set call id and retry count for the next call.
      Parameters:
      cid - input cid.
      rc - input rc.
      externalHandler - input externalHandler.
    • setCallIdAndRetryCountUnprotected

      public static void setCallIdAndRetryCountUnprotected(Integer cid, int rc, Object externalHandler)
    • getCallId

      public static int getCallId()
    • getRetryCount

      public static int getRetryCount()
    • getExternalHandler

      public static Object getExternalHandler()
    • getAsyncCallCounter

      @VisibleForTesting public int getAsyncCallCounter()
    • setMaxAsyncCalls

      @VisibleForTesting public void setMaxAsyncCalls(int limits)
    • isAsyncCallCheckEabled

      @VisibleForTesting public boolean isAsyncCallCheckEabled()
    • setPingInterval

      public static final void setPingInterval(Configuration conf, int pingInterval)
      set the ping interval value in configuration
      Parameters:
      conf - Configuration
      pingInterval - the ping interval
    • getPingInterval

      public static final int getPingInterval(Configuration conf)
      Get the ping interval from configuration; If not set in the configuration, return the default value.
      Parameters:
      conf - Configuration
      Returns:
      the ping interval
    • getTimeout

      @Deprecated public static final int getTimeout(Configuration conf)
      Deprecated.
      The time after which a RPC will timeout. If ping is not enabled (via ipc.client.ping), then the timeout value is the same as the pingInterval. If ping is enabled, then there is no timeout value.
      Parameters:
      conf - Configuration
      Returns:
      the timeout period in milliseconds. -1 if no timeout value is set
    • getRpcTimeout

      public static final int getRpcTimeout(Configuration conf)
      The time after which a RPC will timeout.
      Parameters:
      conf - Configuration
      Returns:
      the timeout period in milliseconds.
    • setConnectTimeout

      public static final void setConnectTimeout(Configuration conf, int timeout)
      set the connection timeout value in configuration
      Parameters:
      conf - Configuration
      timeout - the socket connect timeout value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • stop

      public void stop()
      Stop all threads related to this client. No further calls may be made using this client.
    • call

      public Writable call(RPC.RpcKind rpcKind, Writable rpcRequest, org.apache.hadoop.ipc.Client.ConnectionId remoteId, AtomicBoolean fallbackToSimpleAuth) throws IOException
      Make a call, passing rpcRequest, to the IPC server defined by remoteId, returning the rpc respond.
      Parameters:
      rpcKind - - input rpcKind.
      rpcRequest - - contains serialized method and method parameters
      remoteId - - the target rpc server
      fallbackToSimpleAuth - - set to true or false during this method to indicate if a secure client falls back to simple auth
      Returns:
      the rpc response Throws exceptions if there are network problems or if the remote code threw an exception.
      Throws:
      IOException - raised on errors performing I/O.
    • call

      public Writable call(RPC.RpcKind rpcKind, Writable rpcRequest, org.apache.hadoop.ipc.Client.ConnectionId remoteId, AtomicBoolean fallbackToSimpleAuth, org.apache.hadoop.ipc.AlignmentContext alignmentContext) throws IOException
      Throws:
      IOException
    • isAsynchronousMode

      @Unstable public static boolean isAsynchronousMode()
      Check if RPC is in asynchronous mode or not.
      Returns:
      true, if RPC is in asynchronous mode, otherwise false for synchronous mode.
    • setAsynchronousMode

      @Unstable public static void setAsynchronousMode(boolean async)
      Set RPC to asynchronous or synchronous mode.
      Parameters:
      async - true, RPC will be in asynchronous mode, otherwise false for synchronous mode
    • nextCallId

      public static int nextCallId()
      Returns the next valid sequential call ID by incrementing an atomic counter and masking off the sign bit. Valid call IDs are non-negative integers in the range [ 0, 2^31 - 1 ]. Negative numbers are reserved for special purposes. The values can overflow back to 0 and be reused. Note that prior versions of the client did not mask off the sign bit, so a server may still see a negative call ID if it receives connections from an old client.
      Returns:
      next call ID
    • close

      @Unstable public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception