public class LowResourceMonitor
extends AbstractLifeCycle
An instance of this class will monitor all the connectors of a server (or a set of connectors
configured with setMonitoredConnectors(Collection)) for a low resources state.
Low resources can be detected by:
ThreadPool#isLowOnThreads() if Connector.getExecutor() is
an instance of ThreadPool and setMonitorThreads(boolean) is true.setMaxMemory(long) is non zero then low resources is detected if the JVMs
Runtime instance has Runtime.totalMemory() minus Runtime.freeMemory()
greater than getMaxMemory()setMaxConnections(int) is non zero then low resources is dected if the total number
of connections exceeds getMaxConnections()
Once low resources state is detected, the cause is logged and all existing connections returned
by Connector.getConnectedEndPoints() have EndPoint#setIdleTimeout(long) set
to getLowResourcesIdleTimeout(). New connections are not affected, however if the low
resources state persists for more than getMaxLowResourcesTime(), then the
getLowResourcesIdleTimeout() to all connections again. Once the low resources state is
cleared, the idle timeout is reset to the connector default given by Connector.getIdleTimeout().
If setAcceptingInLowResources(boolean) is set to false (Default is true), then no new connections
are accepted when in low resources state.
| Constructor and Description |
|---|
LowResourceMonitor(Server server) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
clearLowResources() |
protected void |
doStart() |
protected void |
doStop() |
int |
getLowResourcesIdleTimeout() |
java.lang.String |
getLowResourcesReasons() |
long |
getLowResourcesStarted() |
int |
getMaxConnections() |
int |
getMaxLowResourcesTime() |
long |
getMaxMemory() |
java.util.Collection<Connector> |
getMonitoredConnectors() |
protected Connector[] |
getMonitoredOrServerConnectors() |
boolean |
getMonitorThreads() |
int |
getPeriod() |
boolean |
isAcceptingInLowResources() |
boolean |
isLowOnResources() |
protected void |
monitor() |
void |
setAcceptingInLowResources(boolean acceptingInLowResources) |
protected void |
setLowResources() |
void |
setLowResourcesIdleTimeout(int lowResourcesIdleTimeoutMS) |
void |
setMaxConnections(int maxConnections) |
void |
setMaxLowResourcesTime(int maxLowResourcesTimeMS) |
void |
setMaxMemory(long maxMemoryBytes) |
void |
setMonitoredConnectors(java.util.Collection<Connector> monitoredConnectors) |
void |
setMonitorThreads(boolean monitorThreads) |
void |
setPeriod(int periodMS) |
public LowResourceMonitor(Server server)
public boolean isLowOnResources()
public java.lang.String getLowResourcesReasons()
public long getLowResourcesStarted()
public java.util.Collection<Connector> getMonitoredConnectors()
public void setMonitoredConnectors(java.util.Collection<Connector> monitoredConnectors)
monitoredConnectors - The collections of Connectors that should be monitored for low resources.public boolean isAcceptingInLowResources()
public void setAcceptingInLowResources(boolean acceptingInLowResources)
public int getPeriod()
public void setPeriod(int periodMS)
periodMS - The period in ms to monitor for low resourcespublic boolean getMonitorThreads()
public void setMonitorThreads(boolean monitorThreads)
monitorThreads - If true, check connectors executors to see if they are
ThreadPool instances that are low on threads.public int getMaxConnections()
public void setMaxConnections(int maxConnections)
maxConnections - The maximum connections before low resources state is triggeredpublic long getMaxMemory()
public void setMaxMemory(long maxMemoryBytes)
maxMemoryBytes - The maximum memory in bytes in use before low resources is triggered.public int getLowResourcesIdleTimeout()
public void setLowResourcesIdleTimeout(int lowResourcesIdleTimeoutMS)
lowResourcesIdleTimeoutMS - The timeout in ms to apply to EndPoints when in the low resources state.public int getMaxLowResourcesTime()
public void setMaxLowResourcesTime(int maxLowResourcesTimeMS)
maxLowResourcesTimeMS - The time in milliseconds that a low resource state can persist before the low resource idle timeout is reapplied to all connectionsprotected void doStart()
throws java.lang.Exception
java.lang.Exceptionprotected void doStop()
throws java.lang.Exception
java.lang.Exceptionprotected Connector[] getMonitoredOrServerConnectors()
protected void monitor()
protected void setLowResources()
protected void clearLowResources()