## com.sun.grizzly
Interface ProtocolChain

All Known Implementing Classes:
  DefaultProtocolChain

    public interface ProtocolChain

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 ProtocolFilter consists of a two methods (execute() and postExecute) which is passed a "protocol context" parameter containing the dynamic state of the computation, and whose return value is a boolean that determines whether or not processing for the current chain has been completed (false), or whether processing should be delegated to the next ProtocolFilter in the chain (true). The owning ProtocolChain must call the postExectute() method of each ProtocolFilter in a ProtocolChain in reverse order of the invocation of their execute() methods.

The following picture describe how it ProtocolFilter(s)

     -----------------------------------------------------------------------------
     - ProtocolFilter1.execute() --> ProtocolFilter2.execute() -------|          -
     -                                                                |          -
     -                                                                |          -
     -                                                                |          -
     - ProtocolFilter1.postExecute() <-- ProtocolFilter2.postExecute()|          -
     -----------------------------------------------------------------------------

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

Author:
  Jeanfrancois Arcand

Method Summary
`void` `addFilter(int pos, ProtocolFilter protocolFilter)` Insert a `ProtocolFilter` to the list at position 'pos'.
`boolean` `addFilter(ProtocolFilter protocolFilter)` Add a `ProtocolFilter` to the list.
`void` `execute(Context context)` Execute using the `Context` instance.
`boolean` `removeFilter(ProtocolFilter theFilter)` Remove the `ProtocolFilter` from this chain.

Method Detail

### addFilter

    boolean addFilter(ProtocolFilter protocolFilter)

  Add a `ProtocolFilter` to the list. `ProtocolFilter` will be invoked in the order they have been added.

  Parameters:
    `protocolFilter` - `ProtocolFilter`
  Returns:
    `ProtocolFilter` added successfully (yes/no) ?

### removeFilter

    boolean removeFilter(ProtocolFilter theFilter)

  Remove the `ProtocolFilter` from this chain.

  Parameters:
    `theFilter` - `ProtocolFilter`
  Returns:
    `ProtocolFilter` removed successfully (yes/no) ?

### addFilter

    void addFilter(int pos,
                   ProtocolFilter protocolFilter)

  Insert a `ProtocolFilter` to the list at position 'pos'.

  Parameters:
    `pos` - The insertion position
    `protocolFilter` - `ProtocolFilter`

### execute

    void execute(Context context)
                 throws Exception

  Execute using the `Context` instance.

  Parameters:
    `context` - `Context```
  Throws:
    `Exception`

Copyright © 2008 SUN Microsystems. All Rights Reserved.