Package org.eclipse.jetty.server
Class ConnectionLimit
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.server.ConnectionLimit
- All Implemented Interfaces:
EventListener
,Connection.Listener
,SelectorManager.AcceptListener
,SelectorManager.SelectorManagerListener
,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();
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection.Listener
Connection.Listener.Adapter
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConnectionLimit
(int maxConnections, Connector... connectors) ConnectionLimit
(int maxConnections, Server server) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
check()
protected void
doStart()
Method to override to start the lifecycleprotected void
doStop()
Method to override to stop the lifecycleint
long
int
protected void
limit()
void
onAccepted
(SelectableChannel channel) Called after the accepted channel has been allocated anEndPoint
and associatedConnection
, and after the onOpen notifications have been called on both endPoint and connection.void
onAcceptFailed
(SelectableChannel channel, Throwable cause) Called if the processing of the accepted channel fails prior to callingSelectorManager.AcceptListener.onAccepted(SelectableChannel)
.void
onAccepting
(SelectableChannel channel) Called immediately after a new SelectableChannel is accepted, but before it has been submitted to theSelectorManager
.void
onClosed
(Connection connection) void
onOpened
(Connection connection) void
setIdleTimeout
(long idleTimeout) void
setMaxConnections
(int max) protected void
unlimit()
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
-
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
Description copied from class:AbstractLifeCycle
Method to override to start the lifecycle- Overrides:
doStart
in classAbstractLifeCycle
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:AbstractLifeCycle
Method to override to stop the lifecycle- Overrides:
doStop
in classAbstractLifeCycle
- Throws:
Exception
- If there was a problem stopping. Will cause a transition to FAILED state
-
check
protected void check() -
limit
protected void limit() -
unlimit
protected void unlimit() -
onAccepting
Description copied from interface:SelectorManager.AcceptListener
Called immediately after a new SelectableChannel is accepted, but before it has been submitted to theSelectorManager
.- Specified by:
onAccepting
in interfaceSelectorManager.AcceptListener
- Parameters:
channel
- the accepted channel
-
onAcceptFailed
Description copied from interface:SelectorManager.AcceptListener
Called if the processing of the accepted channel fails prior to callingSelectorManager.AcceptListener.onAccepted(SelectableChannel)
.- Specified by:
onAcceptFailed
in interfaceSelectorManager.AcceptListener
- Parameters:
channel
- the accepted channelcause
- the cause of the failure
-
onAccepted
Description copied from interface:SelectorManager.AcceptListener
Called after the accepted channel has been allocated anEndPoint
and associatedConnection
, and after the onOpen notifications have been called on both endPoint and connection.- Specified by:
onAccepted
in interfaceSelectorManager.AcceptListener
- Parameters:
channel
- the accepted channel
-
onOpened
- Specified by:
onOpened
in interfaceConnection.Listener
-
onClosed
- Specified by:
onClosed
in interfaceConnection.Listener
-