@ChannelHandler.Sharable public class IpSubnetFilter extends AbstractRemoteAddressFilter<InetSocketAddress>
This class allows one to filter new Channel
s based on the
IpSubnetFilter
s passed to its constructor. If no rules are provided, all connections
will be accepted since acceptIfNotFound
is true
by default.
If you would like to explicitly take action on rejected Channel
s, you should override
AbstractRemoteAddressFilter.channelRejected(ChannelHandlerContext, SocketAddress)
.
Few Points to keep in mind:
IpSubnetFilter
uses Binary search algorithm, it's a good
idea to insert IP addresses in incremental order. ChannelHandler.Sharable
Constructor and Description |
---|
IpSubnetFilter(boolean acceptIfNotFound,
IpSubnetFilterRule... rules)
Create new
IpSubnetFilter Instance with specified IpSubnetFilterRule as array
and specify if we'll accept a connection if we don't find it in the rule(s). |
IpSubnetFilter(boolean acceptIfNotFound,
List<IpSubnetFilterRule> rules)
Create new
IpSubnetFilter Instance with specified IpSubnetFilterRule as List
and specify if we'll accept a connection if we don't find it in the rule(s). |
IpSubnetFilter(IpSubnetFilterRule... rules)
Create new
IpSubnetFilter Instance with specified IpSubnetFilterRule as array. |
IpSubnetFilter(List<IpSubnetFilterRule> rules)
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
accept(ChannelHandlerContext ctx,
InetSocketAddress remoteAddress)
This method is called immediately after a
Channel gets registered. |
channelAccepted, channelActive, channelRegistered, channelRejected
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 IpSubnetFilter(IpSubnetFilterRule... rules)
Create new IpSubnetFilter
Instance with specified IpSubnetFilterRule
as array.
acceptIfNotFound
is set to true
.
rules
- IpSubnetFilterRule
as an arraypublic IpSubnetFilter(boolean acceptIfNotFound, IpSubnetFilterRule... rules)
Create new IpSubnetFilter
Instance with specified IpSubnetFilterRule
as array
and specify if we'll accept a connection if we don't find it in the rule(s).
acceptIfNotFound
- true
if we'll accept connection if not found in rule(s).rules
- IpSubnetFilterRule
as an arraypublic IpSubnetFilter(List<IpSubnetFilterRule> rules)
Create new IpSubnetFilter
Instance with specified IpSubnetFilterRule
as List
.
acceptIfNotFound
is set to true
.
rules
- IpSubnetFilterRule
as a List
public IpSubnetFilter(boolean acceptIfNotFound, List<IpSubnetFilterRule> rules)
Create new IpSubnetFilter
Instance with specified IpSubnetFilterRule
as List
and specify if we'll accept a connection if we don't find it in the rule(s).
acceptIfNotFound
- true
if we'll accept connection if not found in rule(s).rules
- IpSubnetFilterRule
as a List
protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress)
AbstractRemoteAddressFilter
Channel
gets registered.accept
in class AbstractRemoteAddressFilter<InetSocketAddress>
Copyright © 2008–2024 The Netty Project. All rights reserved.