Package org.apache.hadoop.ipc
Class Client
java.lang.Object
org.apache.hadoop.ipc.Client
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classorg.apache.hadoop.ipc.Client.ConnectionIdThis class holds the address and the user ticket.static classorg.apache.hadoop.ipc.Client.IpcStreamsManages the input and output streams for an IPC connection. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionClient(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 givenWritableclass. -
Method Summary
Modifier and TypeMethodDescriptioncall(RPC.RpcKind rpcKind, Writable rpcRequest, org.apache.hadoop.ipc.Client.ConnectionId remoteId, AtomicBoolean fallbackToSimpleAuth) Make a call, passingrpcRequest, to the IPC server defined byremoteId, returning the rpc respond.call(RPC.RpcKind rpcKind, Writable rpcRequest, org.apache.hadoop.ipc.Client.ConnectionId remoteId, AtomicBoolean fallbackToSimpleAuth, org.apache.hadoop.ipc.AlignmentContext alignmentContext) voidclose()intstatic <T extends Writable>
org.apache.hadoop.util.concurrent.AsyncGet<T,IOException> static intstatic Objectstatic final intgetPingInterval(Configuration conf) Get the ping interval from configuration; If not set in the configuration, return the default value.static <T extends Writable>
CompletableFuture<T>Retrieves the current response future from the thread-local storage.static intstatic final intgetRpcTimeout(Configuration conf) The time after which a RPC will timeout.static final intgetTimeout(Configuration conf) Deprecated.booleanstatic booleanCheck if RPC is in asynchronous mode or not.static intReturns the next valid sequential call ID by incrementing an atomic counter and masking off the sign bit.static voidsetAsynchronousMode(boolean async) Set RPC to asynchronous or synchronous mode.static voidsetCallIdAndRetryCount(int cid, int rc, Object externalHandler) Set call id and retry count for the next call.static voidsetCallIdAndRetryCountUnprotected(Integer cid, int rc, Object externalHandler) static final voidsetConnectTimeout(Configuration conf, int timeout) set the connection timeout value in configurationvoidsetMaxAsyncCalls(int limits) static final voidsetPingInterval(Configuration conf, int pingInterval) set the ping interval value in configurationvoidstop()Stop all threads related to this client.toString()
-
Field Details
-
LOG
public static final org.slf4j.Logger LOG
-
-
Constructor Details
-
Client
Construct an IPC client whose values are of the givenWritableclass.- Parameters:
valueClass- input valueClass.conf- input configuration.factory- input factory.
-
Client
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
Retrieves the current response future from the thread-local storage.- Type Parameters:
T- The type of the value completed by the returnedCompletableFuture. It must be a subclass ofWritable.- Returns:
- A
CompletableFutureof type T that represents the asynchronous operation. If no response future is present in the thread-local storage, this method returnsnull. - See Also:
-
setCallIdAndRetryCount
Set call id and retry count for the next call.- Parameters:
cid- input cid.rc- input rc.externalHandler- input externalHandler.
-
setCallIdAndRetryCountUnprotected
-
getCallId
public static int getCallId() -
getRetryCount
public static int getRetryCount() -
getExternalHandler
-
getAsyncCallCounter
@VisibleForTesting public int getAsyncCallCounter() -
setMaxAsyncCalls
@VisibleForTesting public void setMaxAsyncCalls(int limits) -
isAsyncCallCheckEabled
@VisibleForTesting public boolean isAsyncCallCheckEabled() -
setPingInterval
set the ping interval value in configuration- Parameters:
conf- ConfigurationpingInterval- the ping interval
-
getPingInterval
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.usegetRpcTimeout(Configuration)insteadThe 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
The time after which a RPC will timeout.- Parameters:
conf- Configuration- Returns:
- the timeout period in milliseconds.
-
setConnectTimeout
set the connection timeout value in configuration- Parameters:
conf- Configurationtimeout- the socket connect timeout value
-
toString
-
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, passingrpcRequest, to the IPC server defined byremoteId, returning the rpc respond.- Parameters:
rpcKind- - input rpcKind.rpcRequest- - contains serialized method and method parametersremoteId- - the target rpc serverfallbackToSimpleAuth- - 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
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
getRpcTimeout(Configuration)instead