org.glassfish.grizzly.filterchain
Interface Filter

All Known Subinterfaces:
CodecFilter<K,L>, StreamTransformerFilter
All Known Implementing Classes:
EchoFilter, FilterAdapter, IdleTimeoutFilter, LogFilter, SmartFilter, SSLFilter, TCPNIOTransportFilter, TransportFilter, UDPNIOMessageTransportFilter, UDPNIOStreamTransportFilter

public interface Filter

A Filter encapsulates a unit of processing work to be performed, whose purpose is to examine and/or modify the state of a transaction that is represented by a FilterChainContext. Individual Filter can be assembled into a FilterChain, which allows them to either complete the required processing or delegate further processing to the next Filter in the FilterChain. Filter implementations should be designed in a thread-safe manner, suitable for inclusion in multiple FilterChain that might be processed by different threads simultaneously. In general, this implies that Filter classes should not maintain state information in instance variables. Instead, state information should be maintained via suitable modifications to the attributes of the FilterChainContext that is passed to the appropriate Filter processing methods. Filter implementations typically retrieve and store state information in the FilterChainContext instance that is passed as a parameter to the appropriate Filter processing methods, using particular Attributes that can be acquired via Attribute#get(FilterChainContext) method.

Author:
Jeanfrancois Arcand, Alexey Stashok
See Also:
FilterChain, Attribute

Method Summary
 void exceptionOccurred(FilterChainContext ctx, Throwable error)
          Notification about exception, occured on the FilterChain
 int getIndex()
          Gets the Filter index.
 NextAction handleAccept(FilterChainContext ctx, NextAction nextAction)
          Execute a unit of processing work to be performed, when server channel has accepted the client connection.
 NextAction handleClose(FilterChainContext ctx, NextAction nextAction)
          Execute a unit of processing work to be performed, when connection has been closed.
 NextAction handleConnect(FilterChainContext ctx, NextAction nextAction)
          Execute a unit of processing work to be performed, when channel gets connected.
 NextAction handleRead(FilterChainContext ctx, NextAction nextAction)
          Execute a unit of processing work to be performed, when channel will become available for reading.
 NextAction handleWrite(FilterChainContext ctx, NextAction nextAction)
          Execute a unit of processing work to be performed, when channel will become available for writing.
 boolean isIndexable()
          Defines if this Filter could be indexed by a FilterChain in order to find neighbour Filters faster.
 NextAction postAccept(FilterChainContext ctx, NextAction nextAction)
          Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleAccept(com.sun.grizzly.FilterChainContext) method of this Filter instance.
 NextAction postClose(FilterChainContext ctx, NextAction nextAction)
          Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleClose(com.sun.grizzly.FilterChainContext) method of this Filter instance.
 NextAction postConnect(FilterChainContext ctx, NextAction nextAction)
          Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleConnect(com.sun.grizzly.FilterChainContext) method of this Filter instance.
 NextAction postRead(FilterChainContext ctx, NextAction nextAction)
          Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleRead(com.sun.grizzly.FilterChainContext) method of this Filter instance.
 NextAction postWrite(FilterChainContext ctx, NextAction nextAction)
          Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleWrite(com.sun.grizzly.FilterChainContext) method of this Filter instance.
 void setIndex(int index)
          Sets the Filter index.
 

Method Detail

handleRead

NextAction handleRead(FilterChainContext ctx,
                      NextAction nextAction)
                      throws IOException
Execute a unit of processing work to be performed, when channel will become available for reading. This Filter may either complete the required processing and return false, or delegate remaining processing to the next Filter in a FilterChain containing this Filter by returning true.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

postRead

NextAction postRead(FilterChainContext ctx,
                    NextAction nextAction)
                    throws IOException
Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleRead(com.sun.grizzly.FilterChainContext) method of this Filter instance.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

handleWrite

NextAction handleWrite(FilterChainContext ctx,
                       NextAction nextAction)
                       throws IOException
Execute a unit of processing work to be performed, when channel will become available for writing. This Filter may either complete the required processing and return false, or delegate remaining processing to the next Filter in a FilterChain containing this Filter by returning true.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

postWrite

NextAction postWrite(FilterChainContext ctx,
                     NextAction nextAction)
                     throws IOException
Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleWrite(com.sun.grizzly.FilterChainContext) method of this Filter instance.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

handleConnect

NextAction handleConnect(FilterChainContext ctx,
                         NextAction nextAction)
                         throws IOException
Execute a unit of processing work to be performed, when channel gets connected. This Filter may either complete the required processing and return false, or delegate remaining processing to the next Filter in a FilterChain containing this Filter by returning true.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

postConnect

NextAction postConnect(FilterChainContext ctx,
                       NextAction nextAction)
                       throws IOException
Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleConnect(com.sun.grizzly.FilterChainContext) method of this Filter instance.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

handleAccept

NextAction handleAccept(FilterChainContext ctx,
                        NextAction nextAction)
                        throws IOException
Execute a unit of processing work to be performed, when server channel has accepted the client connection. This Filter may either complete the required processing and return false, or delegate remaining processing to the next Filter in a FilterChain containing this Filter by returning true.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

postAccept

NextAction postAccept(FilterChainContext ctx,
                      NextAction nextAction)
                      throws IOException
Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleAccept(com.sun.grizzly.FilterChainContext) method of this Filter instance.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

handleClose

NextAction handleClose(FilterChainContext ctx,
                       NextAction nextAction)
                       throws IOException
Execute a unit of processing work to be performed, when connection has been closed. This Filter may either complete the required processing and return false, or delegate remaining processing to the next Filter in a FilterChain containing this Filter by returning true.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

postClose

NextAction postClose(FilterChainContext ctx,
                     NextAction nextAction)
                     throws IOException
Execute any cleanup activities, such as releasing resources that were acquired during the execution of Filter#handleClose(com.sun.grizzly.FilterChainContext) method of this Filter instance.

Parameters:
ctx - FilterChainContext
nextAction - default NextAction, which Filter could change in order to control how FilterChain will continue the execution
Returns:
NextAction instruction for FilterChain, how it should continue the execution
Throws:
{@link - java.io.IOException}
IOException

exceptionOccurred

void exceptionOccurred(FilterChainContext ctx,
                       Throwable error)
Notification about exception, occured on the FilterChain

Parameters:
ctx - event processing FilterChainContext
error - error, which occurred during FilterChain execution

isIndexable

boolean isIndexable()
Defines if this Filter could be indexed by a FilterChain in order to find neighbour Filters faster. Most of the time it's very desired for a Filters to be indexable, but there are cases, when it's not appropriate, for example if single Filter instance should be shared among several FilterChains.

Returns:
true, if this Filter is indexable, or false otherwise.

getIndex

int getIndex()
Gets the Filter index.

Returns:
the Filter index.

setIndex

void setIndex(int index)
Sets the Filter index.

Parameters:
index - the Filter index.


Copyright © 2009 SUN Microsystems. All Rights Reserved.