Package org.apache.accumulo.server.rpc
Class TServerUtils
- java.lang.Object
-
- org.apache.accumulo.server.rpc.TServerUtils
-
public class TServerUtils extends Object
Factory methods for creating Thrift server objects
-
-
Field Summary
Fields Modifier and Type Field Description static ThreadLocal<String>
clientAddress
Static instance, passed toClientInfoProcessorFactory
, which will contain the client address of any incoming RPC.
-
Constructor Summary
Constructors Constructor Description TServerUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ServerAddress
createBlockingServer(HostAndPort address, org.apache.thrift.TProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, long maxMessageSize, String serverName, int numThreads, int numSimpleTimerThreads, long timeBetweenThreadChecks)
Creates a TTheadPoolServer for normal unsecure operation.static ServerAddress
createNonBlockingServer(HostAndPort address, org.apache.thrift.TProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize)
Create a NonBlockingServer with a custom thread pool that can dynamically resize itself.static ServerAddress
createSaslThreadPoolServer(HostAndPort address, org.apache.thrift.TProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, long socketTimeout, SaslServerConnectionParams params, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks)
static ThreadPoolExecutor
createSelfResizingThreadPool(String serverName, int executorThreads, int simpleTimerThreads, long timeBetweenThreadChecks)
Creates aSimpleThreadPool
which usesSimpleTimer
to inspect the core pool size and number of active threads of theThreadPoolExecutor
and increase or decrease the core pool size based on activity (excessive or lack thereof).static ServerAddress
createSslThreadPoolServer(HostAndPort address, org.apache.thrift.TProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, long socketTimeout, SslConnectionParams sslParams, String serverName, int numThreads, int numSimpleTimerThreads, long timeBetweenThreadChecks)
Create a Thrift SSL server.static org.apache.thrift.server.TThreadPoolServer
createTThreadPoolServer(org.apache.thrift.transport.TServerTransport transport, org.apache.thrift.TProcessor processor, org.apache.thrift.transport.TTransportFactory transportFactory, org.apache.thrift.protocol.TProtocolFactory protocolFactory)
Create aTThreadPoolServer
with the provided transport, processor and transport factory.static org.apache.thrift.server.TThreadPoolServer
createTThreadPoolServer(org.apache.thrift.transport.TServerTransport transport, org.apache.thrift.TProcessor processor, org.apache.thrift.transport.TTransportFactory transportFactory, org.apache.thrift.protocol.TProtocolFactory protocolFactory, ExecutorService service)
Create aTThreadPoolServer
with the provided server transport, processor and transport factory.static HostAndPort[]
getHostAndPorts(String hostname, int[] ports)
static org.apache.thrift.transport.TServerSocket
getSslServerSocket(int port, int timeout, InetAddress address, SslConnectionParams params)
Create the Thrift server socket for RPC running over SSL.static ServerAddress
startServer(AccumuloServerContext service, String hostname, Property portHintProperty, org.apache.thrift.TProcessor processor, String serverName, String threadName, Property portSearchProperty, Property minThreadProperty, Property timeBetweenThreadChecksProperty, Property maxMessageSizeProperty)
Start a server, at the given port, or higher, if that port is not available.static ServerAddress
startTServer(AccumuloConfiguration conf, ThriftServerType serverType, org.apache.thrift.TProcessor processor, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize, SslConnectionParams sslParams, SaslServerConnectionParams saslParams, long serverSocketTimeout, HostAndPort... addresses)
static ServerAddress
startTServer(ThriftServerType serverType, TimedProcessor processor, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize, SslConnectionParams sslParams, SaslServerConnectionParams saslParams, long serverSocketTimeout, HostAndPort... addresses)
static ServerAddress
startTServer(ThriftServerType serverType, TimedProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize, SslConnectionParams sslParams, SaslServerConnectionParams saslParams, long serverSocketTimeout, HostAndPort... addresses)
Start the appropriate Thrift server (SSL or non-blocking server) for the given parameters.static void
stopTServer(org.apache.thrift.server.TServer s)
Stop a Thrift TServer.
-
-
-
Field Detail
-
clientAddress
public static final ThreadLocal<String> clientAddress
Static instance, passed toClientInfoProcessorFactory
, which will contain the client address of any incoming RPC.
-
-
Method Detail
-
getHostAndPorts
public static HostAndPort[] getHostAndPorts(String hostname, int[] ports)
- Parameters:
hostname
- name of the hostports
- array of ports- Returns:
- array of HostAndPort objects
-
startServer
public static ServerAddress startServer(AccumuloServerContext service, String hostname, Property portHintProperty, org.apache.thrift.TProcessor processor, String serverName, String threadName, Property portSearchProperty, Property minThreadProperty, Property timeBetweenThreadChecksProperty, Property maxMessageSizeProperty) throws UnknownHostException
Start a server, at the given port, or higher, if that port is not available.- Parameters:
service
- RPC configurationportHintProperty
- the port to attempt to open, can be zero, meaning "any available port"processor
- the service to be startedserverName
- the name of the class that is providing the servicethreadName
- name this service's thread for better debuggingportSearchProperty
- A boolean Property to control if port-search should be used, or null to disableminThreadProperty
- A Property to control the minimum number of threads in the pooltimeBetweenThreadChecksProperty
- A Property to control the amount of time between checks to resize the thread poolmaxMessageSizeProperty
- A Property to control the maximum Thrift message size accepted- Returns:
- the server object created, and the port actually used
- Throws:
UnknownHostException
- when we don't know our own address
-
createNonBlockingServer
public static ServerAddress createNonBlockingServer(HostAndPort address, org.apache.thrift.TProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize) throws org.apache.thrift.transport.TTransportException
Create a NonBlockingServer with a custom thread pool that can dynamically resize itself.- Throws:
org.apache.thrift.transport.TTransportException
-
createSelfResizingThreadPool
public static ThreadPoolExecutor createSelfResizingThreadPool(String serverName, int executorThreads, int simpleTimerThreads, long timeBetweenThreadChecks)
Creates aSimpleThreadPool
which usesSimpleTimer
to inspect the core pool size and number of active threads of theThreadPoolExecutor
and increase or decrease the core pool size based on activity (excessive or lack thereof).- Parameters:
serverName
- A name to describe the thrift server this executor will serviceexecutorThreads
- The maximum number of threads for the executorsimpleTimerThreads
- The numbers of threads used to get theSimpleTimer
instancetimeBetweenThreadChecks
- The amount of time, in millis, between attempts to resize the executor thread pool- Returns:
- A
ThreadPoolExecutor
which will resize itself automatically
-
createBlockingServer
public static ServerAddress createBlockingServer(HostAndPort address, org.apache.thrift.TProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, long maxMessageSize, String serverName, int numThreads, int numSimpleTimerThreads, long timeBetweenThreadChecks) throws org.apache.thrift.transport.TTransportException
Creates a TTheadPoolServer for normal unsecure operation. Useful for comparing performance against SSL or SASL transports.- Parameters:
address
- Address to bind toprocessor
- TProcessor for the servermaxMessageSize
- Maximum size of a Thrift message allowed- Returns:
- A configured TThreadPoolServer and its bound address information
- Throws:
org.apache.thrift.transport.TTransportException
-
createTThreadPoolServer
public static org.apache.thrift.server.TThreadPoolServer createTThreadPoolServer(org.apache.thrift.transport.TServerTransport transport, org.apache.thrift.TProcessor processor, org.apache.thrift.transport.TTransportFactory transportFactory, org.apache.thrift.protocol.TProtocolFactory protocolFactory)
Create aTThreadPoolServer
with the provided transport, processor and transport factory.- Parameters:
transport
- Server transportprocessor
- Processor implementationtransportFactory
- Transport factory- Returns:
- A configured
TThreadPoolServer
-
createTThreadPoolServer
public static org.apache.thrift.server.TThreadPoolServer createTThreadPoolServer(org.apache.thrift.transport.TServerTransport transport, org.apache.thrift.TProcessor processor, org.apache.thrift.transport.TTransportFactory transportFactory, org.apache.thrift.protocol.TProtocolFactory protocolFactory, ExecutorService service)
Create aTThreadPoolServer
with the provided server transport, processor and transport factory.- Parameters:
transport
- TServerTransport for the serverprocessor
- TProcessor for the servertransportFactory
- TTransportFactory for the server
-
getSslServerSocket
public static org.apache.thrift.transport.TServerSocket getSslServerSocket(int port, int timeout, InetAddress address, SslConnectionParams params) throws org.apache.thrift.transport.TTransportException
Create the Thrift server socket for RPC running over SSL.- Parameters:
port
- Port of the server socket to bind totimeout
- Socket timeoutaddress
- Address to bind the socket toparams
- SSL parameters- Returns:
- A configured TServerSocket configured to use SSL
- Throws:
org.apache.thrift.transport.TTransportException
-
createSslThreadPoolServer
public static ServerAddress createSslThreadPoolServer(HostAndPort address, org.apache.thrift.TProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, long socketTimeout, SslConnectionParams sslParams, String serverName, int numThreads, int numSimpleTimerThreads, long timeBetweenThreadChecks) throws org.apache.thrift.transport.TTransportException
Create a Thrift SSL server.- Parameters:
address
- host and port to bind toprocessor
- TProcessor for the serversocketTimeout
- Socket timeoutsslParams
- SSL parameters- Returns:
- A ServerAddress with the bound-socket information and the Thrift server
- Throws:
org.apache.thrift.transport.TTransportException
-
createSaslThreadPoolServer
public static ServerAddress createSaslThreadPoolServer(HostAndPort address, org.apache.thrift.TProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, long socketTimeout, SaslServerConnectionParams params, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks) throws org.apache.thrift.transport.TTransportException
- Throws:
org.apache.thrift.transport.TTransportException
-
startTServer
public static ServerAddress startTServer(AccumuloConfiguration conf, ThriftServerType serverType, org.apache.thrift.TProcessor processor, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize, SslConnectionParams sslParams, SaslServerConnectionParams saslParams, long serverSocketTimeout, HostAndPort... addresses) throws org.apache.thrift.transport.TTransportException
- Throws:
org.apache.thrift.transport.TTransportException
-
startTServer
public static ServerAddress startTServer(ThriftServerType serverType, TimedProcessor processor, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize, SslConnectionParams sslParams, SaslServerConnectionParams saslParams, long serverSocketTimeout, HostAndPort... addresses) throws org.apache.thrift.transport.TTransportException
- Throws:
org.apache.thrift.transport.TTransportException
- See Also:
startTServer(ThriftServerType, TimedProcessor, TProtocolFactory, String, String, int, int, long, long, SslConnectionParams, SaslServerConnectionParams, long, HostAndPort...)
-
startTServer
public static ServerAddress startTServer(ThriftServerType serverType, TimedProcessor processor, org.apache.thrift.protocol.TProtocolFactory protocolFactory, String serverName, String threadName, int numThreads, int numSTThreads, long timeBetweenThreadChecks, long maxMessageSize, SslConnectionParams sslParams, SaslServerConnectionParams saslParams, long serverSocketTimeout, HostAndPort... addresses) throws org.apache.thrift.transport.TTransportException
Start the appropriate Thrift server (SSL or non-blocking server) for the given parameters. Non-null SSL parameters will cause an SSL server to be started.- Returns:
- A ServerAddress encapsulating the Thrift server created and the host/port which it is bound to.
- Throws:
org.apache.thrift.transport.TTransportException
-
stopTServer
public static void stopTServer(org.apache.thrift.server.TServer s)
Stop a Thrift TServer. Existing connections will keep our thread running; use reflection to forcibly shut down the threadpool.- Parameters:
s
- The TServer to stop
-
-