Top Description Methods
org.glassfish.grizzly.filterchain

public Interface FilterChain

extends Processor<Context>, List<Filter>
Known Direct Implementers
org.glassfish.grizzly.filterchain.AbstractFilterChain
Imports
java.io.IOException, java.util.List, org.glassfish.grizzly.Closeable, .Codec, .CompletionHandler, .Connection, .Context, .IOEvent, .Processor, .ProcessorResult, .ReadResult, .WriteResult

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.

Authors
Jeanfrancois Arcand, Alexey Stashok
See Also
Filter, Codec

Method Summary

Modifier and TypeMethod and Description
public ProcessorResult
execute(FilterChainContext
processing context
context
)

Method processes occurred IOEvent on this FilterChain.

public void
fail(FilterChainContext context, Throwable failure)

public void
public void
public void
flush(Connection<L> connection, CompletionHandler<WriteResult<K, L>> completionHandler)

public int

Returns:

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

Get the index of Filter in chain, which type is filterType, or -1 if the Filter of required type was not found.

public FilterChainContext
public FilterChainContext
obtainFilterChainContext(Connection<L> connection, Closeable closeable)

public FilterChainContext
obtainFilterChainContext(Connection<L> connection, int startIdx, int endIdx, int currentIdx)

public FilterChainContext
obtainFilterChainContext(Connection<L> connection, Closeable closeable, int startIdx, int endIdx, int currentIdx)

public ReadResult<K, L>
Inherited from java.util.List:
addaddaddAlladdAlladdFirstaddLastclearcontainscontainsAllcopyOfequalsgetgetFirstgetLasthashCodeindexOfisEmptyiteratorlastIndexOflistIteratorlistIteratorofofofofofofofofofofofofofLazyremoveremoveremoveAllremoveFirstremoveLastreplaceAllretainAllreversedsetsizesortspliteratorsubListtoArraytoArray
Inherited from org.glassfish.grizzly.Processor:
isInterestedobtainContextprocessreadsetInterestedwritewritewrite

Method Detail

executeback to summary
public ProcessorResult execute(FilterChainContext context)

Method processes occurred IOEvent on this FilterChain.

Parameters
context:FilterChainContext

processing context

Returns:ProcessorResult

ProcessorResult

failback to summary
public void fail(FilterChainContext context, Throwable failure)
fireEventDownstreamback to summary
public void fireEventDownstream(Connection<L> connection, FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler)
fireEventUpstreamback to summary
public void fireEventUpstream(Connection<L> connection, FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler)
flushback to summary
public void flush(Connection<L> connection, CompletionHandler<WriteResult<K, L>> completionHandler)
indexOfTypeback to summary
public int indexOfType(final 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:Class<? extends Filter>

the type of Filter to search.

Returns:int

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

obtainFilterChainContextback to summary
public FilterChainContext obtainFilterChainContext(Connection<L> connection)
obtainFilterChainContextback to summary
public FilterChainContext obtainFilterChainContext(Connection<L> connection, Closeable closeable)
obtainFilterChainContextback to summary
public FilterChainContext obtainFilterChainContext(Connection<L> connection, int startIdx, int endIdx, int currentIdx)
obtainFilterChainContextback to summary
public FilterChainContext obtainFilterChainContext(Connection<L> connection, Closeable closeable, int startIdx, int endIdx, int currentIdx)
readback to summary
public ReadResult<K, L> read(FilterChainContext context) throws IOException