Client (Apache Hadoop Main 3.5.0 API)
Description: declaration: package: org.apache.hadoop.ipc, class: Client

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:
  - `Server`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `org.apache.hadoop.ipc.Client.ConnectionId`
  This class holds the address and the user ticket.
  `static class`
  `org.apache.hadoop.ipc.Client.IpcStreams`
  Manages the input and output streams for an IPC connection.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final org.slf4j.Logger`
  `LOG`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Client(Class<? extends Writable> valueClass, Configuration conf)`
  Construct an IPC client with the default SocketFactory.
  `Client(Class<? extends Writable> valueClass, Configuration conf, SocketFactory factory)`
  Construct an IPC client whose values are of the given `Writable` class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Writable`
  `call(RPC.RpcKind rpcKind, Writable rpcRequest, org.apache.hadoop.ipc.Client.ConnectionId remoteId, AtomicBoolean fallbackToSimpleAuth)`
  Make a call, passing `rpcRequest`, to the IPC server defined by `remoteId`, returning the rpc respond.
  `Writable`
  `call(RPC.RpcKind rpcKind, Writable rpcRequest, org.apache.hadoop.ipc.Client.ConnectionId remoteId, AtomicBoolean fallbackToSimpleAuth, org.apache.hadoop.ipc.AlignmentContext alignmentContext)`
  `void`
  `close()`
  `int`
  `getAsyncCallCounter()`
  `static <T extends Writable>
  org.apache.hadoop.util.concurrent.AsyncGet<T,IOException>`
  `getAsyncRpcResponse()`
  `static int`
  `getCallId()`
  `static Object`
  `getExternalHandler()`
  `static final int`
  `getPingInterval(Configuration conf)`
  Get the ping interval from configuration; If not set in the configuration, return the default value.
  `static <T extends Writable>
  CompletableFuture<T>`
  `getResponseFuture()`
  Retrieves the current response future from the thread-local storage.
  `static int`
  `getRetryCount()`
  `static final int`
  `getRpcTimeout(Configuration conf)`
  The time after which a RPC will timeout.
  `static final int`
  `getTimeout(Configuration conf)`
  Deprecated.
  use `getRpcTimeout(Configuration)` instead
  `boolean`
  `isAsyncCallCheckEabled()`
  `static boolean`
  `isAsynchronousMode()`
  Check if RPC is in asynchronous mode or not.
  `static int`
  `nextCallId()`
  Returns the next valid sequential call ID by incrementing an atomic counter and masking off the sign bit.
  `static void`
  `setAsynchronousMode(boolean async)`
  Set RPC to asynchronous or synchronous mode.
  `static void`
  `setCallIdAndRetryCount(int cid, int rc, Object externalHandler)`
  Set call id and retry count for the next call.
  `static void`
  `setCallIdAndRetryCountUnprotected(Integer cid, int rc, Object externalHandler)`
  `static final void`
  `setConnectTimeout(Configuration conf, int timeout)`
  set the connection timeout value in configuration
  `void`
  `setMaxAsyncCalls(int limits)`
  `static final void`
  `setPingInterval(Configuration conf, int pingInterval)`
  set the ping interval value in configuration
  `void`
  `stop()`
  Stop all threads related to this client.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## 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:
      - `CompletableFuture`
      - `Writable`

  - ### 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.
    use `getRpcTimeout(Configuration)` instead
    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`