@InterfaceAudience.LimitedPrivate(value={"Coprocesssor","Phoenix"}) @InterfaceStability.Evolving public class RpcServer extends Object implements RpcServerInterface
Scheduler can be variously implemented but default simple scheduler has handlers to which it has given the queues into which calls (i.e. CallRunner instances) are inserted. Handlers run taking from the queue. They run the CallRunner#run method on each item gotten from queue and keep taking while the server is up. CallRunner#run executes the call. When done, asks the included Call to put itself on new queue for Responder to pull from and return result to client.
RpcClientImpl
Modifier and Type | Class and Description |
---|---|
static class |
RpcServer.BlockingServiceAndInterface
Datastructure for passing a
BlockingService and its associated class of
protobuf service interface. |
class |
RpcServer.Call
Datastructure that holds all necessary to a method invocation and then afterward, carries
the result.
|
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 AuthenticationTokenSecretManager |
authTokenSecretMgr |
protected InetSocketAddress |
bindAddress |
protected Counter |
callQueueSize
This is a running count of the size of all outstanding calls by size.
|
protected org.apache.hadoop.conf.Configuration |
conf |
protected List<RpcServer.Connection> |
connectionList |
protected static ThreadLocal<RpcServer.Call> |
CurCall
This is set to Call object before Handler invokes an RPC and ybdie
after the call returns.
|
static byte |
CURRENT_VERSION |
protected HBaseRPCErrorHandler |
errorHandler |
static org.apache.commons.logging.Log |
LOG |
protected int |
maxIdleTime |
protected MetricsHBaseServer |
metrics |
protected int |
numConnections |
protected int |
port |
protected long |
purgeTimeout |
protected RpcServer.Responder |
responder |
protected org.apache.hadoop.security.token.SecretManager<org.apache.hadoop.security.token.TokenIdentifier> |
secretManager |
protected int |
socketSendBufferSize |
protected boolean |
tcpKeepAlive |
protected boolean |
tcpNoDelay |
protected int |
thresholdIdleConnections |
Constructor and Description |
---|
RpcServer(Server server,
String name,
List<RpcServer.BlockingServiceAndInterface> services,
InetSocketAddress bindAddress,
org.apache.hadoop.conf.Configuration conf,
RpcScheduler scheduler)
Constructs a server listening on the named port and address.
|
Modifier and Type | Method and Description |
---|---|
void |
addCallSize(long diff)
Add/subtract from the current size of all outstanding calls.
|
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 long |
channelWrite(GatheringByteChannel channel,
org.apache.hadoop.hbase.ipc.BufferChain bufferChain)
This is a wrapper around
WritableByteChannel.write(java.nio.ByteBuffer) . |
protected void |
closeConnection(RpcServer.Connection connection) |
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.
|
HBaseRPCErrorHandler |
getErrorHandler() |
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
|
static InetAddress |
getRemoteAddress() |
static InetAddress |
getRemoteIp()
Returns the remote side ip address when invoked inside an RPC
Returns null incase of an error.
|
static User |
getRequestUser()
Returns the user credentials associated with the current RPC request or
null if no credentials were provided. |
static String |
getRequestUserName()
Returns the username for any user associated with the current RPC
request or
null if no user is set. |
RpcScheduler |
getScheduler() |
org.apache.hadoop.security.token.SecretManager<? extends org.apache.hadoop.security.token.TokenIdentifier> |
getSecretManager() |
static boolean |
isInRpcCallContext() |
boolean |
isStarted() |
void |
join()
Wait for the server to be stopped.
|
void |
refreshAuthManager(org.apache.hadoop.security.authorize.PolicyProvider pp)
Refresh authentication manager policy.
|
void |
setErrorHandler(HBaseRPCErrorHandler handler)
Set the handler for calling out of RPC for error conditions.
|
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 |
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<RpcServer.Call> CurCall
protected final InetSocketAddress bindAddress
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 final Counter callQueueSize
protected final List<RpcServer.Connection> connectionList
protected RpcServer.Responder responder
protected AuthenticationTokenSecretManager authTokenSecretMgr
protected int numConnections
protected HBaseRPCErrorHandler errorHandler
public RpcServer(Server server, String name, List<RpcServer.BlockingServiceAndInterface> services, InetSocketAddress bindAddress, org.apache.hadoop.conf.Configuration conf, RpcScheduler scheduler) throws IOException
server
- 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.bindAddress
- Where to listenconf
- scheduler
- IOException
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 boolean isStarted()
isStarted
in interface RpcServerInterface
public void start()
start
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 HBaseRPCErrorHandler getErrorHandler()
getErrorHandler
in interface RpcServerInterface
public MetricsHBaseServer getMetrics()
getMetrics
in interface RpcServerInterface
public void addCallSize(long diff)
RpcServerInterface
addCallSize
in interface RpcServerInterface
diff
- Change (plus or minus)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 long channelWrite(GatheringByteChannel channel, org.apache.hadoop.hbase.ipc.BufferChain bufferChain) 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 tobufferChain
- Chain of buffers 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 boolean isInRpcCallContext()
public static User getRequestUser()
null
if no credentials were provided.public static String getRequestUserName()
null
if no user is set.public static InetAddress getRemoteAddress()
public static InetAddress getRemoteIp()
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 bindpublic RpcScheduler getScheduler()
getScheduler
in interface RpcServerInterface
Copyright © 2007-2016 The Apache Software Foundation. All Rights Reserved.