Top Description Fields Constructors Methods
org.eclipse.jetty.server

public Class ConnectionLimit

extends AbstractLifeCycle
implements Listener, AcceptListener
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.io.SelectorManager.AcceptListener, org.eclipse.jetty.io.SelectorManager.SelectorManagerListener, java.util.EventListener, org.eclipse.jetty.io.Connection.Listener
Annotations
@ManagedObject
Imports
java.nio.channels.SelectableChannel, java.util.ArrayList, .HashSet, .List, .Set, org.eclipse.jetty.io.Connection, .Connection.Listener, .EndPoint, .SelectorManager, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, .Name, org.eclipse.jetty.util.component.AbstractLifeCycle, .Container, org.eclipse.jetty.util.thread.AutoLock, org.slf4j.Logger, .LoggerFactory

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
LowResourceMonitor, Connection.Listener, SelectorManager.AcceptListener

Field Summary

Modifier and TypeField and Description
private final Set<SelectableChannel>
private int
private final List<AbstractConnector>
private long
private boolean
private final AutoLock
private int
private final Server
private static final Logger
Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
FAILEDSTARTEDSTARTINGSTOPPEDSTOPPING

Constructor Summary

AccessConstructor and Description
public
ConnectionLimit(int maxConnections, Server server)

public
ConnectionLimit(int maxConnections, Connector... connectors)

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
doStart()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Method to override to start the lifecycle

protected void
doStop()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Method to override to stop the lifecycle

public int
public long
getIdleTimeout()

Returns: If >= 0, the endpoint idle timeout in ms to apply when the connection limit is reached

public int
protected void
public void
onAccepted(SelectableChannel
the accepted channel
channel
)

Overrides default org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepted.

Called after the accepted channel has been allocated an EndPoint and associated Connection, and after the onOpen notifications have been called on both endPoint and connection.

public void
onAcceptFailed(SelectableChannel
the accepted channel
channel
,
Throwable
the cause of the failure
cause
)

Overrides default org.eclipse.jetty.io.SelectorManager.AcceptListener.onAcceptFailed.

Called if the processing of the accepted channel fails prior to calling onAccepted(SelectableChannel).

public void
onAccepting(SelectableChannel
the accepted channel
channel
)

Overrides default org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepting.

Called immediately after a new SelectableChannel is accepted, but before it has been submitted to the SelectorManager.

public void
public void
public void
setIdleTimeout(long
If >= 0 the endpoint idle timeout in ms to apply when the connection limit is reached
idleTimeout
)

public void
protected void
Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
addEventListenergetEventListenersgetStategetStateisFailedisRunningisStartedisStartingisStoppedisStoppingremoveEventListenersetEventListenersstartstoptoString

Field Detail

_acceptingback to summary
private final Set<SelectableChannel> _accepting
_connectionsback to summary
private int _connections
_connectorsback to summary
private final List<AbstractConnector> _connectors
_idleTimeoutback to summary
private long _idleTimeout
_limitingback to summary
private boolean _limiting
_lockback to summary
private final AutoLock _lock

Hides org.eclipse.jetty.util.component.AbstractLifeCycle._lock.

_maxConnectionsback to summary
private int _maxConnections
_serverback to summary
private final Server _server
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.AbstractLifeCycle.LOG.

Constructor Detail

ConnectionLimitback to summary
public ConnectionLimit(int maxConnections, Server server)
ConnectionLimitback to summary
public ConnectionLimit(int maxConnections, Connector... connectors)

Method Detail

checkback to summary
protected void check()
doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Method to override to start the lifecycle

Annotations
@Override
Exceptions
Exception:
If there was a problem starting. Will cause a transition to FAILED state
doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Method to override to stop the lifecycle

Annotations
@Override
Exceptions
Exception:
If there was a problem stopping. Will cause a transition to FAILED state
getConnectionsback to summary
public int getConnections()
Annotations
@ManagedAttribute:The current number of connections
getIdleTimeoutback to summary
public long getIdleTimeout()
Returns:long

If >= 0, the endpoint idle timeout in ms to apply when the connection limit is reached

Annotations
@ManagedAttribute:The endpoint idle timeout in ms to apply when the connection limit is reached
getMaxConnectionsback to summary
public int getMaxConnections()
Annotations
@ManagedAttribute:The maximum number of connections allowed
limitback to summary
protected void limit()
onAcceptedback to summary
public void onAccepted(SelectableChannel channel)

Overrides default org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepted.

Doc from org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepted.

Called after the accepted channel has been allocated an EndPoint and associated Connection, and after the onOpen notifications have been called on both endPoint and connection.

Parameters
channel:SelectableChannel

the accepted channel

Annotations
@Override
onAcceptFailedback to summary
public void onAcceptFailed(SelectableChannel channel, Throwable cause)

Overrides default org.eclipse.jetty.io.SelectorManager.AcceptListener.onAcceptFailed.

Doc from org.eclipse.jetty.io.SelectorManager.AcceptListener.onAcceptFailed.

Called if the processing of the accepted channel fails prior to calling onAccepted(SelectableChannel).

Parameters
channel:SelectableChannel

the accepted channel

cause:Throwable

the cause of the failure

Annotations
@Override
onAcceptingback to summary
public void onAccepting(SelectableChannel channel)

Overrides default org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepting.

Doc from org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepting.

Called immediately after a new SelectableChannel is accepted, but before it has been submitted to the SelectorManager.

Parameters
channel:SelectableChannel

the accepted channel

Annotations
@Override
onClosedback to summary
public void onClosed(Connection connection)

Overrides default org.eclipse.jetty.io.Connection.Listener.onClosed.

Annotations
@Override
onOpenedback to summary
public void onOpened(Connection connection)

Overrides default org.eclipse.jetty.io.Connection.Listener.onOpened.

Annotations
@Override
setIdleTimeoutback to summary
public void setIdleTimeout(long idleTimeout)
Parameters
idleTimeout:long

If >= 0 the endpoint idle timeout in ms to apply when the connection limit is reached

setMaxConnectionsback to summary
public void setMaxConnections(int max)
unlimitback to summary
protected void unlimit()