Top Description Inners Fields Constructors Methods
org.eclipse.jetty.server

public Class AcceptRateLimit

extends AbstractLifeCycle
implements AcceptListener, Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable, org.eclipse.jetty.io.SelectorManager.AcceptListener, org.eclipse.jetty.io.SelectorManager.SelectorManagerListener, java.util.EventListener
Annotations
@ManagedObject
Imports
java.nio.channels.SelectableChannel, java.util.ArrayList, .List, java.util.concurrent.TimeUnit, org.eclipse.jetty.io.SelectorManager, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, .ManagedOperation, .Name, org.eclipse.jetty.util.component.AbstractLifeCycle, .Container, org.eclipse.jetty.util.statistic.RateStatistic, org.eclipse.jetty.util.thread.AutoLock, .Scheduler, org.slf4j.Logger, .LoggerFactory

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();
See Also
SelectorManager.AcceptListener

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final int
private final List<AbstractConnector>
private boolean
private final AutoLock
private final AcceptRateLimit.Rate
private final Server
private Scheduler.Task
private static final Logger
Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
FAILEDSTARTEDSTARTINGSTOPPEDSTOPPING

Constructor Summary

AccessConstructor and Description
public
AcceptRateLimit(int acceptRateLimit, long period, TimeUnit units, Server server)

public
AcceptRateLimit(int limit, long period, TimeUnit units, Connector... connectors)

Method Summary

Modifier and TypeMethod and Description
protected void
age(long period, TimeUnit units)

protected void
doStart()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Method to override to start the lifecycle
protected void
doStop()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Method to override to stop the lifecycle
public int
public long
public long
public int
public TimeUnit
protected void
public void
onAccepting(SelectableChannel
the accepted channel
channel
)

Overrides default org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepting.

Called immediately after a new SelectableChannel is accepted, but before it has been submitted to the SelectorManager.
public void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
private void
protected void
Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
addEventListenergetEventListenersgetStategetStateisFailedisRunningisStartedisStartingisStoppedisStoppingremoveEventListenersetEventListenersstartstoptoString

Field Detail

_acceptRateLimitback to summary
private final int _acceptRateLimit
_connectorsback to summary
private final List<AbstractConnector> _connectors
_limitingback to summary
private boolean _limiting
_lockback to summary
private final AutoLock _lock

Hides org.eclipse.jetty.util.component.AbstractLifeCycle._lock.

_rateback to summary
private final AcceptRateLimit.Rate _rate
_serverback to summary
private final Server _server
_taskback to summary
private Scheduler.Task _task
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.AbstractLifeCycle.LOG.

Constructor Detail

AcceptRateLimitback to summary
public AcceptRateLimit(int acceptRateLimit, long period, TimeUnit units, Server server)
AcceptRateLimitback to summary
public AcceptRateLimit(int limit, long period, TimeUnit units, Connector... connectors)

Method Detail

ageback to summary
protected void age(long period, TimeUnit units)
doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Method to override to start the lifecycle

Annotations
@Override
Exceptions
Exception:
If there was a problem starting. Will cause a transition to FAILED state
doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Method to override to stop the lifecycle

Annotations
@Override
Exceptions
Exception:
If there was a problem stopping. Will cause a transition to FAILED state
getAcceptRateLimitback to summary
public int getAcceptRateLimit()
Annotations
@ManagedAttribute:The accept rate limit
getMaxRateback to summary
public long getMaxRate()
Annotations
@ManagedAttribute:The maximum accept rate achieved
getPeriodback to summary
public long getPeriod()
Annotations
@ManagedAttribute:The accept rate period
getRateback to summary
public int getRate()
Annotations
@ManagedAttribute:The current accept rate
getUnitsback to summary
public TimeUnit getUnits()
Annotations
@ManagedAttribute:The accept rate period units
limitback to summary
protected void limit()
onAcceptingback to summary
public void onAccepting(SelectableChannel channel)

Overrides default org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepting.

Doc from org.eclipse.jetty.io.SelectorManager.AcceptListener.onAccepting.

Called immediately after a new SelectableChannel is accepted, but before it has been submitted to the SelectorManager.

Parameters
channel:SelectableChannel

the accepted channel

Annotations
@Override
resetback to summary
public void reset()
Annotations
@ManagedOperation:Resets the accept rate
impact:ACTION
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
scheduleback to summary
private void schedule()
unlimitback to summary
protected void unlimit()
org.eclipse.jetty.server back to summary

private final Class AcceptRateLimit.Rate

extends RateStatistic
Class Inheritance

Constructor Summary

AccessConstructor and Description
private
Rate(long period, TimeUnit units)

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from org.eclipse.jetty.util.statistic.RateStatistic:
dumpdumpgetCountgetMaxgetOldestgetPeriodgetRategetUnitsrecordresettoString

Constructor Detail

Rateback to summary
private Rate(long period, TimeUnit units)

Method Detail

ageback to summary
protected void age(long period, TimeUnit units)

Overrides org.eclipse.jetty.util.statistic.RateStatistic.age.

Annotations
@Override