Package org.jboss.netty.handler.ipfilter
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 org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
accept
(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress) Called when the channel is connected.protected boolean
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.protected ChannelFuture
handleAllowedChannel
(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress) protected ChannelFuture
handleRefusedChannel
(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().void
Handles the specified upstream event.protected boolean
Internal method to test if the current channel is blocked.void
Remove the filter listener.void
setIpFilterListener
(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 remoteInetSocketAddress
from 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 remoteInetSocketAddress
from 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:ChannelUpstreamHandler
Handles the specified upstream event.- Specified by:
handleUpstream
in interfaceChannelUpstreamHandler
- Parameters:
ctx
- the context object for this handlere
- the upstream event to process or intercept- Throws:
Exception
-
setIpFilterListener
Description copied from interface:IpFilteringHandler
Sets the filter listener.- Specified by:
setIpFilterListener
in interfaceIpFilteringHandler
- Parameters:
listener
- the new ip filter listener
-
removeIpFilterListener
public void removeIpFilterListener()Description copied from interface:IpFilteringHandler
Remove the filter listener.- Specified by:
removeIpFilterListener
in interfaceIpFilteringHandler
-