Class ConnectionThrottleFilter
java.lang.Object
org.apache.mina.core.filterchain.IoFilterAdapter
org.apache.mina.filter.firewall.ConnectionThrottleFilter
- All Implemented Interfaces:
IoFilter
A
IoFilter which blocks connections from connecting
at a rate faster than the specified interval.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface IoFilter
IoFilter.NextFilter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longThe minimal delay the sessions will have to wait before being created againThe map of created sessiosn, associated with the time they were createdprivate static final longThe default delay to wait for a session to be accepted againprivate LockA lock used to protect the map from concurrent modificationsprivate static final org.slf4j.LoggerA logger for this class -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ConnectionThrottleFilter(long allowedInterval) Constructor that takes in a specified wait time. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanisConnectionOk(IoSession session) Method responsible for deciding if a connection is OK to continuevoidsessionCreated(IoFilter.NextFilter nextFilter, IoSession session) FiltersIoHandler.sessionCreated(IoSession)event.voidsetAllowedInterval(long allowedInterval) Sets the interval between connections from a client.Methods inherited from class IoFilterAdapter
destroy, event, exceptionCaught, filterClose, filterWrite, init, inputClosed, messageReceived, messageSent, onPostAdd, onPostRemove, onPreAdd, onPreRemove, sessionClosed, sessionIdle, sessionOpened, toString
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGERA logger for this class -
DEFAULT_TIME
private static final long DEFAULT_TIMEThe default delay to wait for a session to be accepted again- See Also:
-
allowedInterval
private long allowedIntervalThe minimal delay the sessions will have to wait before being created again -
clients
-
lock
A lock used to protect the map from concurrent modifications
-
-
Constructor Details
-
ConnectionThrottleFilter
public ConnectionThrottleFilter()Default constructor. Sets the wait time to 1 second -
ConnectionThrottleFilter
public ConnectionThrottleFilter(long allowedInterval) Constructor that takes in a specified wait time.- Parameters:
allowedInterval- The number of milliseconds a client is allowed to wait before making another successful connection
-
-
Method Details
-
setAllowedInterval
public void setAllowedInterval(long allowedInterval) Sets the interval between connections from a client. This value is measured in milliseconds.- Parameters:
allowedInterval- The number of milliseconds a client is allowed to wait before making another successful connection
-
isConnectionOk
Method responsible for deciding if a connection is OK to continue- Parameters:
session- The new session that will be verified- Returns:
- True if the session meets the criteria, otherwise false
-
sessionCreated
Description copied from class:IoFilterAdapterFiltersIoHandler.sessionCreated(IoSession)event.- Specified by:
sessionCreatedin interfaceIoFilter- Overrides:
sessionCreatedin classIoFilterAdapter- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-