Class IpFilteringHandlerImpl
java.lang.Object
org.jboss.netty.handler.ipfilter.IpFilteringHandlerImpl
- All Implemented Interfaces:
ChannelHandler, ChannelUpstreamHandler, IpFilteringHandler
- Direct Known Subclasses:
IpFilterRuleHandler, OneIpFilterHandler
public abstract class IpFilteringHandlerImpl
extends Object
implements ChannelUpstreamHandler, IpFilteringHandler
General class that handle Ip Filtering.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanaccept(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress) Called when the channel is connected.protected booleanCalled in handleUpstream, if this channel was previously blocked, to check if whatever the event, it should be passed to the next entry in the pipeline.
If one wants to not block events, just overridden this method by returning always true.
Note that OPENED and BOUND events are still passed to the next entry in the pipeline since those events come out before the CONNECTED event and so the possibility to filter the connection.protected ChannelFuturehandleAllowedChannel(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress) protected ChannelFuturehandleRefusedChannel(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress) Called when the channel has the CONNECTED status and the channel was refused by a previous call to accept().voidHandles the specified upstream event.protected booleanInternal method to test if the current channel is blocked.voidRemove the filter listener.voidsetIpFilterListener(IpFilterListener listener) Sets the filter listener.
-
Field Details
-
listener
-
-
Constructor Details
-
IpFilteringHandlerImpl
public IpFilteringHandlerImpl()
-
-
Method Details
-
accept
protected abstract boolean accept(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress) throws Exception Called when the channel is connected. It returns True if the corresponding connection is to be allowed. Else it returns False.- Parameters:
inetSocketAddress- the remoteInetSocketAddressfrom client- Returns:
- True if the corresponding connection is allowed, else False.
- Throws:
Exception
-
handleRefusedChannel
protected ChannelFuture handleRefusedChannel(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress) throws Exception Called when the channel has the CONNECTED status and the channel was refused by a previous call to accept(). This method enables your implementation to send a message back to the client before closing or whatever you need. This method returns a ChannelFuture on which the implementation will wait uninterruptibly before closing the channel.
For instance, If a message is sent back, the corresponding ChannelFuture has to be returned.- Parameters:
inetSocketAddress- the remoteInetSocketAddressfrom client- Returns:
- the associated ChannelFuture to be waited for before closing the channel. Null is allowed.
- Throws:
Exception
-
handleAllowedChannel
protected ChannelFuture handleAllowedChannel(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress) throws Exception - Throws:
Exception
-
isBlocked
Internal method to test if the current channel is blocked. Should not be overridden.- Returns:
- True if the current channel is blocked, else False
-
continues
Called in handleUpstream, if this channel was previously blocked, to check if whatever the event, it should be passed to the next entry in the pipeline.
If one wants to not block events, just overridden this method by returning always true.
Note that OPENED and BOUND events are still passed to the next entry in the pipeline since those events come out before the CONNECTED event and so the possibility to filter the connection.- Returns:
- True if the event should continue, False if the event should not continue since this channel was blocked by this filter
- Throws:
Exception
-
handleUpstream
Description copied from interface:ChannelUpstreamHandlerHandles the specified upstream event.- Specified by:
handleUpstreamin interfaceChannelUpstreamHandler- Parameters:
ctx- the context object for this handlere- the upstream event to process or intercept- Throws:
Exception
-
setIpFilterListener
Description copied from interface:IpFilteringHandlerSets the filter listener.- Specified by:
setIpFilterListenerin interfaceIpFilteringHandler- Parameters:
listener- the new ip filter listener
-
removeIpFilterListener
public void removeIpFilterListener()Description copied from interface:IpFilteringHandlerRemove the filter listener.- Specified by:
removeIpFilterListenerin interfaceIpFilteringHandler
-