Class TServerUtils


  • public class TServerUtils
    extends Object
    Factory methods for creating Thrift server objects
    • Constructor Detail

      • TServerUtils

        public TServerUtils()
    • Method Detail

      • getHostAndPorts

        public static HostAndPort[] getHostAndPorts​(String hostname,
                                                    int[] ports)
        Parameters:
        hostname - name of the host
        ports - array of ports
        Returns:
        array of HostAndPort objects
      • startServer

        public static ServerAddress startServer​(org.apache.hadoop.metrics2.MetricsSystem metricsSystem,
                                                ServerContext 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 configuration
        portHintProperty - the port to attempt to open, can be zero, meaning "any available port"
        processor - the service to be started
        serverName - the name of the class that is providing the service
        threadName - name this service's thread for better debugging
        portSearchProperty - A boolean Property to control if port-search should be used, or null to disable
        minThreadProperty - A Property to control the minimum number of threads in the pool
        timeBetweenThreadChecksProperty - A Property to control the amount of time between checks to resize the thread pool
        maxMessageSizeProperty - 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
      • createThreadedSelectorServer

        public static ServerAddress createThreadedSelectorServer​(HostAndPort address,
                                                                 org.apache.thrift.TProcessor processor,
                                                                 org.apache.thrift.protocol.TProtocolFactory protocolFactory,
                                                                 String serverName,
                                                                 int numThreads,
                                                                 int numSTThreads,
                                                                 long timeBetweenThreadChecks,
                                                                 long maxMessageSize)
                                                          throws org.apache.thrift.transport.TTransportException
        Create a non blocking server with multiple select threads and a custom thread pool that can dynamically resize itself.
        Throws:
        org.apache.thrift.transport.TTransportException
      • createNonBlockingServer

        public static ServerAddress createNonBlockingServer​(HostAndPort address,
                                                            org.apache.thrift.TProcessor processor,
                                                            org.apache.thrift.protocol.TProtocolFactory protocolFactory,
                                                            String serverName,
                                                            int numThreads,
                                                            int numSTThreads,
                                                            long timeBetweenThreadChecks,
                                                            long maxMessageSize)
                                                     throws org.apache.thrift.transport.TTransportException
        Create a NonBlockingServer with a single select threads and 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 a SimpleThreadPool which uses SimpleTimer to inspect the core pool size and number of active threads of the ThreadPoolExecutor 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 service
        executorThreads - The maximum number of threads for the executor
        simpleTimerThreads - The numbers of threads used to get the SimpleTimer instance
        timeBetweenThreadChecks - 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 TThreadPoolServer for normal unsecure operation. Useful for comparing performance against SSL or SASL transports.
        Parameters:
        address - Address to bind to
        processor - TProcessor for the server
        maxMessageSize - 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,
                                                                                         ExecutorService service)
        Create a TThreadPoolServer with the provided server transport, processor and transport factory.
        Parameters:
        transport - TServerTransport for the server
        processor - TProcessor for the server
        transportFactory - 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 to
        timeout - Socket timeout
        address - Address to bind the socket to
        params - 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 to
        processor - TProcessor for the server
        socketTimeout - Socket timeout
        sslParams - 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,
                                                               int numThreads,
                                                               int numSTThreads,
                                                               long timeBetweenThreadChecks)
                                                        throws org.apache.thrift.transport.TTransportException
        Throws:
        org.apache.thrift.transport.TTransportException
      • 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