Class NetworkConnectionLimit
- All Implemented Interfaces:
EventListener, org.eclipse.jetty.io.SelectorManager.AcceptListener, org.eclipse.jetty.io.SelectorManager.SelectorManagerListener, org.eclipse.jetty.util.component.LifeCycle
A listener that limits the number of network connections.
This listener applies a limit to the number of network connections, which when
exceeded results in a call to AbstractConnector.setAccepting(boolean)
to prevent further network connections to be accepted.
This listener can be applied to an entire Server or to a specific
Connector by adding it via Container.addBean(Object).
When the number of network connections is exceeded, the idle timeout of existing
EndPoints is changed to the value configured in this listener (typically
a shorter value).
When the number of network connections returns below the limit, as they
are closed, the idle timeout of existing EndPoints is restored
to that of the connector.
Typical usage:
Server server = new Server();
server.addBean(new NetworkConnectionLimit(5000, server));
...
server.start();
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener -
Field Summary
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPING -
Constructor Summary
ConstructorsConstructorDescriptionNetworkConnectionLimit(int maxNetworkConnections, Connector... connectors) NetworkConnectionLimit(int maxNetworkConnections, Server server) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoStart()protected voiddoStop()longintintintprotected voidlimit()voidonAccepted(SelectableChannel channel) voidonAcceptFailed(SelectableChannel channel, Throwable cause) voidonAccepting(SelectableChannel channel) voidonClosed(SelectableChannel channel) voidsetEndPointIdleTimeout(long idleTimeout) Sets the idle timeout in ms to apply to all EndPoints when the network connection limit is reached.voidsetMaxNetworkConnectionCount(int max) protected voidunlimit()Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, start, stop, toString
-
Constructor Details
-
NetworkConnectionLimit
public NetworkConnectionLimit(@Name("maxNetworkConnectionCount") int maxNetworkConnections, @Name("server") Server server) -
NetworkConnectionLimit
public NetworkConnectionLimit(@Name("maxNetworkConnectionCount") int maxNetworkConnections, @Name("connectors") Connector... connectors)
-
-
Method Details
-
getEndPointIdleTimeout
@ManagedAttribute("The EndPoint idle timeout in ms to apply when the network connection limit is reached") public long getEndPointIdleTimeout()- Returns:
- the idle timeout in ms to apply to all EndPoints when the network connection limit is reached
-
setEndPointIdleTimeout
public void setEndPointIdleTimeout(long idleTimeout) Sets the idle timeout in ms to apply to all EndPoints when the network connection limit is reached.
A value less than or equal to zero will not change the existing EndPoint idle timeout.
- Parameters:
idleTimeout- the idle timeout in ms to apply to all EndPoints when the network connection limit is reached
-
getMaxNetworkConnectionCount
@ManagedAttribute("The maximum number of network connections") public int getMaxNetworkConnectionCount() -
setMaxNetworkConnectionCount
public void setMaxNetworkConnectionCount(int max) -
getNetworkConnectionCount
@ManagedAttribute("The number of connected network connections") public int getNetworkConnectionCount() -
getPendingNetworkConnectionCount
@ManagedAttribute("The number of pending network connections") public int getPendingNetworkConnectionCount() -
doStart
-
doStop
-
limit
protected void limit() -
unlimit
protected void unlimit() -
onAccepting
- Specified by:
onAcceptingin interfaceorg.eclipse.jetty.io.SelectorManager.AcceptListener
-
onAcceptFailed
- Specified by:
onAcceptFailedin interfaceorg.eclipse.jetty.io.SelectorManager.AcceptListener
-
onAccepted
- Specified by:
onAcceptedin interfaceorg.eclipse.jetty.io.SelectorManager.AcceptListener
-
onClosed
- Specified by:
onClosedin interfaceorg.eclipse.jetty.io.SelectorManager.AcceptListener
-