public class ConnectionThrottleFilter extends IoFilterAdapter
IoFilter which blocks connections from connecting
at a rate faster than the specified interval.| Modifier and Type | Class and Description |
|---|---|
private class |
ConnectionThrottleFilter.ExpiredSessionThread |
IoFilter.NextFilter| Modifier and Type | Field and Description |
|---|---|
private long |
allowedInterval
The minimal delay the sessions will have to wait before being created
again
|
private java.util.Map<java.lang.String,java.lang.Long> |
clients
The map of created sessiosn, associated with the time they were created
|
private static long |
DEFAULT_TIME
The default delay to wait for a session to be accepted again
|
private java.util.concurrent.locks.Lock |
lock
A lock used to protect the map from concurrent modifications
|
private static org.slf4j.Logger |
LOGGER
A logger for this class
|
| Constructor and Description |
|---|
ConnectionThrottleFilter()
Default constructor.
|
ConnectionThrottleFilter(long allowedInterval)
Constructor that takes in a specified wait time.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
isConnectionOk(IoSession session)
Method responsible for deciding if a connection is OK
to continue
|
void |
sessionCreated(IoFilter.NextFilter nextFilter,
IoSession session)
Filters
IoHandler.sessionCreated(IoSession) event. |
void |
setAllowedInterval(long allowedInterval)
Sets the interval between connections from a client.
|
destroy, exceptionCaught, filterClose, filterWrite, init, inputClosed, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionIdle, sessionOpened, toStringprivate static final org.slf4j.Logger LOGGER
private static final long DEFAULT_TIME
private long allowedInterval
private final java.util.Map<java.lang.String,java.lang.Long> clients
private java.util.concurrent.locks.Lock lock
public ConnectionThrottleFilter()
public ConnectionThrottleFilter(long allowedInterval)
allowedInterval - The number of milliseconds a client is allowed to wait
before making another successful connectionpublic void setAllowedInterval(long allowedInterval)
allowedInterval - The number of milliseconds a client is allowed to wait
before making another successful connectionprotected boolean isConnectionOk(IoSession session)
session - The new session that will be verifiedpublic void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
IoFilterAdapterIoHandler.sessionCreated(IoSession) event.sessionCreated in interface IoFiltersessionCreated in class IoFilterAdapternextFilter - the IoFilter.NextFilter for this filter. You can reuse this
object until this filter is removed from the chain.session - The IoSession which has received this eventjava.lang.Exception