## com.sun.grizzly
Class DefaultProtocolChain

    java.lang.Object
      com.sun.grizzly.DefaultProtocolChain

All Implemented Interfaces:
  ProtocolChain

    public class DefaultProtocolChain

extends Object
implements ProtocolChain

Default ProtocolChain implementation.

Author:
  Jeanfrancois Arcand

Nested Class Summary
`static interface` `DefaultProtocolChain.EventHandler` Interface, which introduces handler, which will be notified about event, happened on `ProtocolChain`
`static class` `DefaultProtocolChain.Phase`

Field Summary
`protected boolean` `continousExecution` `true` if a pipelined execution is required.
`protected Collection<DefaultProtocolChain.EventHandler>` `eventHandlers` The list of `DefaultProtocolChain.EventHandler`s, which will be notified about this `ProtocolChain` events
`protected List<ProtocolFilter>` `protocolFilters` The list of ProtocolFilter this chain will invoke.

Constructor Summary
`DefaultProtocolChain()`

Method Summary
`boolean` `addEventHandler(DefaultProtocolChain.EventHandler eventHandler)` Add the `DefaultProtocolChain.EventHandler`
`void` `addFilter(int pos, ProtocolFilter protocolFilter)` Insert a ProtocolFilter at position pos.
`boolean` `addFilter(ProtocolFilter protocolFilter)` Add the `ProtocolFilter` to this `ProtocolChain`
`void` `execute(Context ctx)` Execute this ProtocolChain.
`void` `execute(Context ctx, int firstFilter)` Execute this ProtocolChain.
`protected int` `executeProtocolFilter(Context ctx)` Execute the ProtocolFilter.execute method.
`protected int` `executeProtocolFilter(Context ctx, int firstFilter)` Execute the ProtocolFilter.execute method.
`boolean` `isContinuousExecution()` Return `true` if the current `Pipeline` can re-execute its ProtocolFilter after a successful execution.
`protected void` `notifyException(DefaultProtocolChain.Phase phase, ProtocolFilter filter, Throwable throwable)` Notifies all `DefaultProtocolChain.EventHandler`s about exception, which occured
`protected boolean` `postExecuteProtocolFilter(int currentPosition, Context ctx)` Execute the ProtocolFilter.postExcute.
`boolean` `removeEventHandler(DefaultProtocolChain.EventHandler eventHandler)` Remove the `DefaultProtocolChain.EventHandler`.
`boolean` `removeFilter(ProtocolFilter theFilter)` Remove a ProtocolFilter.
`void` `setContinuousExecution(boolean continousExecution)` Set to `true` if the current `Pipeline` can re-execute its ProtocolFilter(s) after a successful execution.
`ProtocolFilter` `setProtocolFilter(int pos, ProtocolFilter protocolFilter)` Insert a ProtocolFilter at position pos.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### protocolFilters

    protected List<ProtocolFilter> protocolFilters

  The list of ProtocolFilter this chain will invoke.

### eventHandlers

    protected Collection<DefaultProtocolChain.EventHandler> eventHandlers

  The list of `DefaultProtocolChain.EventHandler`s, which will be notified about this `ProtocolChain` events

### continousExecution

    protected boolean continousExecution

  `true` if a pipelined execution is required. A pipelined execution occurs when a ProtocolFilter implementation set the ProtocolFilter.READ_SUCCESS as an attribute to a Context. When this attribute is present, the ProtocolChain will not release the current running Thread and will re-execute all its ProtocolFilter.

Constructor Detail

### DefaultProtocolChain

    public DefaultProtocolChain()

Method Detail

### execute

    public void execute(Context ctx)
                 throws Exception

  Execute this ProtocolChain.

  Specified by:
    `execute` in interface `ProtocolChain`
  Parameters:
    `ctx` - `Context`
  Throws:
    `Exception`

### execute

    public void execute(Context ctx,
                        int firstFilter)
                 throws Exception

  Execute this ProtocolChain.

  Parameters:
    `ctx` - `Context`
    `firstFilter` - The first filter to be invoked.
  Throws:
    `Exception`

### executeProtocolFilter

    protected int executeProtocolFilter(Context ctx)

  Execute the ProtocolFilter.execute method. If a ProtocolFilter.execute return false, avoid invoking the next ProtocolFilter.

  Parameters:
    `ctx` - `Context`
  Returns:
    position of next `ProtocolFilter` to exexute

### executeProtocolFilter

    protected int executeProtocolFilter(Context ctx,
                                        int firstFilter)

  Execute the ProtocolFilter.execute method. If a ProtocolFilter.execute return false, avoid invoking the next ProtocolFilter.

  Parameters:
    `ctx` - `Context`
    `firstFilter` - The first filter position to be invoked.
  Returns:
    position of next `ProtocolFilter` to exexute

### postExecuteProtocolFilter

    protected boolean postExecuteProtocolFilter(int currentPosition,
                                                Context ctx)

  Execute the ProtocolFilter.postExcute.

  Parameters:
    `currentPosition` - position in list of `ProtocolFilter`s
    `ctx` - `Context`
  Returns:
    false, always false

### removeFilter

    public boolean removeFilter(ProtocolFilter theFilter)

  Remove a ProtocolFilter.

  Specified by:
    `removeFilter` in interface `ProtocolChain`
  Parameters:
    `theFilter` - the ProtocolFilter to remove
  Returns:
    removed ProtocolFilter

### addFilter

    public boolean addFilter(ProtocolFilter protocolFilter)

  Add the `ProtocolFilter` to this `ProtocolChain`

  Specified by:
    `addFilter` in interface `ProtocolChain`
  Parameters:
    `protocolFilter` - to add
  Returns:

### addFilter

    public void addFilter(int pos,
                          ProtocolFilter protocolFilter)

  Insert a ProtocolFilter at position pos.

  Specified by:
    `addFilter` in interface `ProtocolChain`
  Parameters:
    `pos` -
    `protocolFilter` -

### setProtocolFilter

    public ProtocolFilter setProtocolFilter(int pos,
                                            ProtocolFilter protocolFilter)

  Insert a ProtocolFilter at position pos.

  Parameters:
    `pos` - - position in this ProtocolChain
    `protocolFilter` - - `ProtocolFilter` to insert
  Returns:
    `ProtocolFilter` that was set

### setContinuousExecution

    public void setContinuousExecution(boolean continousExecution)

  Set to `true` if the current `Pipeline` can re-execute its ProtocolFilter(s) after a successful execution. Enabling this property is useful for protocol that needs to support pipelined message requests as the ProtocolFilter are automatically re-executed, avoiding the overhead of releasing the current Thread, registering back the SelectionKey to the SelectorHandler and waiting for a new NIO event. Some protocols (like http) can get the http headers in one SocketChannel.read, parse the message and then get the next http message on the second SocketChannel.read(). Not having to release the Thread and re-execute the ProtocolFilter greatly improve performance.

  Parameters:
    `continousExecution` - true to enable continuous execution. (default is false).

### isContinuousExecution

    public boolean isContinuousExecution()

  Return `true` if the current `Pipeline` can re-execute its ProtocolFilter after a successful execution.

### addEventHandler

    public boolean addEventHandler(DefaultProtocolChain.EventHandler eventHandler)

  Add the `DefaultProtocolChain.EventHandler`

  Parameters:
    `eventHandler` -
  Returns:
    true, if `DefaultProtocolChain.EventHandler` was added, false otherwise

### removeEventHandler

    public boolean removeEventHandler(DefaultProtocolChain.EventHandler eventHandler)

  Remove the `DefaultProtocolChain.EventHandler`.

  Parameters:
    `eventHandler` - the `ProtocolFilter`to remove``
  Returns:
    true, if `DefaultProtocolChain.EventHandler` was removed, false otherwise

### notifyException

    protected void notifyException(DefaultProtocolChain.Phase phase,
                                   ProtocolFilter filter,
                                   Throwable throwable)

  Notifies all `DefaultProtocolChain.EventHandler`s about exception, which occured

  Parameters:
    `phase` - execution `Phase`, where exception occured
    `filter` - `ProtocolFilter`, where exception occured
    `throwable` - actual exception

Copyright © 2008 SUN Microsystems. All Rights Reserved.