Class ConnectionLimit
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.server.ConnectionLimit
- All Implemented Interfaces:
EventListener, Connection.Listener, SelectorManager.AcceptListener, LifeCycle
@ManagedObject
public class ConnectionLimit
extends AbstractLifeCycle
implements Connection.Listener, SelectorManager.AcceptListener
A Listener that limits the number of Connections.
This listener applies a limit to the number of connections, which when
exceeded results in a call to AbstractConnector.setAccepting(boolean)
to prevent further connections being received. It can be applied to an
entire server or to a specific connector by adding it via Container.addBean(Object)
Usage:
Server server = new Server(); server.addBean(new ConnectionLimit(5000,server)); ... server.start();
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListenerNested classes/interfaces inherited from interface Connection.Listener
Connection.Listener.AdapterNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Set<SelectableChannel> private intprivate final List<AbstractConnector> private longprivate booleanprivate intprivate final Serverprivate static final Logger -
Constructor Summary
ConstructorsConstructorDescriptionConnectionLimit(int maxConnections, Connector... connectors) ConnectionLimit(int maxConnections, Server server) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheck()protected voiddoStart()protected voiddoStop()intlongintprotected voidlimit()voidonAccepted(SelectableChannel channel) Called after the accepted channel has been allocated anEndPointand associatedConnection, and after the onOpen notifications have been called on both endPoint and connection.voidonAcceptFailed(SelectableChannel channel, Throwable cause) Called if the processing of the accepted channel fails prior to callingSelectorManager.AcceptListener.onAccepted(SelectableChannel).voidonAccepting(SelectableChannel channel) Called immediately after a new SelectableChannel is accepted, but before it has been submitted to theSelectorManager.voidonClosed(Connection connection) voidonOpened(Connection connection) voidsetIdleTimeout(long idleTimeout) voidsetMaxConnections(int max) protected voidunlimit()Methods inherited from class AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop, toString
-
Field Details
-
LOG
-
_server
-
_connectors
-
_accepting
-
_connections
private int _connections -
_maxConnections
private int _maxConnections -
_idleTimeout
private long _idleTimeout -
_limiting
private boolean _limiting
-
-
Constructor Details
-
ConnectionLimit
-
ConnectionLimit
-
-
Method Details
-
getIdleTimeout
@ManagedAttribute("The endpoint idle timeout in ms to apply when the connection limit is reached") public long getIdleTimeout()- Returns:
- If >= 0, the endpoint idle timeout in ms to apply when the connection limit is reached
-
setIdleTimeout
public void setIdleTimeout(long idleTimeout) - Parameters:
idleTimeout- If >= 0 the endpoint idle timeout in ms to apply when the connection limit is reached
-
getMaxConnections
-
setMaxConnections
public void setMaxConnections(int max) -
getConnections
-
doStart
- Overrides:
doStartin classAbstractLifeCycle- Throws:
Exception
-
doStop
- Overrides:
doStopin classAbstractLifeCycle- Throws:
Exception
-
check
protected void check() -
limit
protected void limit() -
unlimit
protected void unlimit() -
onAccepting
Description copied from interface:SelectorManager.AcceptListenerCalled immediately after a new SelectableChannel is accepted, but before it has been submitted to theSelectorManager.- Specified by:
onAcceptingin interfaceSelectorManager.AcceptListener- Parameters:
channel- the accepted channel
-
onAcceptFailed
Description copied from interface:SelectorManager.AcceptListenerCalled if the processing of the accepted channel fails prior to callingSelectorManager.AcceptListener.onAccepted(SelectableChannel).- Specified by:
onAcceptFailedin interfaceSelectorManager.AcceptListener- Parameters:
channel- the accepted channelcause- the cause of the failure
-
onAccepted
Description copied from interface:SelectorManager.AcceptListenerCalled after the accepted channel has been allocated anEndPointand associatedConnection, and after the onOpen notifications have been called on both endPoint and connection.- Specified by:
onAcceptedin interfaceSelectorManager.AcceptListener- Parameters:
channel- the accepted channel
-
onOpened
- Specified by:
onOpenedin interfaceConnection.Listener
-
onClosed
- Specified by:
onClosedin interfaceConnection.Listener
-