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
EndPoint
s 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 EndPoint
s is restored
to that of the connector.
Typical usage:
Server server = new Server();
server.addBean(new NetworkConnectionLimit(5000, server));
...
server.start();
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionNetworkConnectionLimit
(int maxNetworkConnections, Connector... connectors) NetworkConnectionLimit
(int maxNetworkConnections, Server server) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doStart()
Method to override to start the lifecycleprotected void
doStop()
Method to override to stop the lifecyclelong
int
int
int
protected void
limit()
void
onAccepted
(SelectableChannel channel) Called after the accepted channel has been allocated anEndPoint
and associatedConnection
, 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 callingSelectorManager.AcceptListener.onAccepted(SelectableChannel)
.void
onAccepting
(SelectableChannel channel) Called immediately after a new SelectableChannel is accepted, but before it has been submitted to theSelectorManager
.void
onClosed
(SelectableChannel channel) Called when an acceptedSelectableChannel
is closed.void
setEndPointIdleTimeout
(long idleTimeout) Sets the idle timeout in ms to apply to all EndPoints when the network connection limit is reached.void
setMaxNetworkConnectionCount
(int max) protected void
unlimit()
Methods inherited from class org.eclipse.jetty.util.component.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:AbstractLifeCycle
Method to override to start the lifecycle- Overrides:
doStart
in classAbstractLifeCycle
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:AbstractLifeCycle
Method to override to stop the lifecycle- Overrides:
doStop
in 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.AcceptListener
Called immediately after a new SelectableChannel is accepted, but before it has been submitted to theSelectorManager
.- Specified by:
onAccepting
in interfaceSelectorManager.AcceptListener
- Parameters:
channel
- the accepted channel
-
onAcceptFailed
Description copied from interface:SelectorManager.AcceptListener
Called if the processing of the accepted channel fails prior to callingSelectorManager.AcceptListener.onAccepted(SelectableChannel)
.- Specified by:
onAcceptFailed
in interfaceSelectorManager.AcceptListener
- Parameters:
channel
- the accepted channelcause
- the cause of the failure
-
onAccepted
Description copied from interface:SelectorManager.AcceptListener
Called after the accepted channel has been allocated anEndPoint
and associatedConnection
, and after the onOpen notifications have been called on both endPoint and connection.- Specified by:
onAccepted
in interfaceSelectorManager.AcceptListener
- Parameters:
channel
- the accepted channel
-
onClosed
Description copied from interface:SelectorManager.AcceptListener
Called when an acceptedSelectableChannel
is closed.- Specified by:
onClosed
in interfaceSelectorManager.AcceptListener
- Parameters:
channel
- the accepted channel
-