org.glassfish.grizzly.filterchain
Interface FilterChain

All Superinterfaces:
java.util.Collection<Filter>, java.lang.Iterable<Filter>, java.util.List<Filter>, Processor
All Known Implementing Classes:
AbstractFilterChain, DefaultFilterChain, ListFacadeFilterChain

public interface FilterChain
extends Processor, java.util.List<Filter>

This class implement the "Chain of Responsibility" pattern (for more info, take a look at the classic "Gang of Four" design patterns book). Towards that end, the Chain API models a computation as a series of "protocol filter" that can be combined into a "protocol chain".

The API for Filter consists of a two set of methods (handleXXX() and postXXX) which is passed a "protocol context" parameter containing the dynamic state of the computation, and whose return value is a NextAction that instructs FilterChain, how it should continue processing. The owning ProtocolChain must call the postXXX() method of each Filter in a FilterChain in reverse order of the invocation of their handleXXX() methods.

The following picture describe how it Filter(s)


 -----------------------------------------------------------------------------
 - Filter1.handleXXX() --> Filter2.handleXXX()                    |          -
 -                                                                |          -
 -                                                                |          -
 -                                                                |          -
 - Filter1.postXXX() <-- Filter2.postXXX()                        |          -
 -----------------------------------------------------------------------------
 

The "context" abstraction is designed to isolate Filter implementations from the environment in which they are run (such as a Filter that can be used in either IIOP or HTTP parsing, without being tied directly to the API contracts of either of these environments). For Filter that need to allocate resources prior to delegation, and then release them upon return (even if a delegated-to Filter throws an exception), the "postXXX" method can be used for cleanup.

Author:
Jeanfrancois Arcand, Alexey Stashok
See Also:
Filter, Codec

Method Summary
 ProcessorResult execute(FilterChainContext context)
          Method processes occurred IOEvent on this FilterChain.
 void fail(FilterChainContext context, java.lang.Throwable failure)
           
 GrizzlyFuture<FilterChainContext> fireEventDownstream(Connection connection, FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler)
           
 GrizzlyFuture<FilterChainContext> fireEventUpstream(Connection connection, FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler)
           
<M> GrizzlyFuture<WriteResult>
flush(Connection connection, CompletionHandler<WriteResult> completionHandler)
           
 int indexOfType(java.lang.Class<? extends Filter> filterType)
          Get the index of Filter in chain, which type is filterType, or -1 if the Filter of required type was not found.
 FilterChainContext obtainFilterChainContext(Connection connection)
           
 ReadResult read(FilterChainContext context)
           
 
Methods inherited from interface org.glassfish.grizzly.Processor
isInterested, obtainContext, process, read, setInterested, write
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, set, size, subList, toArray, toArray
 

Method Detail

obtainFilterChainContext

FilterChainContext obtainFilterChainContext(Connection connection)

indexOfType

int indexOfType(java.lang.Class<? extends Filter> filterType)
Get the index of Filter in chain, which type is filterType, or -1 if the Filter of required type was not found.

Parameters:
filterType - the type of Filter to search.
Returns:
the index of Filter in chain, which type is filterType, or -1 if the Filter of required type was not found.

execute

ProcessorResult execute(FilterChainContext context)
                        throws java.io.IOException
Method processes occurred IOEvent on this FilterChain.

Parameters:
context - processing context
Returns:
ProcessorResult
Throws:
java.io.IOException

flush

<M> GrizzlyFuture<WriteResult> flush(Connection connection,
                                     CompletionHandler<WriteResult> completionHandler)
                                 throws java.io.IOException
Throws:
java.io.IOException

fireEventUpstream

GrizzlyFuture<FilterChainContext> fireEventUpstream(Connection connection,
                                                    FilterChainEvent event,
                                                    CompletionHandler<FilterChainContext> completionHandler)
                                                    throws java.io.IOException
Throws:
java.io.IOException

fireEventDownstream

GrizzlyFuture<FilterChainContext> fireEventDownstream(Connection connection,
                                                      FilterChainEvent event,
                                                      CompletionHandler<FilterChainContext> completionHandler)
                                                      throws java.io.IOException
Throws:
java.io.IOException

read

ReadResult read(FilterChainContext context)
                throws java.io.IOException
Throws:
java.io.IOException

fail

void fail(FilterChainContext context,
          java.lang.Throwable failure)


Copyright © 2011 Oracle Corpration. All Rights Reserved.