## org.apache.hadoop.ipc
Class Server

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

Direct Known Subclasses:
  RPC.Server

    public abstract class Server

extends Object

An abstract 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:
  `Client`

Nested Class Summary
`class` `Server.Connection` Reads calls from a connection and queues them for handling.

Field Summary
`static byte` `CURRENT_VERSION`
`static ByteBuffer` `HEADER` The first four bytes of Hadoop RPC connections
`static org.apache.commons.logging.Log` `LOG`
`protected RpcInstrumentation` `rpcMetrics`

Constructor Summary
`protected` `Server(String bindAddress, int port, Class<? extends Writable> paramClass, int handlerCount, Configuration conf)`
`protected` `Server(String bindAddress, int port, Class<? extends Writable> paramClass, int handlerCount, Configuration conf, String serverName)`
`protected` `Server(String bindAddress, int port, Class<? extends Writable> paramClass, int handlerCount, Configuration conf, String serverName, SecretManager<? extends TokenIdentifier> secretManager)` Constructs a server listening on the named port and address.

Method Summary
`void` `authorize(UserGroupInformation user, org.apache.hadoop.ipc.ConnectionHeader connection, InetAddress addr)` Authorize the incoming client connection.
`static void` `bind(ServerSocket socket, InetSocketAddress address, int backlog)` A convenience method to bind to a given address and report better exceptions if the address is not a valid host.
`abstract Writable` `call(Class<?> protocol, Writable param, long receiveTime)` Called for each call.
`Writable` `call(Writable param, long receiveTime)` Deprecated. Use `call(Class, Writable, long)` instead
`static Server` `get()` Returns the server instance called under or null.
`int` `getCallQueueLen()` The number of rpc calls in the queue.
`InetSocketAddress` `getListenerAddress()` Return the socket (ip+port) on which the RPC server is listening to.
`int` `getNumOpenConnections()` The number of open RPC conections
`static String` `getRemoteAddress()` Returns remote address as a string when invoked inside an RPC.
`static InetAddress` `getRemoteIp()` Returns the remote side ip address when invoked inside an RPC Returns null incase of an error.
`RpcInstrumentation` `getRpcMetrics()` Returns a handle to the rpcMetrics (required in tests)
`void` `join()` Wait for the server to be stopped.
`void` `setSocketSendBufSize(int size)` Sets the socket buffer size used for responding to RPCs
`void` `start()` Starts the service.
`void` `stop()` Stops the service.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### HEADER

    public static final ByteBuffer HEADER

  The first four bytes of Hadoop RPC connections

### CURRENT_VERSION

    public static final byte CURRENT_VERSION

See Also:
  Constant Field Values

### LOG

    public static final org.apache.commons.logging.Log LOG

### rpcMetrics

    protected RpcInstrumentation rpcMetrics

Constructor Detail

### Server

    protected Server(String bindAddress,
                     int port,
                     Class<? extends Writable> paramClass,
                     int handlerCount,
                     Configuration conf)
              throws IOException

Throws:
  `IOException`

### Server

    protected Server(String bindAddress,
                     int port,
                     Class<? extends Writable> paramClass,
                     int handlerCount,
                     Configuration conf,
                     String serverName)
              throws IOException

Throws:
  `IOException`

### Server

    protected Server(String bindAddress,
                     int port,
                     Class<? extends Writable> paramClass,
                     int handlerCount,
                     Configuration conf,
                     String serverName,
                     SecretManager<? extends TokenIdentifier> secretManager)
              throws IOException

  Constructs a server listening on the named port and address. Parameters passed must be of the named class. The `handlerCount</handlerCount> determines the number of handler threads that will be used to process calls.

  Throws:
    `IOException`
  `

Method Detail

### get

    public static Server get()

  Returns the server instance called under or null. May be called under `call(Writable, long)` implementations, and under `Writable` methods of paramters and return values. Permits applications to access the server context.

### getRemoteIp

    public static InetAddress getRemoteIp()

  Returns the remote side ip address when invoked inside an RPC Returns null incase of an error.

### getRemoteAddress

    public static String getRemoteAddress()

  Returns remote address as a string when invoked inside an RPC. Returns null in case of an error.

### bind

    public static void bind(ServerSocket socket,
                            InetSocketAddress address,
                            int backlog)
                     throws IOException

  A convenience method to bind to a given address and report better exceptions if the address is not a valid host.

  Parameters:
    `socket` - the socket to bind
    `address` - the address to bind to
    `backlog` - the number of connections allowed in the queue
  Throws:
    `BindException` - if the address can't be bound
    `UnknownHostException` - if the address isn't a valid host name
    `IOException` - other random errors from bind

### getRpcMetrics

    public RpcInstrumentation getRpcMetrics()

  Returns a handle to the rpcMetrics (required in tests)

  Returns:
    rpc metrics

### setSocketSendBufSize

    public void setSocketSendBufSize(int size)

  Sets the socket buffer size used for responding to RPCs

### start

    public void start()

  Starts the service. Must be called before any calls will be handled.

### stop

    public void stop()

  Stops the service. No new calls will be handled after this is called.

### join

    public void join()
              throws InterruptedException

  Wait for the server to be stopped. Does not wait for all subthreads to finish. See `stop()`.

  Throws:
    `InterruptedException`

### getListenerAddress

    public InetSocketAddress getListenerAddress()

  Return the socket (ip+port) on which the RPC server is listening to.

  Returns:
    the socket (ip+port) on which the RPC server is listening to.

### call

    @Deprecated
    public Writable call(Writable param,
                                    long receiveTime)
                  throws IOException

  Deprecated. Use `call(Class, Writable, long)` instead

  Called for each call.

  Throws:
    `IOException`

### call

    public abstract Writable call(Class<?> protocol,
                                  Writable param,
                                  long receiveTime)
                           throws IOException

  Called for each call.

  Throws:
    `IOException`

### authorize

    public void authorize(UserGroupInformation user,
                          org.apache.hadoop.ipc.ConnectionHeader connection,
                          InetAddress addr)
                   throws AuthorizationException

  Authorize the incoming client connection.

  Parameters:
    `user` - client user
    `connection` - incoming connection
    `addr` - InetAddress of incoming connection
  Throws:
    `AuthorizationException` - when the client isn't authorized to talk the protocol

### getNumOpenConnections

    public int getNumOpenConnections()

  The number of open RPC conections

  Returns:
    the number of open rpc connections

### getCallQueueLen

    public int getCallQueueLen()

  The number of rpc calls in the queue.

  Returns:
    The number of rpc calls in the queue.

Copyright © 2009 The Apache Software Foundation