Class AbstractRemoteAddressFilter<T extends SocketAddress>
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.ipfilter.AbstractRemoteAddressFilter<T>
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
- Direct Known Subclasses:
IpSubnetFilter, RuleBasedIpFilter, UniqueIpFilter
public abstract class AbstractRemoteAddressFilter<T extends SocketAddress>
extends ChannelInboundHandlerAdapter
This class provides the functionality to either accept or reject new
Channels
based on their IP address.
You should inherit from this class if you would like to implement your own IP-based filter. Basically you have to
implement accept(ChannelHandlerContext, SocketAddress) to decided whether you want to accept or reject
a connection from the remote address.
Furthermore overriding channelRejected(ChannelHandlerContext, SocketAddress) gives you the
flexibility to respond to rejected (denied) connections. If you do not want to send a response, just have it return
null. Take a look at RuleBasedIpFilter for details.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanaccept(ChannelHandlerContext ctx, T remoteAddress) This method is called immediately after aChannelgets registered.protected voidchannelAccepted(ChannelHandlerContext ctx, T remoteAddress) This method is called ifremoteAddressgets accepted byaccept(ChannelHandlerContext, SocketAddress).voidCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline.voidCallsChannelHandlerContext.fireChannelRegistered()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected ChannelFuturechannelRejected(ChannelHandlerContext ctx, T remoteAddress) This method is called ifremoteAddressgets rejected byaccept(ChannelHandlerContext, SocketAddress).Methods inherited from class ChannelInboundHandlerAdapter
channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
AbstractRemoteAddressFilter
public AbstractRemoteAddressFilter()
-
-
Method Details
-
channelRegistered
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelRegistered()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelRegisteredin interfaceChannelInboundHandler- Overrides:
channelRegisteredin classChannelInboundHandlerAdapter- Throws:
Exception
-
channelActive
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelActive()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelActivein interfaceChannelInboundHandler- Overrides:
channelActivein classChannelInboundHandlerAdapter- Throws:
Exception
-
accept
-
channelAccepted
This method is called ifremoteAddressgets accepted byaccept(ChannelHandlerContext, SocketAddress). You should override it if you would like to handle (e.g. respond to) accepted addresses. -
channelRejected
This method is called ifremoteAddressgets rejected byaccept(ChannelHandlerContext, SocketAddress). You should override it if you would like to handle (e.g. respond to) rejected addresses.- Returns:
- A
ChannelFutureif you perform I/O operations, so that theChannelcan be closed once it completes. Null otherwise.
-