@ManagedObject public class AcceptRateLimit extends AbstractLifeCycle implements SelectorManager.AcceptListener, java.lang.Runnable
A Listener that limits the rate at which new connections are accepted
If the limits are exceeded, accepting is suspended until the rate is again below the limit, so incoming connections are held in the operating system accept queue (no syn ack sent), where they may either timeout or wait for the server to resume accepting.
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 AcceptLimit(100,5,TimeUnit.SECONDS,server)); ... server.start();
SelectorManager.AcceptListener
Modifier and Type | Class and Description |
---|---|
private class |
AcceptRateLimit.Rate |
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Modifier and Type | Field and Description |
---|---|
private int |
_acceptRateLimit |
private java.util.List<AbstractConnector> |
_connectors |
private boolean |
_limiting |
private AcceptRateLimit.Rate |
_rate |
private Server |
_server |
private Scheduler.Task |
_task |
private static Logger |
LOG |
Constructor and Description |
---|
AcceptRateLimit(int limit,
long period,
java.util.concurrent.TimeUnit units,
Connector... connectors) |
AcceptRateLimit(int acceptRateLimit,
long period,
java.util.concurrent.TimeUnit units,
Server server) |
Modifier and Type | Method and Description |
---|---|
protected void |
age(long period,
java.util.concurrent.TimeUnit units) |
protected void |
doStart() |
protected void |
doStop() |
int |
getAcceptRateLimit() |
long |
getMaxRate() |
long |
getPeriod() |
int |
getRate() |
java.util.concurrent.TimeUnit |
getUnits() |
protected void |
limit() |
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 |
reset() |
void |
run() |
private void |
schedule() |
protected void |
unlimit() |
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
onAccepted, onAcceptFailed
private static final Logger LOG
private final Server _server
private final java.util.List<AbstractConnector> _connectors
private final AcceptRateLimit.Rate _rate
private final int _acceptRateLimit
private boolean _limiting
private Scheduler.Task _task
public AcceptRateLimit(@Name(value="acceptRateLimit") int acceptRateLimit, @Name(value="period") long period, @Name(value="units") java.util.concurrent.TimeUnit units, @Name(value="server") Server server)
@ManagedAttribute(value="The accept rate limit") public int getAcceptRateLimit()
@ManagedAttribute(value="The accept rate period") public long getPeriod()
@ManagedAttribute(value="The accept rate period units") public java.util.concurrent.TimeUnit getUnits()
@ManagedAttribute(value="The current accept rate") public int getRate()
@ManagedAttribute(value="The maximum accept rate achieved") public long getMaxRate()
@ManagedOperation(value="Resets the accept rate", impact="ACTION") public void reset()
protected void age(long period, java.util.concurrent.TimeUnit units)
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 limit()
protected void unlimit()
public void onAccepting(java.nio.channels.SelectableChannel channel)
SelectorManager.AcceptListener
SelectorManager
.onAccepting
in interface SelectorManager.AcceptListener
channel
- the accepted channelprivate void schedule()
public void run()
run
in interface java.lang.Runnable