Module io.netty5.handler
Package io.netty5.handler.ipfilter
Class AbstractRemoteAddressFilter<T extends SocketAddress>
- java.lang.Object
-
- io.netty5.handler.ipfilter.AbstractRemoteAddressFilter<T>
-
- All Implemented Interfaces:
ChannelHandler
- Direct Known Subclasses:
IpSubnetFilter,RuleBasedIpFilter,UniqueIpFilter
public abstract class AbstractRemoteAddressFilter<T extends SocketAddress> extends Object implements ChannelHandler
This class provides the functionality to either accept or reject newChannels 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 atRuleBasedIpFilterfor details.
-
-
Constructor Summary
Constructors Constructor Description AbstractRemoteAddressFilter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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).voidchannelActive(ChannelHandlerContext ctx)TheChannelof theChannelHandlerContextis now activevoidchannelRegistered(ChannelHandlerContext ctx)protected Future<Void>channelRejected(ChannelHandlerContext ctx, T remoteAddress)This method is called ifremoteAddressgets rejected byaccept(ChannelHandlerContext, SocketAddress).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Method Detail
-
channelRegistered
public void channelRegistered(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler- Specified by:
channelRegisteredin interfaceChannelHandler- Throws:
Exception
-
channelActive
public void channelActive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextis now active- Specified by:
channelActivein interfaceChannelHandler- Throws:
Exception
-
accept
protected abstract boolean accept(ChannelHandlerContext ctx, T remoteAddress) throws Exception
This method is called immediately after aChannelgets registered.- Returns:
- Return true if connections from this IP address and port should be accepted. False otherwise.
- Throws:
Exception
-
channelAccepted
protected void channelAccepted(ChannelHandlerContext ctx, T remoteAddress)
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
protected Future<Void> channelRejected(ChannelHandlerContext ctx, T remoteAddress)
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.
-
-