@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();
LowResourceMonitor,
Connection.Listener,
SelectorManager.AcceptListenerAbstractLifeCycle.AbstractLifeCycleListenerConnection.Listener.AdapterLifeCycle.Listener| Constructor and Description |
|---|
ConnectionLimit(int maxConnections,
Connector... connectors) |
ConnectionLimit(int maxConnections,
Server server) |
| Modifier and Type | Method and Description |
|---|---|
int |
getConnections() |
long |
getIdleTimeout() |
int |
getMaxConnections() |
void |
onAccepted(SelectableChannel channel)
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. |
void |
onAcceptFailed(SelectableChannel channel,
Throwable cause)
Called if the processing of the accepted channel fails prior to calling
SelectorManager.AcceptListener.onAccepted(SelectableChannel). |
void |
onAccepting(SelectableChannel channel)
Called immediately after a new SelectableChannel is accepted, but
before it has been submitted to the
SelectorManager. |
void |
onClosed(Connection connection) |
void |
onOpened(Connection connection) |
void |
setIdleTimeout(long idleTimeout) |
void |
setMaxConnections(int max) |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop, toStringpublic ConnectionLimit(@Name(value="maxConnections") int maxConnections, @Name(value="server") Server server)
@ManagedAttribute(value="The endpoint idle timeout in ms to apply when the connection limit is reached") public long getIdleTimeout()
public void setIdleTimeout(long idleTimeout)
idleTimeout - If >= 0 the endpoint idle timeout in ms to apply when the connection limit is reached@ManagedAttribute(value="The maximum number of connections allowed") public int getMaxConnections()
public void setMaxConnections(int max)
@ManagedAttribute(value="The current number of connections ") public int getConnections()
public void onAccepting(SelectableChannel channel)
SelectorManager.AcceptListenerSelectorManager.onAccepting in interface SelectorManager.AcceptListenerchannel - the accepted channelpublic void onAcceptFailed(SelectableChannel channel, Throwable cause)
SelectorManager.AcceptListenerSelectorManager.AcceptListener.onAccepted(SelectableChannel).onAcceptFailed in interface SelectorManager.AcceptListenerchannel - the accepted channelcause - the cause of the failurepublic void onAccepted(SelectableChannel channel)
SelectorManager.AcceptListenerEndPoint
and associated Connection, and after the onOpen notifications have
been called on both endPoint and connection.onAccepted in interface SelectorManager.AcceptListenerchannel - the accepted channelpublic void onOpened(Connection connection)
onOpened in interface Connection.Listenerpublic void onClosed(Connection connection)
onClosed in interface Connection.ListenerCopyright © 2010 - 2020 Adobe. All Rights Reserved