Package org.eclipse.jetty.server
Class ConnectionLimit
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.server.ConnectionLimit
-
- All Implemented Interfaces:
java.util.EventListener
,Connection.Listener
,SelectorManager.AcceptListener
,org.eclipse.jetty.util.component.LifeCycle
@ManagedObject public class ConnectionLimit extends org.eclipse.jetty.util.component.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 viaContainer.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
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection.Listener
Connection.Listener.Adapter
-
-
Constructor Summary
Constructors Constructor Description ConnectionLimit(int maxConnections, Connector... connectors)
ConnectionLimit(int maxConnections, Server server)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
check()
protected void
doStart()
protected void
doStop()
int
getConnections()
long
getIdleTimeout()
int
getMaxConnections()
protected void
limit()
void
onAccepted(java.nio.channels.SelectableChannel channel)
void
onAcceptFailed(java.nio.channels.SelectableChannel channel, java.lang.Throwable cause)
void
onAccepting(java.nio.channels.SelectableChannel channel)
void
onClosed(Connection connection)
void
onOpened(Connection connection)
void
setIdleTimeout(long idleTimeout)
void
setMaxConnections(int max)
protected void
unlimit()
-
-
-
Method Detail
-
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
@ManagedAttribute("The maximum number of connections allowed") public int getMaxConnections()
-
setMaxConnections
public void setMaxConnections(int max)
-
getConnections
@ManagedAttribute("The current number of connections ") public int getConnections()
-
doStart
protected void doStart() throws java.lang.Exception
- Overrides:
doStart
in classorg.eclipse.jetty.util.component.AbstractLifeCycle
- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception
- Overrides:
doStop
in classorg.eclipse.jetty.util.component.AbstractLifeCycle
- Throws:
java.lang.Exception
-
check
protected void check()
-
limit
protected void limit()
-
unlimit
protected void unlimit()
-
onAccepting
public void onAccepting(java.nio.channels.SelectableChannel channel)
- Specified by:
onAccepting
in interfaceSelectorManager.AcceptListener
-
onAcceptFailed
public void onAcceptFailed(java.nio.channels.SelectableChannel channel, java.lang.Throwable cause)
- Specified by:
onAcceptFailed
in interfaceSelectorManager.AcceptListener
-
onAccepted
public void onAccepted(java.nio.channels.SelectableChannel channel)
- Specified by:
onAccepted
in interfaceSelectorManager.AcceptListener
-
onOpened
public void onOpened(Connection connection)
- Specified by:
onOpened
in interfaceConnection.Listener
-
onClosed
public void onClosed(Connection connection)
- Specified by:
onClosed
in interfaceConnection.Listener
-
-