Class RPC

java.lang.Object
org.apache.hadoop.ipc.RPC

@LimitedPrivate({"Common","HDFS","MapReduce","Yarn"}) @Evolving public class RPC extends Object
A simple RPC mechanism. A protocol is a Java interface. All parameters and return types must be one of:
  • a primitive type, boolean, byte, char, short, int, long, float, double, or void; or
  • a String; or
  • a Writable; or
  • an array of the above types
All methods in the protocol should throw only IOException. No field data of the protocol instance is transmitted.
  • Method Details

    • getProtocolName

      public static String getProtocolName(Class<?> protocol)
      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

      public static long getProtocolVersion(Class<?> protocol)
      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

      public static void setProtocolEngine(Configuration conf, Class<?> protocol, Class<?> engine)
      Set a protocol to use a non-default RpcEngine if one is not specified in the configuration.
      Parameters:
      conf - configuration to use
      protocol - the protocol interface
      engine - 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 class
      clientVersion - client version
      addr - remote address
      conf - 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 class
      clientVersion - client version
      addr - remote address
      conf - 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 class
      clientVersion - client version
      addr - remote address
      conf - configuration to use
      connTimeout - 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 class
      clientVersion - client version
      addr - remote address
      conf - configuration to use
      connTimeout - 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 class
      clientVersion - client version
      addr - remote address
      conf - configuration to use
      rpcTimeout - timeout for each RPC
      timeout - 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 class
      clientVersion - client version
      addr - remote address
      conf - configuration to use
      rpcTimeout - timeout for each RPC
      connectionRetryPolicy - 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 class
      clientVersion - client version
      addr - remote address
      conf - configuration to use
      factory - 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 class
      clientVersion - client version
      addr - remote address
      ticket - user group information
      conf - configuration to use
      factory - 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 class
      clientVersion - client's version
      connId - client connection identifier
      conf - configuration
      factory - 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 class
      clientVersion - client's version
      connId - client connection identifier
      conf - configuration
      factory - socket factory
      alignmentContext - 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 - protocol
      clientVersion - client's version
      addr - server address
      ticket - security ticket
      conf - configuration
      factory - socket factory
      rpcTimeout - 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 - protocol
      clientVersion - client's version
      addr - server address
      ticket - security ticket
      conf - configuration
      factory - socket factory
      rpcTimeout - max time for each rpc; 0 means no timeout
      connectionRetryPolicy - 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 - protocol
      clientVersion - client's version
      addr - server address
      ticket - security ticket
      conf - configuration
      factory - socket factory
      rpcTimeout - max time for each rpc; 0 means no timeout
      connectionRetryPolicy - retry policy
      fallbackToSimpleAuth - 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 - protocol
      clientVersion - client's version
      addr - server address
      ticket - security ticket
      conf - configuration
      factory - socket factory
      rpcTimeout - max time for each rpc; 0 means no timeout
      connectionRetryPolicy - retry policy
      fallbackToSimpleAuth - set to true or false during calls to indicate if a secure client falls back to simple auth
      alignmentContext - 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

      public static InetSocketAddress getServerAddress(Object proxy)
      Parameters:
      proxy - input proxy.
      Returns:
      Returns the server address for a given proxy.
    • getConnectionIdForProxy

      public static Client.ConnectionId getConnectionIdForProxy(Object proxy)
      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

      public static void stopProxy(Object proxy)
      Stop the proxy. Proxy must either implement Closeable or must have associated RpcInvocationHandler.
      Parameters:
      proxy - the RPC proxy object to be stopped
      Throws:
      HadoopIllegalArgumentException - if the proxy does not implement Closeable interface or does not have closeable InvocationHandler
    • getRpcTimeout

      public static int getRpcTimeout(Configuration conf)
      Get the RPC time from configuration; If not set in the configuration, return the default value.
      Parameters:
      conf - Configuration
      Returns:
      the RPC timeout (ms)