Class ServerGroup

    • Field Detail

      • log

        private static final org.slf4j.Logger log
      • DEFAULT_INCOMING_ACCEPTOR_THREADS

        public static final int DEFAULT_INCOMING_ACCEPTOR_THREADS
        The default number of threads to accept incoming requests from clients. (Requests are serviced by worker threads, not acceptor threads.)
        See Also:
        Constant Field Values
      • DEFAULT_INCOMING_WORKER_THREADS

        public static final int DEFAULT_INCOMING_WORKER_THREADS
        The default number of threads to service incoming requests from clients.
        See Also:
        Constant Field Values
      • DEFAULT_OUTGOING_WORKER_THREADS

        public static final int DEFAULT_OUTGOING_WORKER_THREADS
        The default number of threads to service outgoing requests to servers.
        See Also:
        Constant Field Values
      • name

        private final String name
        A name for this ServerGroup to use in naming threads.
      • serverGroupId

        private final int serverGroupId
        The ID of this server group. Forms part of the name of each thread created for this server group. Useful for differentiating threads when multiple proxy instances are running.
      • incomingAcceptorThreads

        private final int incomingAcceptorThreads
      • incomingWorkerThreads

        private final int incomingWorkerThreads
      • outgoingWorkerThreads

        private final int outgoingWorkerThreads
      • TRANSPORT_PROTOCOL_SELECTOR_PROVIDERS

        private static final EnumMap<TransportProtocol,​SelectorProvider> TRANSPORT_PROTOCOL_SELECTOR_PROVIDERS
        A mapping of selector providers to transport protocols. Avoids special-casing each transport protocol during transport protocol initialization.
      • stopped

        private final AtomicBoolean stopped
        True when this ServerGroup is stopped.
      • THREAD_POOL_INIT_LOCK

        private final Object THREAD_POOL_INIT_LOCK
        Lock for initializing any transport protocols.
    • Constructor Detail

      • ServerGroup

        public ServerGroup​(String name,
                           int incomingAcceptorThreads,
                           int incomingWorkerThreads,
                           int outgoingWorkerThreads)
        Creates a new ServerGroup instance for a proxy. Threads created for this ServerGroup will have the specified ServerGroup name in the Thread name. This constructor does not actually initialize any thread pools; instead, thread pools for specific transport protocols are lazily initialized as needed.
        Parameters:
        name - ServerGroup name to include in thread names
        incomingAcceptorThreads - number of acceptor threads per protocol
        incomingWorkerThreads - number of client-to-proxy worker threads per protocol
        outgoingWorkerThreads - number of proxy-to-server worker threads per protocol
    • Method Detail

      • getThreadPoolsForProtocol

        private ProxyThreadPools getThreadPoolsForProtocol​(TransportProtocol protocol)
        Retrieves the ProxyThreadPools for the specified transport protocol. Lazily initializes the thread pools for the transport protocol if they have not yet been initialized. If the protocol has already been initialized, this method returns immediately, without synchronization. If initialization is necessary, the initialization process creates the acceptor and worker threads necessary to service requests to/from the proxy.

        This method is thread-safe; no external locking is necessary.

        Parameters:
        protocol - transport protocol to retrieve thread pools for
        Returns:
        thread pools for the specified transport protocol
      • registerProxyServer

        public void registerProxyServer​(HttpProxyServer proxyServer)
        Registers the specified proxy server as a consumer of this server group. The server group will not be shut down until the proxy unregisters itself.
        Parameters:
        proxyServer - proxy server instance to register
      • unregisterProxyServer

        public void unregisterProxyServer​(HttpProxyServer proxyServer,
                                          boolean graceful)
        Unregisters the specified proxy server from this server group. If this was the last registered proxy server, the server group will be shut down.
        Parameters:
        proxyServer - proxy server instance to unregister
        graceful - when true, the server group shutdown (if necessary) will be graceful
      • shutdown

        private void shutdown​(boolean graceful)
        Shuts down all event loops owned by this server group.
        Parameters:
        graceful - when true, event loops will "gracefully" terminate, waiting for submitted tasks to finish
      • getClientToProxyAcceptorPoolForTransport

        public EventLoopGroup getClientToProxyAcceptorPoolForTransport​(TransportProtocol protocol)
        Retrieves the client-to-proxy acceptor thread pool for the specified protocol. Initializes the pool if it has not yet been initialized.

        This method is thread-safe; no external locking is necessary.

        Parameters:
        protocol - transport protocol to retrieve the thread pool for
        Returns:
        the client-to-proxy acceptor thread pool
      • getClientToProxyWorkerPoolForTransport

        public EventLoopGroup getClientToProxyWorkerPoolForTransport​(TransportProtocol protocol)
        Retrieves the client-to-proxy acceptor worker pool for the specified protocol. Initializes the pool if it has not yet been initialized.

        This method is thread-safe; no external locking is necessary.

        Parameters:
        protocol - transport protocol to retrieve the thread pool for
        Returns:
        the client-to-proxy worker thread pool
      • getProxyToServerWorkerPoolForTransport

        public EventLoopGroup getProxyToServerWorkerPoolForTransport​(TransportProtocol protocol)
        Retrieves the proxy-to-server worker thread pool for the specified protocol. Initializes the pool if it has not yet been initialized.

        This method is thread-safe; no external locking is necessary.

        Parameters:
        protocol - transport protocol to retrieve the thread pool for
        Returns:
        the proxy-to-server worker thread pool
      • isStopped

        public boolean isStopped()
        Returns:
        true if this ServerGroup has already been stopped