public abstract class AbstractRemoteAddressFilter<T extends java.net.SocketAddress> extends ChannelInboundHandlerAdapter
Channel
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 at RuleBasedIpFilter
for details.
ChannelHandler.Sharable
Constructor and Description |
---|
AbstractRemoteAddressFilter() |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
accept(ChannelHandlerContext ctx,
T remoteAddress)
This method is called immediately after a
Channel gets registered. |
protected void |
channelAccepted(ChannelHandlerContext ctx,
T remoteAddress)
This method is called if
remoteAddress gets accepted by
accept(ChannelHandlerContext, SocketAddress) . |
void |
channelActive(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelActive() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
void |
channelRegistered(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelRegistered() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
protected ChannelFuture |
channelRejected(ChannelHandlerContext ctx,
T remoteAddress)
This method is called if
remoteAddress gets rejected by
accept(ChannelHandlerContext, SocketAddress) . |
channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded, handlerRemoved
public void channelRegistered(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRegistered()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRegistered
in interface ChannelInboundHandler
channelRegistered
in class ChannelInboundHandlerAdapter
java.lang.Exception
public void channelActive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelActive()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelActive
in interface ChannelInboundHandler
channelActive
in class ChannelInboundHandlerAdapter
java.lang.Exception
protected abstract boolean accept(ChannelHandlerContext ctx, T remoteAddress) throws java.lang.Exception
Channel
gets registered.java.lang.Exception
protected void channelAccepted(ChannelHandlerContext ctx, T remoteAddress)
remoteAddress
gets accepted by
accept(ChannelHandlerContext, SocketAddress)
. You should override it if you would like to handle
(e.g. respond to) accepted addresses.protected ChannelFuture channelRejected(ChannelHandlerContext ctx, T remoteAddress)
remoteAddress
gets rejected by
accept(ChannelHandlerContext, SocketAddress)
. You should override it if you would like to handle
(e.g. respond to) rejected addresses.ChannelFuture
if you perform I/O operations, so that
the Channel
can be closed once it completes. Null otherwise.Copyright © 2008–2018 The Netty Project. All rights reserved.