org.apache.hadoop.hbase.ipc
Class HBaseServer

java.lang.Object
  extended by org.apache.hadoop.hbase.ipc.HBaseServer
All Implemented Interfaces:
RpcServer

@InterfaceAudience.Private
public abstract class HBaseServer
extends Object
implements RpcServer

A client for an IPC service. IPC calls take a single Protobuf message as a parameter, and return a single Protobuf message 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

Nested Class Summary
protected  class HBaseServer.Call
          A call queued for handling.
static class HBaseServer.CallQueueTooBigException
           
 class HBaseServer.Connection
          Reads calls from a connection and queues them for handling.
protected  class HBaseServer.Responder
           
 
Field Summary
protected  org.apache.hadoop.security.authorize.ServiceAuthorizationManager authManager
           
protected  String bindAddress
           
protected  BlockingQueue<HBaseServer.Call> callQueue
           
protected  org.cliffc.high_scale_lib.Counter callQueueSize
           
protected  org.apache.hadoop.conf.Configuration conf
           
protected  List<HBaseServer.Connection> connectionList
           
protected static ThreadLocal<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
           
protected  int highPriorityLevel
           
protected  boolean isSecurityEnabled
           
static org.apache.commons.logging.Log LOG
           
protected  int maxIdleTime
           
protected  MetricsHBaseServer metrics
           
protected  int numConnections
           
protected  int port
           
protected  BlockingQueue<HBaseServer.Call> priorityCallQueue
           
protected  long purgeTimeout
           
protected  BlockingQueue<HBaseServer.Call> replicationQueue
          replication related queue;
protected  HBaseServer.Responder responder
           
protected  boolean running
           
protected  org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier> secretManager
           
protected static ThreadLocal<RpcServer> SERVER
           
protected  int socketSendBufferSize
           
protected  boolean tcpKeepAlive
           
protected  boolean tcpNoDelay
           
protected  int thresholdIdleConnections
           
 
Constructor Summary
protected HBaseServer(String bindAddress, int port, int handlerCount, int priorityHandlerCount, org.apache.hadoop.conf.Configuration conf, String serverName, int highPriorityLevel)
           
 
Method Summary
 void authorize(org.apache.hadoop.security.UserGroupInformation user, RPCProtos.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.
protected  int channelRead(ReadableByteChannel channel, ByteBuffer buffer)
          This is a wrapper around ReadableByteChannel.read(java.nio.ByteBuffer).
protected  int channelWrite(WritableByteChannel channel, ByteBuffer buffer)
          This is a wrapper around WritableByteChannel.write(java.nio.ByteBuffer).
protected  void closeConnection(HBaseServer.Connection connection)
           
static RpcServer get()
          Returns the server instance called under or null.
protected  HBaseServer.Connection getConnection(SocketChannel channel, long time)
          Subclasses of HBaseServer can override this to provide their own Connection implementations.
static RpcCallContext getCurrentCall()
          Needed for delayed calls.
 InetSocketAddress getListenerAddress()
          Return the socket (ip+port) on which the RPC server is listening to.
 MetricsHBaseServer getMetrics()
          Returns the metrics instance for reporting RPC call statistics
protected  int getQosLevel(Pair<RPCProtos.RequestHeader,com.google.protobuf.Message> headerAndParam)
           
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.
 org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> getSecretManager()
           
 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<Pair<RPCProtos.RequestHeader,com.google.protobuf.Message>,Integer> newFunc)
          Gets the QOS level for this call.
 void setSecretManager(org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> secretManager)
           
 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
 
Methods inherited from interface org.apache.hadoop.hbase.ipc.RpcServer
call
 

Field Detail

LOG

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

isSecurityEnabled

protected boolean isSecurityEnabled

CURRENT_VERSION

public static final byte CURRENT_VERSION
See Also:
Constant Field Values

secretManager

protected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier> secretManager

authManager

protected org.apache.hadoop.security.authorize.ServiceAuthorizationManager authManager

SERVER

protected static final ThreadLocal<RpcServer> SERVER

CurCall

protected static final ThreadLocal<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

maxIdleTime

protected int maxIdleTime

thresholdIdleConnections

protected int thresholdIdleConnections

metrics

protected MetricsHBaseServer metrics

conf

protected org.apache.hadoop.conf.Configuration conf

socketSendBufferSize

protected int socketSendBufferSize

tcpNoDelay

protected final boolean tcpNoDelay

tcpKeepAlive

protected final boolean tcpKeepAlive

purgeTimeout

protected final long purgeTimeout

running

protected volatile boolean running

callQueue

protected BlockingQueue<HBaseServer.Call> callQueue

callQueueSize

protected final org.cliffc.high_scale_lib.Counter callQueueSize

priorityCallQueue

protected BlockingQueue<HBaseServer.Call> priorityCallQueue

highPriorityLevel

protected int highPriorityLevel

connectionList

protected final List<HBaseServer.Connection> connectionList

responder

protected HBaseServer.Responder responder

numConnections

protected int numConnections

replicationQueue

protected BlockingQueue<HBaseServer.Call> replicationQueue
replication related queue;


errorHandler

protected HBaseRPCErrorHandler errorHandler
Constructor Detail

HBaseServer

protected HBaseServer(String bindAddress,
                      int port,
                      int handlerCount,
                      int priorityHandlerCount,
                      org.apache.hadoop.conf.Configuration conf,
                      String serverName,
                      int highPriorityLevel)
               throws IOException
Throws:
IOException
Method Detail

get

public static RpcServer get()
Returns the server instance called under or null. May be called under #call(Class, RpcRequestBody, long, MonitoredRPCHandler) implementations, and under protobuf methods of parameters 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<Pair<RPCProtos.RequestHeader,com.google.protobuf.Message>,Integer> newFunc)
Gets the QOS level for this call. If it is higher than the highPriorityLevel and there are priorityHandlers available it will be processed in it's own thread set.

Specified by:
setQosFunction in interface RpcServer
Parameters:
newFunc -

getQosLevel

protected int getQosLevel(Pair<RPCProtos.RequestHeader,com.google.protobuf.Message> headerAndParam)

getConnection

protected HBaseServer.Connection getConnection(SocketChannel channel,
                                               long time)
Subclasses of HBaseServer can override this to provide their own Connection implementations.


closeConnection

protected void closeConnection(HBaseServer.Connection connection)

setSocketSendBufSize

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

Specified by:
setSocketSendBufSize in interface RpcServer
Parameters:
size - send size

start

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

Specified by:
start in interface RpcServer

openServer

public void openServer()
Open a previously started server.

Specified by:
openServer in interface RpcServer

startThreads

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

Specified by:
startThreads in interface RpcServer

getSecretManager

public org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> getSecretManager()

setSecretManager

public void setSecretManager(org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> secretManager)

stop

public void stop()
Stops the service. No new calls will be handled after this is called.

Specified by:
stop in interface RpcServer

join

public void join()
          throws InterruptedException
Wait for the server to be stopped. Does not wait for all subthreads to finish. See stop().

Specified by:
join in interface RpcServer
Throws:
InterruptedException - e

getListenerAddress

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

Specified by:
getListenerAddress in interface RpcServer
Returns:
the socket (ip+port) on which the RPC server is listening to.

setErrorHandler

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

Specified by:
setErrorHandler in interface RpcServer
Parameters:
handler - the handler implementation

getMetrics

public MetricsHBaseServer getMetrics()
Returns the metrics instance for reporting RPC call statistics

Specified by:
getMetrics in interface RpcServer

authorize

public void authorize(org.apache.hadoop.security.UserGroupInformation user,
                      RPCProtos.ConnectionHeader connection,
                      InetAddress addr)
               throws org.apache.hadoop.security.authorize.AuthorizationException
Authorize the incoming client connection.

Parameters:
user - client user
connection - incoming connection
addr - InetAddress of incoming connection
Throws:
org.apache.hadoop.security.authorize.AuthorizationException - when the client isn't authorized to talk the protocol

channelWrite

protected int channelWrite(WritableByteChannel channel,
                           ByteBuffer buffer)
                    throws IOException
This is a wrapper around WritableByteChannel.write(java.nio.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(java.nio.ByteBuffer)

channelRead

protected int channelRead(ReadableByteChannel channel,
                          ByteBuffer buffer)
                   throws IOException
This is a wrapper around ReadableByteChannel.read(java.nio.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(java.nio.ByteBuffer)

getCurrentCall

public static RpcCallContext getCurrentCall()
Needed for delayed calls. We need to be able to store the current call so that we can complete it later.

Returns:
Call the server is currently handling.


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