com.sun.grizzly.filter
Class ReadFilter

java.lang.Object
  extended by com.sun.grizzly.filter.ReadFilter
All Implemented Interfaces:
ProtocolFilter, ReinvokeAware
Direct Known Subclasses:
ParserProtocolFilter, PUReadFilter, UDPReadFilter

public class ReadFilter
extends Object
implements ProtocolFilter, ReinvokeAware

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 DELAYED_CLOSE_NOTIFICATION
           
protected  int readAttempts
           
static String UDP_SOCKETADDRESS
           
 
Fields inherited from interface com.sun.grizzly.ProtocolFilter
SUCCESSFUL_READ
 
Constructor Summary
ReadFilter()
           
 
Method Summary
protected  void checkEmptyRead(SocketChannel channel, int size)
           
 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.
 int getReadAttempts()
          Get the number of attempts the ReadFilter will try to read a data from a channel.
 boolean isContinuousExecution()
          Return true if the current ExecutorService 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 ExecutorService can re-execute its ProtocolFilter(s) after a successful execution.
 void setReadAttempts(int readAttempts)
          Set the number of attempts the ReadFilter will try to read a data from a channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DELAYED_CLOSE_NOTIFICATION

public static final String DELAYED_CLOSE_NOTIFICATION
See Also:
Constant Field Values

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.


readAttempts

protected int readAttempts
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 ExecutorService 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.

Specified by:
setContinuousExecution in interface ReinvokeAware
Parameters:
continousExecution - true to enable continuous execution. (default is false).

isContinuousExecution

public boolean isContinuousExecution()
Return true if the current ExecutorService can re-execute its ProtocolFilter after a successful execution.

Specified by:
isContinuousExecution in interface ReinvokeAware

getReadAttempts

public int getReadAttempts()
Get the number of attempts the ReadFilter will try to read a data from a channel.

Returns:
the number of attempts the ReadFilter will try to read a data from a channel.

setReadAttempts

public void setReadAttempts(int readAttempts)
Set the number of attempts the ReadFilter will try to read a data from a channel.

Parameters:
readAttempts - the number of attempts the ReadFilter will try to read a data from a channel.

log

protected void log(String msg,
                   Throwable t)
Log a message/exception.

Parameters:
msg - String
t - Throwable

checkEmptyRead

protected final void checkEmptyRead(SocketChannel channel,
                                    int size)


Copyright © 2013 Oracle Corporation. All Rights Reserved.