org.apache.hadoop.hbase.ipc
Class HBaseServer

java.lang.Object
  extended by org.apache.hadoop.hbase.ipc.HBaseServer
Direct Known Subclasses:
HBaseRPC.Server

public abstract class HBaseServer
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.

Copied local so can fix HBASE-900.

See Also:
HBaseClient

Field Summary
protected  String bindAddress
           
protected  BlockingQueue<org.apache.hadoop.hbase.ipc.HBaseServer.Call> callQueue
           
protected  org.apache.hadoop.conf.Configuration conf
           
protected  List<org.apache.hadoop.hbase.ipc.HBaseServer.Connection> connectionList
           
protected static ThreadLocal<org.apache.hadoop.hbase.ipc.HBaseServer.Call> CurCall
          This is set to Call object before Handler invokes an RPC and reset after the call returns.
static byte CURRENT_VERSION
           
protected  HBaseRPCErrorHandler errorHandler
           
static ByteBuffer HEADER
          The first four bytes of Hadoop RPC connections
static org.apache.commons.logging.Log LOG
           
protected  int maxIdleTime
           
protected  int numConnections
           
protected  Class<? extends org.apache.hadoop.io.Writable> paramClass
           
protected  int port
           
protected  BlockingQueue<org.apache.hadoop.hbase.ipc.HBaseServer.Call> priorityCallQueue
           
protected  org.apache.hadoop.hbase.ipc.HBaseServer.Responder responder
           
protected  HBaseRpcMetrics rpcMetrics
           
protected  boolean running
           
protected static ThreadLocal<HBaseServer> SERVER
           
protected  int socketSendBufferSize
           
protected  boolean tcpKeepAlive
           
protected  boolean tcpNoDelay
           
protected  int thresholdIdleConnections
           
 
Constructor Summary
protected HBaseServer(String bindAddress, int port, Class<? extends org.apache.hadoop.io.Writable> paramClass, int handlerCount, int priorityHandlerCount, org.apache.hadoop.conf.Configuration conf, String serverName, int highPriorityLevel)
           
 
Method Summary
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  org.apache.hadoop.io.Writable call(org.apache.hadoop.io.Writable param, long receiveTime)
          Called for each call.
protected static int channelRead(ReadableByteChannel channel, ByteBuffer buffer)
          This is a wrapper around ReadableByteChannel.read(ByteBuffer).
protected static int channelWrite(WritableByteChannel channel, ByteBuffer buffer)
          This is a wrapper around WritableByteChannel.write(ByteBuffer).
protected  void closeConnection(org.apache.hadoop.hbase.ipc.HBaseServer.Connection connection)
           
static HBaseServer 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
protected  int getQosLevel(org.apache.hadoop.io.Writable param)
           
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.
 HBaseRpcMetrics getRpcMetrics()
          Returns the metrics instance for reporting RPC call statistics
 void join()
          Wait for the server to be stopped.
 void openServer()
          Open a previously started server.
 void setErrorHandler(HBaseRPCErrorHandler handler)
          Set the handler for calling out of RPC for error conditions.
 void setQosFunction(com.google.common.base.Function<org.apache.hadoop.io.Writable,Integer> newFunc)
           
 void setSocketSendBufSize(int size)
          Sets the socket buffer size used for responding to RPCs.
 void start()
          Starts the service.
 void startThreads()
          Starts the service threads but does not allow requests to be responded yet.
 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

SERVER

protected static final ThreadLocal<HBaseServer> SERVER

CurCall

protected static final ThreadLocal<org.apache.hadoop.hbase.ipc.HBaseServer.Call> CurCall
This is set to Call object before Handler invokes an RPC and reset after the call returns.


bindAddress

protected String bindAddress

port

protected int port

paramClass

protected Class<? extends org.apache.hadoop.io.Writable> paramClass

maxIdleTime

protected int maxIdleTime

thresholdIdleConnections

protected int thresholdIdleConnections

rpcMetrics

protected HBaseRpcMetrics rpcMetrics

conf

protected org.apache.hadoop.conf.Configuration conf

socketSendBufferSize

protected int socketSendBufferSize

tcpNoDelay

protected final boolean tcpNoDelay

tcpKeepAlive

protected final boolean tcpKeepAlive

running

protected volatile boolean running

callQueue

protected BlockingQueue<org.apache.hadoop.hbase.ipc.HBaseServer.Call> callQueue

priorityCallQueue

protected BlockingQueue<org.apache.hadoop.hbase.ipc.HBaseServer.Call> priorityCallQueue

connectionList

protected final List<org.apache.hadoop.hbase.ipc.HBaseServer.Connection> connectionList

responder

protected org.apache.hadoop.hbase.ipc.HBaseServer.Responder responder

numConnections

protected int numConnections

errorHandler

protected HBaseRPCErrorHandler errorHandler
Constructor Detail

HBaseServer

protected HBaseServer(String bindAddress,
                      int port,
                      Class<? extends org.apache.hadoop.io.Writable> paramClass,
                      int handlerCount,
                      int priorityHandlerCount,
                      org.apache.hadoop.conf.Configuration conf,
                      String serverName,
                      int highPriorityLevel)
               throws IOException
Throws:
IOException
Method Detail

get

public static HBaseServer 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.

Returns:
HBaseServer

getRemoteIp

public static InetAddress getRemoteIp()
Returns the remote side ip address when invoked inside an RPC Returns null incase of an error.

Returns:
InetAddress

getRemoteAddress

public static String getRemoteAddress()
Returns remote address as a string when invoked inside an RPC. Returns null in case of an error.

Returns:
String

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

setQosFunction

public void setQosFunction(com.google.common.base.Function<org.apache.hadoop.io.Writable,Integer> newFunc)

getQosLevel

protected int getQosLevel(org.apache.hadoop.io.Writable param)

closeConnection

protected void closeConnection(org.apache.hadoop.hbase.ipc.HBaseServer.Connection connection)

setSocketSendBufSize

public void setSocketSendBufSize(int size)
Sets the socket buffer size used for responding to RPCs.

Parameters:
size - send size

start

public void start()
Starts the service. Must be called before any calls will be handled.


openServer

public void openServer()
Open a previously started server.


startThreads

public void startThreads()
Starts the service threads but does not allow requests to be responded yet. Client will get ServerNotRunningException instead.


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 - e

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

public abstract org.apache.hadoop.io.Writable call(org.apache.hadoop.io.Writable param,
                                                   long receiveTime)
                                            throws IOException
Called for each call.

Parameters:
param - writable parameter
receiveTime - time
Returns:
Writable
Throws:
IOException - e

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.

setErrorHandler

public void setErrorHandler(HBaseRPCErrorHandler handler)
Set the handler for calling out of RPC for error conditions.

Parameters:
handler - the handler implementation

getRpcMetrics

public HBaseRpcMetrics getRpcMetrics()
Returns the metrics instance for reporting RPC call statistics


channelWrite

protected static int channelWrite(WritableByteChannel channel,
                                  ByteBuffer buffer)
                           throws IOException
This is a wrapper around WritableByteChannel.write(ByteBuffer). If the amount of data is large, it writes to channel in smaller chunks. This is to avoid jdk from creating many direct buffers as the size of buffer increases. This also minimizes extra copies in NIO layer as a result of multiple write operations required to write a large buffer.

Parameters:
channel - writable byte channel to write to
buffer - buffer to write
Returns:
number of bytes written
Throws:
IOException - e
See Also:
WritableByteChannel.write(ByteBuffer)

channelRead

protected static int channelRead(ReadableByteChannel channel,
                                 ByteBuffer buffer)
                          throws IOException
This is a wrapper around ReadableByteChannel.read(ByteBuffer). If the amount of data is large, it writes to channel in smaller chunks. This is to avoid jdk from creating many direct buffers as the size of ByteBuffer increases. There should not be any performance degredation.

Parameters:
channel - writable byte channel to write on
buffer - buffer to write
Returns:
number of bytes written
Throws:
IOException - e
See Also:
ReadableByteChannel.read(ByteBuffer)


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.