Package io.netty.handler.ipfilter
Class AbstractRemoteAddressFilter<T extends java.net.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 java.net.SocketAddress> extends ChannelInboundHandlerAdapter
This class provides the functionality to either accept or reject newChannel
s 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 atRuleBasedIpFilter
for details.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description AbstractRemoteAddressFilter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
accept(ChannelHandlerContext ctx, T remoteAddress)
This method is called immediately after aChannel
gets registered.protected void
channelAccepted(ChannelHandlerContext ctx, T remoteAddress)
This method is called ifremoteAddress
gets accepted byaccept(ChannelHandlerContext, SocketAddress)
.void
channelActive(ChannelHandlerContext ctx)
CallsChannelHandlerContext.fireChannelActive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
channelRegistered(ChannelHandlerContext ctx)
CallsChannelHandlerContext.fireChannelRegistered()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.protected ChannelFuture
channelRejected(ChannelHandlerContext ctx, T remoteAddress)
This method is called ifremoteAddress
gets rejected byaccept(ChannelHandlerContext, SocketAddress)
.-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
-
-
-
Method Detail
-
channelRegistered
public void channelRegistered(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRegistered()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRegistered
in interfaceChannelInboundHandler
- Overrides:
channelRegistered
in classChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
channelActive
public void channelActive(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelActive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelActive
in interfaceChannelInboundHandler
- Overrides:
channelActive
in classChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
accept
protected abstract boolean accept(ChannelHandlerContext ctx, T remoteAddress) throws java.lang.Exception
This method is called immediately after aChannel
gets registered.- Returns:
- Return true if connections from this IP address and port should be accepted. False otherwise.
- Throws:
java.lang.Exception
-
channelAccepted
protected void channelAccepted(ChannelHandlerContext ctx, T remoteAddress)
This method is called ifremoteAddress
gets accepted byaccept(ChannelHandlerContext, SocketAddress)
. You should override it if you would like to handle (e.g. respond to) accepted addresses.
-
channelRejected
protected ChannelFuture channelRejected(ChannelHandlerContext ctx, T remoteAddress)
This method is called ifremoteAddress
gets rejected byaccept(ChannelHandlerContext, SocketAddress)
. You should override it if you would like to handle (e.g. respond to) rejected addresses.- Returns:
- A
ChannelFuture
if you perform I/O operations, so that theChannel
can be closed once it completes. Null otherwise.
-
-