@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.AcceptListener
AbstractLifeCycle.AbstractLifeCycleListener
Connection.Listener.Adapter
LifeCycle.Listener
Constructor and Description |
---|
ConnectionLimit(int maxConnections,
Connector... connectors) |
ConnectionLimit(int maxConnections,
Server server) |
Modifier and Type | Method and 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)
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(java.nio.channels.SelectableChannel channel,
java.lang.Throwable cause)
Called if the processing of the accepted channel fails prior to calling
SelectorManager.AcceptListener.onAccepted(SelectableChannel) . |
void |
onAccepting(java.nio.channels.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) |
protected void |
unlimit() |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop, toString
public 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()
protected void doStart() throws java.lang.Exception
doStart
in class AbstractLifeCycle
java.lang.Exception
protected void doStop() throws java.lang.Exception
doStop
in class AbstractLifeCycle
java.lang.Exception
protected void check()
protected void limit()
protected void unlimit()
public void onAccepting(java.nio.channels.SelectableChannel channel)
SelectorManager.AcceptListener
SelectorManager
.onAccepting
in interface SelectorManager.AcceptListener
channel
- the accepted channelpublic void onAcceptFailed(java.nio.channels.SelectableChannel channel, java.lang.Throwable cause)
SelectorManager.AcceptListener
SelectorManager.AcceptListener.onAccepted(SelectableChannel)
.onAcceptFailed
in interface SelectorManager.AcceptListener
channel
- the accepted channelcause
- the cause of the failurepublic void onAccepted(java.nio.channels.SelectableChannel channel)
SelectorManager.AcceptListener
EndPoint
and associated Connection
, and after the onOpen notifications have
been called on both endPoint and connection.onAccepted
in interface SelectorManager.AcceptListener
channel
- the accepted channelpublic void onOpened(Connection connection)
onOpened
in interface Connection.Listener
public void onClosed(Connection connection)
onClosed
in interface Connection.Listener
Copyright © 1995–2023 Webtide. All rights reserved.