Package org.apache.hadoop.ipc
Class RPC
java.lang.Object
org.apache.hadoop.ipc.RPC
A simple RPC mechanism.
A protocol is a Java interface. All parameters and return types must
be one of:
All methods in the protocol should throw only IOException. No field data of
the protocol instance is transmitted.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass to construct instances of RPC server with specific options.static enumstatic classAn RPC Server.static classA version mismatch for the RPC protocol. -
Method Summary
Modifier and TypeMethodDescriptionstatic Client.ConnectionIdgetConnectionIdForProxy(Object proxy) Return the connection ID of the given object.static StringgetProtocolName(Class<?> protocol) Get the protocol name.static <T> ProtocolProxy<T>getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the serverstatic <T> ProtocolProxy<T>getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, SocketFactory factory) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.static <T> ProtocolProxy<T>getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the serverstatic <T> ProtocolProxy<T>getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.static <T> ProtocolProxy<T>getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy, AtomicBoolean fallbackToSimpleAuth) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.static <T> ProtocolProxy<T>getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy, AtomicBoolean fallbackToSimpleAuth, AlignmentContext alignmentContext) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.static <T> ProtocolProxy<T>getProtocolProxy(Class<T> protocol, long clientVersion, Client.ConnectionId connId, Configuration conf, SocketFactory factory) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.static <T> ProtocolProxy<T>getProtocolProxy(Class<T> protocol, long clientVersion, Client.ConnectionId connId, Configuration conf, SocketFactory factory, AlignmentContext alignmentContext) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.static longgetProtocolVersion(Class<?> protocol) Get the protocol version from protocol class.static <T> TgetProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) Construct a client-side proxy object with the default SocketFactory.static <T> TgetProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, SocketFactory factory) Construct a client-side proxy object that implements the named protocol, talking to a server at the named address.static <T> TgetProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory) Construct a client-side proxy object that implements the named protocol, talking to a server at the named address.static <T> TgetProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout) Construct a client-side proxy that implements the named protocol, talking to a server at the named address.static intgetRpcTimeout(Configuration conf) Get the RPC time from configuration; If not set in the configuration, return the default value.static InetSocketAddressgetServerAddress(Object proxy) static voidsetProtocolEngine(Configuration conf, Class<?> protocol, Class<?> engine) Set a protocol to use a non-default RpcEngine if one is not specified in the configuration.static voidStop the proxy.static <T> ProtocolProxy<T>waitForProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.static <T> ProtocolProxy<T>waitForProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, int rpcTimeout, RetryPolicy connectionRetryPolicy, long timeout) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.static <T> ProtocolProxy<T>waitForProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, long connTimeout) Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the serverstatic <T> TwaitForProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) Get a proxy connection to a remote server.static <T> TwaitForProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, int rpcTimeout, long timeout) Get a proxy connection to a remote server.static <T> TwaitForProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, long connTimeout) Get a proxy connection to a remote server.
-
Method Details
-
getProtocolName
Get the protocol name. If the protocol class has a ProtocolAnnotation, then get the protocol name from the annotation; otherwise the class name is the protocol name.- Parameters:
protocol- input protocol.- Returns:
- protocol name.
-
getProtocolVersion
Get the protocol version from protocol class. If the protocol class has a ProtocolAnnotation, then get the protocol version from the annotation; otherwise get it from the versionID field of the protocol class.- Parameters:
protocol- input protocol.- Returns:
- ProtocolVersion.
-
setProtocolEngine
Set a protocol to use a non-default RpcEngine if one is not specified in the configuration.- Parameters:
conf- configuration to useprotocol- the protocol interfaceengine- the RpcEngine impl
-
waitForProxy
public static <T> T waitForProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) throws IOException Get a proxy connection to a remote server.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocol classclientVersion- client versionaddr- remote addressconf- configuration to use- Returns:
- the proxy
- Throws:
IOException- if the far end through a RemoteException
-
waitForProtocolProxy
public static <T> ProtocolProxy<T> waitForProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocol classclientVersion- client versionaddr- remote addressconf- configuration to use- Returns:
- the protocol proxy
- Throws:
IOException- if the far end through a RemoteException
-
waitForProxy
public static <T> T waitForProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, long connTimeout) throws IOException Get a proxy connection to a remote server.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocol classclientVersion- client versionaddr- remote addressconf- configuration to useconnTimeout- time in milliseconds before giving up- Returns:
- the proxy
- Throws:
IOException- if the far end through a RemoteException
-
waitForProtocolProxy
public static <T> ProtocolProxy<T> waitForProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, long connTimeout) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocol classclientVersion- client versionaddr- remote addressconf- configuration to useconnTimeout- time in milliseconds before giving up- Returns:
- the protocol proxy
- Throws:
IOException- if the far end through a RemoteException
-
waitForProxy
public static <T> T waitForProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, int rpcTimeout, long timeout) throws IOException Get a proxy connection to a remote server.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocol classclientVersion- client versionaddr- remote addressconf- configuration to userpcTimeout- timeout for each RPCtimeout- time in milliseconds before giving up- Returns:
- the proxy
- Throws:
IOException- if the far end through a RemoteException
-
waitForProtocolProxy
public static <T> ProtocolProxy<T> waitForProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, int rpcTimeout, RetryPolicy connectionRetryPolicy, long timeout) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.- Type Parameters:
T- Generics Type.- Parameters:
protocol- protocol classclientVersion- client versionaddr- remote addressconf- configuration to userpcTimeout- timeout for each RPCconnectionRetryPolicy- input connectionRetryPolicy.timeout- time in milliseconds before giving up- Returns:
- the proxy
- Throws:
IOException- if the far end through a RemoteException.
-
getProxy
public static <T> T getProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, SocketFactory factory) throws IOException Construct a client-side proxy object that implements the named protocol, talking to a server at the named address.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- input protocol.clientVersion- input clientVersion.addr- input addr.conf- input Configuration.factory- input factory.- Returns:
- proxy.
- Throws:
IOException- raised on errors performing I/O.
-
getProtocolProxy
public static <T> ProtocolProxy<T> getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, SocketFactory factory) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocol classclientVersion- client versionaddr- remote addressconf- configuration to usefactory- socket factory- Returns:
- the protocol proxy
- Throws:
IOException- if the far end through a RemoteException
-
getProxy
public static <T> T getProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory) throws IOException Construct a client-side proxy object that implements the named protocol, talking to a server at the named address.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- input protocol.clientVersion- input clientVersion.addr- input addr.ticket- input tocket.conf- input conf.factory- input factory.- Returns:
- the protocol proxy.
- Throws:
IOException- raised on errors performing I/O.
-
getProtocolProxy
public static <T> ProtocolProxy<T> getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocol classclientVersion- client versionaddr- remote addressticket- user group informationconf- configuration to usefactory- socket factory- Returns:
- the protocol proxy
- Throws:
IOException- if the far end through a RemoteException
-
getProtocolProxy
public static <T> ProtocolProxy<T> getProtocolProxy(Class<T> protocol, long clientVersion, Client.ConnectionId connId, Configuration conf, SocketFactory factory) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.- Type Parameters:
T- Generics Type T- Parameters:
protocol- protocol classclientVersion- client's versionconnId- client connection identifierconf- configurationfactory- socket factory- Returns:
- the protocol proxy
- Throws:
IOException- if the far end through a RemoteException
-
getProtocolProxy
public static <T> ProtocolProxy<T> getProtocolProxy(Class<T> protocol, long clientVersion, Client.ConnectionId connId, Configuration conf, SocketFactory factory, AlignmentContext alignmentContext) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.- Type Parameters:
T- Generics Type T- Parameters:
protocol- protocol classclientVersion- client's versionconnId- client connection identifierconf- configurationfactory- socket factoryalignmentContext- StateID alignment context- Returns:
- the protocol proxy
- Throws:
IOException- if the far end through a RemoteException
-
getProxy
public static <T> T getProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout) throws IOException Construct a client-side proxy that implements the named protocol, talking to a server at the named address.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocolclientVersion- client's versionaddr- server addressticket- security ticketconf- configurationfactory- socket factoryrpcTimeout- max time for each rpc; 0 means no timeout- Returns:
- the proxy
- Throws:
IOException- if any error occurs
-
getProtocolProxy
public static <T> ProtocolProxy<T> getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocolclientVersion- client's versionaddr- server addressticket- security ticketconf- configurationfactory- socket factoryrpcTimeout- max time for each rpc; 0 means no timeoutconnectionRetryPolicy- retry policy- Returns:
- the proxy
- Throws:
IOException- if any error occurs
-
getProtocolProxy
public static <T> ProtocolProxy<T> getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy, AtomicBoolean fallbackToSimpleAuth) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocolclientVersion- client's versionaddr- server addressticket- security ticketconf- configurationfactory- socket factoryrpcTimeout- max time for each rpc; 0 means no timeoutconnectionRetryPolicy- retry policyfallbackToSimpleAuth- set to true or false during calls to indicate if a secure client falls back to simple auth- Returns:
- the proxy
- Throws:
IOException- if any error occurs
-
getProtocolProxy
public static <T> ProtocolProxy<T> getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout, RetryPolicy connectionRetryPolicy, AtomicBoolean fallbackToSimpleAuth, AlignmentContext alignmentContext) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- protocolclientVersion- client's versionaddr- server addressticket- security ticketconf- configurationfactory- socket factoryrpcTimeout- max time for each rpc; 0 means no timeoutconnectionRetryPolicy- retry policyfallbackToSimpleAuth- set to true or false during calls to indicate if a secure client falls back to simple authalignmentContext- state alignment context- Returns:
- the proxy
- Throws:
IOException- if any error occurs
-
getProxy
public static <T> T getProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) throws IOException Construct a client-side proxy object with the default SocketFactory.- Type Parameters:
T- Generics Type T.- Parameters:
protocol- input protocol.clientVersion- input clientVersion.addr- input addr.conf- input Configuration.- Returns:
- a proxy instance
- Throws:
IOException- if the thread is interrupted.
-
getServerAddress
- Parameters:
proxy- input proxy.- Returns:
- Returns the server address for a given proxy.
-
getConnectionIdForProxy
Return the connection ID of the given object. If the provided object is in fact a protocol translator, we'll get the connection ID of the underlying proxy object.- Parameters:
proxy- the proxy object to get the connection ID of.- Returns:
- the connection ID for the provided proxy object.
-
getProtocolProxy
public static <T> ProtocolProxy<T> getProtocolProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf) throws IOException Get a protocol proxy that contains a proxy connection to a remote server and a set of methods that are supported by the server- Type Parameters:
T- Generics Type T.- Parameters:
protocol- input protocol.clientVersion- input clientVersion.addr- input addr.conf- input configuration.- Returns:
- a protocol proxy
- Throws:
IOException- if the thread is interrupted.
-
stopProxy
Stop the proxy. Proxy must either implementCloseableor must have associatedRpcInvocationHandler.- Parameters:
proxy- the RPC proxy object to be stopped- Throws:
HadoopIllegalArgumentException- if the proxy does not implementCloseableinterface or does not have closeableInvocationHandler
-
getRpcTimeout
Get the RPC time from configuration; If not set in the configuration, return the default value.- Parameters:
conf- Configuration- Returns:
- the RPC timeout (ms)
-