Class NetworkConnectionLimit
- All Implemented Interfaces:
 EventListener, SelectorManager.AcceptListener, SelectorManager.SelectorManagerListener, LifeCycle
A listener that limits the number of network connections.
This listener applies a limit to the number of network connections, which when
exceeded results in a call to AbstractConnector.setAccepting(boolean)
to prevent further network connections to be accepted.
This listener can be applied to an entire Server or to a specific
Connector by adding it via Container.addBean(Object).
When the number of network connections is exceeded, the idle timeout of existing
EndPoints is changed to the value configured in this listener (typically
a shorter value).
When the number of network connections returns below the limit, as they
are closed, the idle timeout of existing EndPoints is restored
to that of the connector.
Typical usage:
Server server = new Server();
server.addBean(new NetworkConnectionLimit(5000, server));
...
server.start();
- See Also:
 
- 
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener - 
Field Summary
 - 
Constructor Summary
ConstructorsConstructorDescriptionNetworkConnectionLimit(int maxNetworkConnections, Connector... connectors) NetworkConnectionLimit(int maxNetworkConnections, Server server)  - 
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoStart()Method to override to start the lifecycleprotected voiddoStop()Method to override to stop the lifecyclelongintintintprotected voidlimit()voidonAccepted(SelectableChannel channel) Called after the accepted channel has been allocated anEndPointand associatedConnection, and after the onOpen notifications have been called on both endPoint and connection.voidonAcceptFailed(SelectableChannel channel, Throwable cause) Called if the processing of the accepted channel fails prior to callingSelectorManager.AcceptListener.onAccepted(SelectableChannel).voidonAccepting(SelectableChannel channel) Called immediately after a new SelectableChannel is accepted, but before it has been submitted to theSelectorManager.voidonClosed(SelectableChannel channel) Called when an acceptedSelectableChannelis closed.voidsetEndPointIdleTimeout(long idleTimeout) Sets the idle timeout in ms to apply to all EndPoints when the network connection limit is reached.voidsetMaxNetworkConnectionCount(int max) protected voidunlimit()Methods inherited from class AbstractLifeCycle
addEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, start, stop, toString 
- 
Constructor Details
- 
NetworkConnectionLimit
 - 
NetworkConnectionLimit
 
 - 
 - 
Method Details
- 
getEndPointIdleTimeout
@ManagedAttribute("The EndPoint idle timeout in ms to apply when the network connection limit is reached") public long getEndPointIdleTimeout()- Returns:
 - the idle timeout in ms to apply to all EndPoints when the network connection limit is reached
 
 - 
setEndPointIdleTimeout
public void setEndPointIdleTimeout(long idleTimeout) Sets the idle timeout in ms to apply to all EndPoints when the network connection limit is reached.
A value less than or equal to zero will not change the existing EndPoint idle timeout.
- Parameters:
 idleTimeout- the idle timeout in ms to apply to all EndPoints when the network connection limit is reached
 - 
getMaxNetworkConnectionCount
@ManagedAttribute("The maximum number of network connections") public int getMaxNetworkConnectionCount() - 
setMaxNetworkConnectionCount
public void setMaxNetworkConnectionCount(int max)  - 
getNetworkConnectionCount
@ManagedAttribute("The number of connected network connections") public int getNetworkConnectionCount() - 
getPendingNetworkConnectionCount
@ManagedAttribute("The number of pending network connections") public int getPendingNetworkConnectionCount() - 
doStart
Description copied from class:AbstractLifeCycleMethod to override to start the lifecycle- Overrides:
 doStartin classAbstractLifeCycle- Throws:
 Exception- If there was a problem starting. Will cause a transition to FAILED state
 - 
doStop
Description copied from class:AbstractLifeCycleMethod to override to stop the lifecycle- Overrides:
 doStopin classAbstractLifeCycle- Throws:
 Exception- If there was a problem stopping. Will cause a transition to FAILED state
 - 
limit
protected void limit() - 
unlimit
protected void unlimit() - 
onAccepting
Description copied from interface:SelectorManager.AcceptListenerCalled immediately after a new SelectableChannel is accepted, but before it has been submitted to theSelectorManager.- Specified by:
 onAcceptingin interfaceSelectorManager.AcceptListener- Parameters:
 channel- the accepted channel
 - 
onAcceptFailed
Description copied from interface:SelectorManager.AcceptListenerCalled if the processing of the accepted channel fails prior to callingSelectorManager.AcceptListener.onAccepted(SelectableChannel).- Specified by:
 onAcceptFailedin interfaceSelectorManager.AcceptListener- Parameters:
 channel- the accepted channelcause- the cause of the failure
 - 
onAccepted
Description copied from interface:SelectorManager.AcceptListenerCalled after the accepted channel has been allocated anEndPointand associatedConnection, and after the onOpen notifications have been called on both endPoint and connection.- Specified by:
 onAcceptedin interfaceSelectorManager.AcceptListener- Parameters:
 channel- the accepted channel
 - 
onClosed
Description copied from interface:SelectorManager.AcceptListenerCalled when an acceptedSelectableChannelis closed.- Specified by:
 onClosedin interfaceSelectorManager.AcceptListener- Parameters:
 channel- the accepted channel
 
 -