Class TThreadedSelectorServer


  • public class TThreadedSelectorServer
    extends AbstractNonblockingServer
    A Half-Sync/Half-Async server with a separate pool of threads to handle non-blocking I/O. Accepts are handled on a single thread, and a configurable number of nonblocking selector threads manage reading and writing of client connections. A synchronous worker thread pool handles processing of requests. Performs better than TNonblockingServer/THsHaServer in multi-core environments when the the bottleneck is CPU on the single selector thread handling I/O. In addition, because the accept handling is decoupled from reads/writes and invocation, the server has better ability to handle back- pressure from new connections (e.g. stop accepting when busy). Like TNonblockingServer, it relies on the use of TFramedTransport.
    • Constructor Detail

      • TThreadedSelectorServer

        public TThreadedSelectorServer​(TThreadedSelectorServer.Args args)
        Create the server with the specified Args configuration
    • Method Detail

      • startThreads

        protected boolean startThreads()
        Start the accept and selector threads running to deal with clients.
        Specified by:
        startThreads in class AbstractNonblockingServer
        Returns:
        true if everything went ok, false if we couldn't start for some reason.
      • joinThreads

        protected void joinThreads()
                            throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • stop

        public void stop()
        Stop serving and shut everything down.
        Overrides:
        stop in class TServer
      • gracefullyShutdownInvokerPool

        protected void gracefullyShutdownInvokerPool()
      • requestInvoke

        protected boolean requestInvoke​(AbstractNonblockingServer.FrameBuffer frameBuffer)
        We override the standard invoke method here to queue the invocation for invoker service instead of immediately invoking. If there is no thread pool, handle the invocation inline on this thread
        Specified by:
        requestInvoke in class AbstractNonblockingServer
        Returns:
        true if invocation was successfully requested, which is not a guarantee that invocation has completed. False if the request failed.
      • createDefaultExecutor

        protected static java.util.concurrent.ExecutorService createDefaultExecutor​(TThreadedSelectorServer.Args options)
        Helper to create the invoker if one is not specified