public class WebClientsManager extends java.lang.Object implements WebClientAllocator, WebClientRegistrar, SessionListener
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<java.lang.String,java.util.TimerTask> |
cleaners
Map of cleaners, for each UUID.
|
private java.util.Timer |
cleanerTimer
A timer to clean allocated configurations.
|
private static int |
CONNECTING_TIMEOUT_IN_MILLISECONDS
The time-out in milliseconds that measures a period of time from connecting test starts until
it must be completed.
|
private int |
connectionTestTimeout
The time-out in milliseconds that measures a period of time from connecting test starts until
it must be completed.
|
private static java.util.regex.Pattern |
DEBUGGER_ADDRESS_PATTERN
The search pattern for the debugger port
|
private int |
from
ports range started from this port number
|
private HostsManager |
hostsManager
The hosts manager
|
private static WebClientsManager |
instance
one instance per standard server
|
private boolean |
javaDebuggerNeeded
True value indicates that remote java debugger agent is provided by jvmArgs
|
private int |
javaDebuggerSinglePortNumber
The java debugger port number if this value is provided by jvmArgs
|
private static java.util.regex.Pattern |
JMX_PORT_PATTERN
The search pattern for the jmx agent port
|
private boolean |
jmxAgentNeeded
True value indicates that remote jmx agent is provided by jvmArgs
|
private int |
jmxAgentSinglePortNumber
The jmx agent port number if this value is provided by jvmArgs
|
private static CentralLogger |
LOG
Logger
|
private int |
maxAgentPort
Holds clientConfig/maxAgentPort value
|
private int |
minAgentPort
Holds clientConfig/minAgentPort value
|
private static int |
POLL_TIMEOUT_IN_MILLISECONDS
The poll timeout in milliseconds to get element from the queue
|
private int |
pollTimeout
The poll timeout in milliseconds to get element from the queue
|
private boolean |
portsRestricted
True value indicates that ports range is given
|
private java.lang.String |
prefix
Prefix is used to build mapping from ports to strings
|
private static java.lang.String |
PROXY_PATH_SEGMENT
The path segment used by default to represent a top level segment for forwarded urls exposed to www.
|
private java.lang.String |
proxyPathSegment
The path segment used to represent a top level segment for forwarded urls
|
private int |
to
ports range bounded by this port number
|
private java.util.Map<java.lang.String,WebAllocatedResources> |
webClientConfigs
Maps client's uuid to its configuration, the client uuid are unique within the given server
|
private java.util.Map<java.lang.Integer,WebAllocatedResources> |
webClientSessions
Maps the web client's remote address pair to its configuration
|
| Modifier | Constructor and Description |
|---|---|
private |
WebClientsManager()
Creates a unique instance per a standard P2J server.
|
| Modifier and Type | Method and Description |
|---|---|
WebAllocatedResources |
allocateClient(java.lang.String[] proxyConfigs,
java.lang.String host,
java.lang.String uuid,
java.lang.String osUser)
Allocates the dedicated port number from the restricted ports range for the new spawned
web client.
|
java.util.concurrent.BlockingQueue<WebAllocatedResources> |
createResourceQueue(java.lang.String host)
Create the resource queue filled with web clients ports if web client ports ranges are configured,
otherwise null.
|
void |
freeClient(java.lang.String uuid)
Releases the system resources for the web client given by uuid.
|
void |
freeWebClientResources(java.lang.String webClientId)
Releases the web client resources managed by the server.
|
static WebClientsManager |
getInstance()
Returns the web clients manager or null if is is not setup properly.
|
private int |
getTestPort(WebAllocatedResources webClientConfig)
Get the port to test.
|
void |
initialize(Session session)
This method is not implemented by WebClientsManager.
|
private boolean |
isAgentRangeConfigured()
Tests if the agent port range is configured.
|
boolean |
isJavaDebuggerNeeded()
Tests if java debugger agent string is provided by jvmArgs.
|
boolean |
isJmxAgentNeeded()
Tests if jmx agent string is provided by jvmArgs.
|
private void |
logLeakedPorts(WebAllocatedResources webClientConf,
java.lang.String host,
java.lang.InterruptedException ex)
Log leaked resource not added back to its queue.
|
private static int |
parseDebuggerPort(java.lang.String jvmArgs)
Get the debugger port from the jvm arguments string, otherwise return -1.
|
private static int |
parseJMXPort(java.lang.String jvmArgs)
Get the jmx agent port from the jvm arguments string, otherwise return -1.
|
void |
registerWebClientSession(java.lang.String webClientId,
int peerNode)
Registers the P2J session between the server and the web client to release its system
resources on the server side in the case if the web client is failed unexpectedly.
|
void |
terminate(Session session)
This method is called when the session is ending.
|
private static final CentralLogger LOG
private static final java.util.regex.Pattern JMX_PORT_PATTERN
private static final java.util.regex.Pattern DEBUGGER_ADDRESS_PATTERN
private static final int POLL_TIMEOUT_IN_MILLISECONDS
private static final int CONNECTING_TIMEOUT_IN_MILLISECONDS
private static final java.lang.String PROXY_PATH_SEGMENT
private static WebClientsManager instance
private final boolean portsRestricted
private final int from
private final int to
private final java.lang.String prefix
private final java.util.Map<java.lang.Integer,WebAllocatedResources> webClientSessions
private final java.util.Map<java.lang.String,java.util.TimerTask> cleaners
ClientSpawner.CLIENT_STARTUP_TIMEOUT_SEC, then the config is released.private final java.util.Timer cleanerTimer
private final java.util.Map<java.lang.String,WebAllocatedResources> webClientConfigs
private final HostsManager hostsManager
private final int minAgentPort
private final int maxAgentPort
private final boolean jmxAgentNeeded
private final int jmxAgentSinglePortNumber
private final boolean javaDebuggerNeeded
private final int javaDebuggerSinglePortNumber
private final java.lang.String proxyPathSegment
private final int pollTimeout
private final int connectionTestTimeout
private WebClientsManager()
throws java.lang.Exception
java.lang.Exception - if it is not setup properly.public static WebClientsManager getInstance()
At this time the code doesn't throw exceptions, it just logs them in the standard error stream.
public java.util.concurrent.BlockingQueue<WebAllocatedResources> createResourceQueue(java.lang.String host)
public boolean isJmxAgentNeeded()
public boolean isJavaDebuggerNeeded()
public WebAllocatedResources allocateClient(java.lang.String[] proxyConfigs, java.lang.String host, java.lang.String uuid, java.lang.String osUser)
allocateClient in interface WebClientAllocatorproxyConfigs - The first element should hold the forwarded host and the second one the corresponding
forwarded protocol.host - The remote host for the spawned web clientuuid - The web client uuidosUser - The OS user namepublic void registerWebClientSession(java.lang.String webClientId,
int peerNode)
registerWebClientSession in interface WebClientRegistrarwebClientId - The web client unique identifierpeerNode - The remote node of the P2J session between the server and the web clientpublic void initialize(Session session)
initialize in interface SessionListenersession - The session that is starting.public void freeClient(java.lang.String uuid)
freeClient in interface WebClientAllocatoruuid - The web client uuidpublic void freeWebClientResources(java.lang.String webClientId)
freeWebClientResources in interface WebClientRegistrarwebClientId - The web client unique identifierpublic void terminate(Session session)
terminate in interface SessionListenersession - The session that is ending.private boolean isAgentRangeConfigured()
private void logLeakedPorts(WebAllocatedResources webClientConf, java.lang.String host, java.lang.InterruptedException ex)
webClientConf - The web client config not added back to its queuehost - The host managed these web resourcesex - The root cause exceptionprivate int getTestPort(WebAllocatedResources webClientConfig)
webClientConfig - The given web client configprivate static int parseDebuggerPort(java.lang.String jvmArgs)
jvmArgs - The jvm arguments stringprivate static int parseJMXPort(java.lang.String jvmArgs)
jvmArgs - The jvm arguments string