## com.sun.grizzly.filter
Class ReadFilter

    java.lang.Object
      com.sun.grizzly.filter.ReadFilter

All Implemented Interfaces:
  ProtocolFilter

Direct Known Subclasses:
  ParserProtocolFilter, UDPReadFilter

    public class ReadFilter

extends Object
implements ProtocolFilter

Simple `ProtocolFilter` implementation which read the available bytes and delegate the processing to the next `ProtocolFilter` in the `ProtocolChain`. If no bytes are available, no new `ProtocolFilter` will be a invoked and the connection (SelectionKey) will be cancelled. This filter can be used for both UDP (reveive) and TCP (read). Note that all ready OP_WRITE operations will be ignored.

Author:
  Jeanfrancois Arcand

Field Summary
`protected boolean` `continousExecution` `true` if a pipelined execution is required.
`static String` `UDP_SOCKETADDRESS`

Fields inherited from interface com.sun.grizzly.ProtocolFilter
`SUCCESSFUL_READ`

Constructor Summary
`ReadFilter()`

Method Summary
`boolean` `execute(Context ctx)` Read available bytes and delegate the processing of them to the next `ProtocolFilter` in the `ProtocolChain`.
`protected boolean` `execute(Context ctx, ByteBuffer byteBuffer)` Read available bytes to the specific `ByteBuffer` and delegate the processing of them to the next ProtocolFilter in the ProtocolChain.
`boolean` `isContinuousExecution()` Return `true` if the current `Pipeline` can re-execute its ProtocolFilter after a successful execution.
`protected void` `log(String msg, Throwable t)` Log a message/exception.
`boolean` `postExecute(Context ctx)` If no bytes were available, close the connection by cancelling the SelectionKey.
`void` `setContinuousExecution(boolean continousExecution)` Set to `true` if the current `Pipeline` can re-execute its ProtocolFilter(s) after a successful execution.

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

Field Detail

### UDP_SOCKETADDRESS

    public static final String UDP_SOCKETADDRESS

See Also:
  Constant Field Values

### 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

### ReadFilter

    public ReadFilter()

Method Detail

### execute

    public boolean execute(Context ctx)
                    throws IOException

  Read available bytes and delegate the processing of them to the next `ProtocolFilter` in the `ProtocolChain`.

  Specified by:
    `execute` in interface `ProtocolFilter`
  Parameters:
    `ctx` - `Context`
  Returns:
    `true` if the next ProtocolFilter on the ProtocolChain need to bve invoked.
  Throws:
    `IOException`

### execute

    protected boolean execute(Context ctx,
                              ByteBuffer byteBuffer)
                       throws IOException

  Read available bytes to the specific `ByteBuffer` and delegate the processing of them to the next ProtocolFilter in the ProtocolChain.

  Returns:
    `true` if the next ProtocolFilter on the ProtocolChain need to bve invoked.
  Throws:
    `IOException`

### postExecute

    public boolean postExecute(Context ctx)
                        throws IOException

  If no bytes were available, close the connection by cancelling the SelectionKey. If bytes were available, register the SelectionKey for new bytes.

  Specified by:
    `postExecute` in interface `ProtocolFilter`
  Parameters:
    `ctx` - `Context`
  Returns:
    `true` if the previous ProtocolFilter postExecute method needs to be invoked.
  Throws:
    `IOException`

### 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.

### log

    protected void log(String msg,
                       Throwable t)

  Log a message/exception.

  Parameters:
    `msg` - `String`
    `t` - `Throwable`

Copyright © 2008 SUN Microsystems. All Rights Reserved.