@InterfaceAudience.Private public class RpcServer extends Object implements RpcServerInterface
Once was copied from Hadoop to local to fix HBASE-900 but deviated long ago.
RpcClient
Modifier and Type | Class and Description |
---|---|
static class |
RpcServer.BlockingServiceAndInterface
Datastructure for passing a
BlockingService and its associated class of
protobuf service interface. |
static class |
RpcServer.CallQueueTooBigException |
class |
RpcServer.Connection
Reads calls from a connection and queues them for handling.
|
protected class |
RpcServer.Responder |
Modifier and Type | Field and Description |
---|---|
protected org.apache.hadoop.security.authorize.ServiceAuthorizationManager |
authManager |
protected BlockingQueue<org.apache.hadoop.hbase.ipc.RpcServer.Call> |
callQueue |
protected org.cliffc.high_scale_lib.Counter |
callQueueSize |
protected org.apache.hadoop.conf.Configuration |
conf |
protected List<RpcServer.Connection> |
connectionList |
protected static ThreadLocal<org.apache.hadoop.hbase.ipc.RpcServer.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 InetSocketAddress |
isa |
static org.apache.commons.logging.Log |
LOG |
protected int |
maxIdleTime |
protected MetricsHBaseServer |
metrics |
protected int |
numConnections |
protected int |
port |
protected BlockingQueue<org.apache.hadoop.hbase.ipc.RpcServer.Call> |
priorityCallQueue |
protected long |
purgeTimeout |
protected BlockingQueue<org.apache.hadoop.hbase.ipc.RpcServer.Call> |
replicationQueue
replication related queue;
|
protected RpcServer.Responder |
responder |
protected boolean |
running |
protected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier> |
secretManager |
protected static ThreadLocal<RpcServerInterface> |
SERVER |
protected int |
socketSendBufferSize |
protected boolean |
tcpKeepAlive |
protected boolean |
tcpNoDelay |
protected int |
thresholdIdleConnections |
Constructor and Description |
---|
RpcServer(com.google.protobuf.BlockingService service,
InetSocketAddress isa,
org.apache.hadoop.conf.Configuration conf)
Minimal setup.
|
RpcServer(Server serverInstance,
String name,
List<RpcServer.BlockingServiceAndInterface> services,
InetSocketAddress isa,
int handlerCount,
int priorityHandlerCount,
org.apache.hadoop.conf.Configuration conf,
int highPriorityLevel)
Constructs a server listening on the named port and address.
|
Modifier and Type | Method and Description |
---|---|
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.
|
Pair<com.google.protobuf.Message,CellScanner> |
call(com.google.protobuf.BlockingService service,
com.google.protobuf.Descriptors.MethodDescriptor md,
com.google.protobuf.Message param,
CellScanner cellScanner,
long receiveTime,
MonitoredRPCHandler status)
This is a server side method, which is invoked over RPC.
|
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(RpcServer.Connection connection) |
static RpcServerInterface |
get()
May be called under
#call(Class, RpcRequestBody, long, MonitoredRPCHandler) implementations,
and under protobuf methods of parameters and return values. |
protected RpcServer.Connection |
getConnection(SocketChannel channel,
long time)
Subclasses of HBaseServer can override this to provide their own
Connection implementations.
|
static RpcCallContext |
getCurrentCall()
Needed for features such as 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 |
refreshAuthManager(org.apache.hadoop.security.authorize.PolicyProvider pp)
Refresh autentication manager policy.
|
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.
|
public static final org.apache.commons.logging.Log LOG
public static final byte CURRENT_VERSION
protected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier> secretManager
protected org.apache.hadoop.security.authorize.ServiceAuthorizationManager authManager
protected static final ThreadLocal<RpcServerInterface> SERVER
protected static final ThreadLocal<org.apache.hadoop.hbase.ipc.RpcServer.Call> CurCall
protected final InetSocketAddress isa
protected int port
protected int maxIdleTime
protected int thresholdIdleConnections
protected MetricsHBaseServer metrics
protected final org.apache.hadoop.conf.Configuration conf
protected int socketSendBufferSize
protected final boolean tcpNoDelay
protected final boolean tcpKeepAlive
protected final long purgeTimeout
protected volatile boolean running
protected BlockingQueue<org.apache.hadoop.hbase.ipc.RpcServer.Call> callQueue
protected final org.cliffc.high_scale_lib.Counter callQueueSize
protected BlockingQueue<org.apache.hadoop.hbase.ipc.RpcServer.Call> priorityCallQueue
protected int highPriorityLevel
protected final List<RpcServer.Connection> connectionList
protected RpcServer.Responder responder
protected int numConnections
protected BlockingQueue<org.apache.hadoop.hbase.ipc.RpcServer.Call> replicationQueue
protected HBaseRPCErrorHandler errorHandler
public RpcServer(com.google.protobuf.BlockingService service, InetSocketAddress isa, org.apache.hadoop.conf.Configuration conf) throws IOException
service
- isa
- conf
- IOException
public RpcServer(Server serverInstance, String name, List<RpcServer.BlockingServiceAndInterface> services, InetSocketAddress isa, int handlerCount, int priorityHandlerCount, org.apache.hadoop.conf.Configuration conf, int highPriorityLevel) throws IOException
serverInstance
- hosting instance of Server
. We will do authentications if an
instance else pass null for no authentication check.name
- Used keying this rpc servers' metrics and for naming the Listener thread.services
- A list of services.isa
- Where to listenhandlerCount
- the number of handler threads that will be used to process callspriorityHandlerCount
- How many threads for priority handling.conf
- highPriorityLevel
- IOException
public void setQosFunction(com.google.common.base.Function<Pair<RPCProtos.RequestHeader,com.google.protobuf.Message>,Integer> newFunc)
setQosFunction
in interface RpcServerInterface
newFunc
- protected int getQosLevel(Pair<RPCProtos.RequestHeader,com.google.protobuf.Message> headerAndParam)
protected RpcServer.Connection getConnection(SocketChannel channel, long time)
protected void closeConnection(RpcServer.Connection connection)
public void setSocketSendBufSize(int size)
setSocketSendBufSize
in interface RpcServerInterface
size
- send sizepublic void start()
start
in interface RpcServerInterface
public void openServer()
openServer
in interface RpcServerInterface
public void startThreads()
ServerNotRunningYetException
instead.startThreads
in interface RpcServerInterface
public void refreshAuthManager(org.apache.hadoop.security.authorize.PolicyProvider pp)
RpcServerInterface
refreshAuthManager
in interface RpcServerInterface
public org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> getSecretManager()
public void setSecretManager(org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> secretManager)
public Pair<com.google.protobuf.Message,CellScanner> call(com.google.protobuf.BlockingService service, com.google.protobuf.Descriptors.MethodDescriptor md, com.google.protobuf.Message param, CellScanner cellScanner, long receiveTime, MonitoredRPCHandler status) throws IOException
call
in interface RpcServerInterface
IOException
public void stop()
stop
in interface RpcServerInterface
public void join() throws InterruptedException
stop()
.join
in interface RpcServerInterface
InterruptedException
- epublic InetSocketAddress getListenerAddress()
getListenerAddress
in interface RpcServerInterface
public void setErrorHandler(HBaseRPCErrorHandler handler)
setErrorHandler
in interface RpcServerInterface
handler
- the handler implementationpublic MetricsHBaseServer getMetrics()
getMetrics
in interface RpcServerInterface
public void authorize(org.apache.hadoop.security.UserGroupInformation user, RPCProtos.ConnectionHeader connection, InetAddress addr) throws org.apache.hadoop.security.authorize.AuthorizationException
user
- client userconnection
- incoming connectionaddr
- InetAddress of incoming connectionorg.apache.hadoop.security.authorize.AuthorizationException
- when the client isn't authorized to talk the protocolprotected int channelWrite(WritableByteChannel channel, ByteBuffer buffer) throws IOException
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.channel
- writable byte channel to write tobuffer
- buffer to writeIOException
- eWritableByteChannel.write(java.nio.ByteBuffer)
protected int channelRead(ReadableByteChannel channel, ByteBuffer buffer) throws IOException
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.channel
- writable byte channel to write onbuffer
- buffer to writeIOException
- eReadableByteChannel.read(java.nio.ByteBuffer)
public static RpcCallContext getCurrentCall()
public static InetAddress getRemoteIp()
public static String getRemoteAddress()
public static RpcServerInterface get()
#call(Class, RpcRequestBody, long, MonitoredRPCHandler)
implementations,
and under protobuf methods of parameters and return values.
Permits applications to access the server context.public static void bind(ServerSocket socket, InetSocketAddress address, int backlog) throws IOException
socket
- the socket to bindaddress
- the address to bind tobacklog
- the number of connections allowed in the queueBindException
- if the address can't be boundUnknownHostException
- if the address isn't a valid host nameIOException
- other random errors from bindCopyright © 2013 The Apache Software Foundation. All rights reserved.