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 java.lang.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 Modifier and Type Field Description private IpFilterListener
listener
-
Constructor Summary
Constructors Constructor Description IpFilteringHandlerImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
accept(ChannelHandlerContext ctx, ChannelEvent e, java.net.InetSocketAddress inetSocketAddress)
Called when the channel is connected.protected boolean
continues(ChannelHandlerContext ctx, ChannelEvent e)
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, java.net.InetSocketAddress inetSocketAddress)
protected ChannelFuture
handleRefusedChannel(ChannelHandlerContext ctx, ChannelEvent e, java.net.InetSocketAddress inetSocketAddress)
Called when the channel has the CONNECTED status and the channel was refused by a previous call to accept().void
handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
Handles the specified upstream event.protected boolean
isBlocked(ChannelHandlerContext ctx)
Internal method to test if the current channel is blocked.void
removeIpFilterListener()
Remove the filter listener.void
setIpFilterListener(IpFilterListener listener)
Sets the filter listener.
-
-
-
Field Detail
-
listener
private IpFilterListener listener
-
-
Method Detail
-
accept
protected abstract boolean accept(ChannelHandlerContext ctx, ChannelEvent e, java.net.InetSocketAddress inetSocketAddress) throws java.lang.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:
java.lang.Exception
-
handleRefusedChannel
protected ChannelFuture handleRefusedChannel(ChannelHandlerContext ctx, ChannelEvent e, java.net.InetSocketAddress inetSocketAddress) throws java.lang.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:
java.lang.Exception
-
handleAllowedChannel
protected ChannelFuture handleAllowedChannel(ChannelHandlerContext ctx, ChannelEvent e, java.net.InetSocketAddress inetSocketAddress) throws java.lang.Exception
- Throws:
java.lang.Exception
-
isBlocked
protected boolean isBlocked(ChannelHandlerContext ctx)
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
protected boolean continues(ChannelHandlerContext ctx, ChannelEvent e) throws java.lang.Exception
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:
java.lang.Exception
-
handleUpstream
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws java.lang.Exception
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:
java.lang.Exception
-
setIpFilterListener
public void setIpFilterListener(IpFilterListener listener)
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
-
-