- All Known Implementing Classes:
AbstractFilterChain
,DefaultFilterChain
,ListFacadeFilterChain
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.
-
Method Summary
Modifier and TypeMethodDescriptionexecute
(FilterChainContext context) Method processes occurredIOEvent
on thisFilterChain
.void
fail
(FilterChainContext context, Throwable failure) void
fireEventDownstream
(Connection connection, FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) void
fireEventUpstream
(Connection connection, FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) void
flush
(Connection connection, CompletionHandler<WriteResult> completionHandler) int
indexOfType
(Class<? extends Filter> filterType) obtainFilterChainContext
(Connection connection) obtainFilterChainContext
(Connection connection, int startIdx, int endIdx, int currentIdx) obtainFilterChainContext
(Connection connection, Closeable closeable) obtainFilterChainContext
(Connection connection, Closeable closeable, int startIdx, int endIdx, int currentIdx) read
(FilterChainContext context) Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
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, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
Methods inherited from interface org.glassfish.grizzly.Processor
isInterested, obtainContext, process, read, setInterested, write, write, write
-
Method Details
-
obtainFilterChainContext
-
obtainFilterChainContext
-
obtainFilterChainContext
FilterChainContext obtainFilterChainContext(Connection connection, int startIdx, int endIdx, int currentIdx) -
obtainFilterChainContext
FilterChainContext obtainFilterChainContext(Connection connection, Closeable closeable, int startIdx, int endIdx, int currentIdx) -
indexOfType
-
execute
Method processes occurredIOEvent
on thisFilterChain
.- Parameters:
context
- processing context- Returns:
ProcessorResult
-
flush
-
fireEventUpstream
void fireEventUpstream(Connection connection, FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) -
fireEventDownstream
void fireEventDownstream(Connection connection, FilterChainEvent event, CompletionHandler<FilterChainContext> completionHandler) -
read
- Throws:
IOException
-
fail
-