public class ServerGroup extends Object
registerProxyServer(HttpProxyServer)
, and when they shut down, must unregister with the
ServerGroup using unregisterProxyServer(HttpProxyServer, boolean)
.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_INCOMING_ACCEPTOR_THREADS
The default number of threads to accept incoming requests from clients.
|
static int |
DEFAULT_INCOMING_WORKER_THREADS
The default number of threads to service incoming requests from clients.
|
static int |
DEFAULT_OUTGOING_WORKER_THREADS
The default number of threads to service outgoing requests to servers.
|
private int |
incomingAcceptorThreads |
private int |
incomingWorkerThreads |
private static org.slf4j.Logger |
log |
private String |
name
A name for this ServerGroup to use in naming threads.
|
private int |
outgoingWorkerThreads |
private EnumMap<TransportProtocol,ProxyThreadPools> |
protocolThreadPools
A mapping of
TransportProtocol s to their initialized ProxyThreadPools . |
List<HttpProxyServer> |
registeredServers
List of all servers registered to use this ServerGroup.
|
private Object |
SERVER_REGISTRATION_LOCK
Lock controlling access to the
registerProxyServer(HttpProxyServer) and unregisterProxyServer(HttpProxyServer, boolean)
methods. |
private static AtomicInteger |
serverGroupCount
Global counter for the
serverGroupId . |
private int |
serverGroupId
The ID of this server group.
|
private AtomicBoolean |
stopped
True when this ServerGroup is stopped.
|
private Object |
THREAD_POOL_INIT_LOCK
Lock for initializing any transport protocols.
|
private static EnumMap<TransportProtocol,SelectorProvider> |
TRANSPORT_PROTOCOL_SELECTOR_PROVIDERS
A mapping of selector providers to transport protocols.
|
Constructor and Description |
---|
ServerGroup(String name,
int incomingAcceptorThreads,
int incomingWorkerThreads,
int outgoingWorkerThreads)
Creates a new ServerGroup instance for a proxy.
|
Modifier and Type | Method and Description |
---|---|
io.netty.channel.EventLoopGroup |
getClientToProxyAcceptorPoolForTransport(TransportProtocol protocol)
Retrieves the client-to-proxy acceptor thread pool for the specified protocol.
|
io.netty.channel.EventLoopGroup |
getClientToProxyWorkerPoolForTransport(TransportProtocol protocol)
Retrieves the client-to-proxy acceptor worker pool for the specified protocol.
|
io.netty.channel.EventLoopGroup |
getProxyToServerWorkerPoolForTransport(TransportProtocol protocol)
Retrieves the proxy-to-server worker thread pool for the specified protocol.
|
private ProxyThreadPools |
getThreadPoolsForProtocol(TransportProtocol protocol)
Retrieves the
ProxyThreadPools for the specified transport protocol. |
boolean |
isStopped() |
void |
registerProxyServer(HttpProxyServer proxyServer)
Registers the specified proxy server as a consumer of this server group.
|
private void |
shutdown(boolean graceful)
Shuts down all event loops owned by this server group.
|
void |
unregisterProxyServer(HttpProxyServer proxyServer,
boolean graceful)
Unregisters the specified proxy server from this server group.
|
private static final org.slf4j.Logger log
public static final int DEFAULT_INCOMING_ACCEPTOR_THREADS
public static final int DEFAULT_INCOMING_WORKER_THREADS
public static final int DEFAULT_OUTGOING_WORKER_THREADS
private static final AtomicInteger serverGroupCount
serverGroupId
.private final String name
private final int serverGroupId
private final int incomingAcceptorThreads
private final int incomingWorkerThreads
private final int outgoingWorkerThreads
public final List<HttpProxyServer> registeredServers
SERVER_REGISTRATION_LOCK
.private final EnumMap<TransportProtocol,ProxyThreadPools> protocolThreadPools
TransportProtocol
s to their initialized ProxyThreadPools
. Each transport uses a
different thread pool, since the initialization parameters are different.private static final EnumMap<TransportProtocol,SelectorProvider> TRANSPORT_PROTOCOL_SELECTOR_PROVIDERS
private final AtomicBoolean stopped
private final Object THREAD_POOL_INIT_LOCK
private final Object SERVER_REGISTRATION_LOCK
registerProxyServer(HttpProxyServer)
and unregisterProxyServer(HttpProxyServer, boolean)
methods.public ServerGroup(String name, int incomingAcceptorThreads, int incomingWorkerThreads, int outgoingWorkerThreads)
name
- ServerGroup name to include in thread namesincomingAcceptorThreads
- number of acceptor threads per protocolincomingWorkerThreads
- number of client-to-proxy worker threads per protocoloutgoingWorkerThreads
- number of proxy-to-server worker threads per protocolprivate ProxyThreadPools getThreadPoolsForProtocol(TransportProtocol protocol)
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.protocol
- transport protocol to retrieve thread pools forpublic void registerProxyServer(HttpProxyServer proxyServer)
proxyServer
- proxy server instance to registerpublic void unregisterProxyServer(HttpProxyServer proxyServer, boolean graceful)
proxyServer
- proxy server instance to unregistergraceful
- when true, the server group shutdown (if necessary) will be gracefulprivate void shutdown(boolean graceful)
graceful
- when true, event loops will "gracefully" terminate, waiting for submitted tasks to finishpublic io.netty.channel.EventLoopGroup getClientToProxyAcceptorPoolForTransport(TransportProtocol protocol)
protocol
- transport protocol to retrieve the thread pool forpublic io.netty.channel.EventLoopGroup getClientToProxyWorkerPoolForTransport(TransportProtocol protocol)
protocol
- transport protocol to retrieve the thread pool forpublic io.netty.channel.EventLoopGroup getProxyToServerWorkerPoolForTransport(TransportProtocol protocol)
protocol
- transport protocol to retrieve the thread pool forpublic boolean isStopped()
Copyright © 2009–2018 LittleShoot. All rights reserved.