com.sun.grizzly.comet
Class CometTask

java.lang.Object
  extended by com.sun.grizzly.util.SelectionKeyAttachment
      extended by com.sun.grizzly.util.SelectedKeyAttachmentLogic
          extended by com.sun.grizzly.comet.CometTask
All Implemented Interfaces:
java.lang.Runnable

public class CometTask
extends SelectedKeyAttachmentLogic
implements java.lang.Runnable

A Task implementation that allow Grizzly ARP to invokeCometHandler CometHandler when new data (bytes) are available from the CometSelector.

Author:
Jeanfrancois Arcand, Gustav Trede

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.grizzly.util.SelectionKeyAttachment
SelectionKeyAttachment.KeySelectionListener, SelectionKeyAttachment.TimeOutListener
 
Field Summary
protected  AsyncProcessorTask asyncProcessorTask
          The AsyncProcessorTask
protected  boolean callInterrupt
          true if run() should call comet context.interrupt0
protected  CometContext cometContext
          The CometContext associated with this instance.
protected  CometHandler cometHandler
          The CometHandler associated with this task.
protected  boolean cometHandlerIsAsyncRegistered
          true if comet handler is registered for async IO in comet context.
protected  java.io.InputStream inputStream
          The InputStream
protected  boolean isDetectConnectionClose
          true, if we want to enable mechanism, which detects closed connections, or false otherwise.
protected  boolean upcoming_op_isread
          The current non blocking operation.
 
Fields inherited from class com.sun.grizzly.util.SelectionKeyAttachment
DEREGISTERED, idleTimeoutDelay, keySelectionListener, timeout, timeoutListener, UNLIMITED_TIMEOUT, UNSET_TIMEOUT
 
Constructor Summary
CometTask(CometContext cometContext, CometHandler cometHandler)
          New CometTask.
CometTask(CometContext cometContext, CometHandler cometHandler, boolean isDetectConnectionClose)
          New CometTask.
 
Method Summary
 void doTask()
          Notify the CometHandler that bytes are available for read.
 AsyncProcessorTask getAsyncProcessorTask()
          returns the AsyncProcessorTask
 CometContext getCometContext()
          Return the CometContext associated with this instance.
 CometHandler getCometHandler()
          returns the CometHandler
 long getIdleTimeoutDelay()
          
 java.nio.channels.SelectionKey getSelectionKey()
          returns selection key
 boolean handleSelectedKey(java.nio.channels.SelectionKey selectionKey)
          
 boolean isComethandlerAsyncRegistered()
          returns true if the comet handler is registered for async io
 boolean isDetectConnectionClose()
          Returns true if connection terminate detection is on.
 void release(java.nio.channels.SelectionKey selectionKey)
          This should never be called for for comet, due to we are nulling the attachment and completely overriding the selector.select logic.
called by grizzly when the selection key is canceled and its socket closed.
 void run()
          Performs doTask() or cometContext.interrupt0
 void setAsyncProcessorTask(AsyncProcessorTask asyncProcessorTask)
          sets the AsyncProcessorTask
 void setComethandlerIsAsyncRegistered(boolean cometHandlerIsAsyncRegistered)
          sets the comet task async interest flag in the comet task
 boolean timedOut(java.nio.channels.SelectionKey key)
          
 
Methods inherited from class com.sun.grizzly.util.SelectionKeyAttachment
getAttachment, getKeySelectionListener, getTimeout, getTimeoutListener, setIdleTimeoutDelay, setKeySelectionListener, setTimeout, setTimeoutListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cometContext

protected final CometContext cometContext
The CometContext associated with this instance.


cometHandler

protected final CometHandler cometHandler
The CometHandler associated with this task.


asyncProcessorTask

protected AsyncProcessorTask asyncProcessorTask
The AsyncProcessorTask


inputStream

protected java.io.InputStream inputStream
The InputStream


cometHandlerIsAsyncRegistered

protected volatile boolean cometHandlerIsAsyncRegistered
true if comet handler is registered for async IO in comet context. used to optimize: don't give simple read == -1 operations to thread pool


upcoming_op_isread

protected boolean upcoming_op_isread
The current non blocking operation.


callInterrupt

protected boolean callInterrupt
true if run() should call comet context.interrupt0


isDetectConnectionClose

protected final boolean isDetectConnectionClose
true, if we want to enable mechanism, which detects closed connections, or false otherwise. The mentioned mechanism should be disabled if we expect client to use HTTP pipelining.

Constructor Detail

CometTask

public CometTask(CometContext cometContext,
                 CometHandler cometHandler)
New CometTask.


CometTask

public CometTask(CometContext cometContext,
                 CometHandler cometHandler,
                 boolean isDetectConnectionClose)
New CometTask.

Method Detail

run

public void run()
Performs doTask() or cometContext.interrupt0

Specified by:
run in interface java.lang.Runnable

getIdleTimeoutDelay

public long getIdleTimeoutDelay()

Overrides:
getIdleTimeoutDelay in class SelectionKeyAttachment

release

public void release(java.nio.channels.SelectionKey selectionKey)
This should never be called for for comet, due to we are nulling the attachment and completely overriding the selector.select logic.
called by grizzly when the selection key is canceled and its socket closed.

Overrides:
release in class SelectionKeyAttachment
Parameters:
selectionKey -

timedOut

public boolean timedOut(java.nio.channels.SelectionKey key)

Overrides:
timedOut in class SelectionKeyAttachment

handleSelectedKey

public boolean handleSelectedKey(java.nio.channels.SelectionKey selectionKey)

Overrides:
handleSelectedKey in class SelectionKeyAttachment

doTask

public void doTask()
            throws java.io.IOException
Notify the CometHandler that bytes are available for read. The notification will invoke all CometContext

Throws:
java.io.IOException

setComethandlerIsAsyncRegistered

public void setComethandlerIsAsyncRegistered(boolean cometHandlerIsAsyncRegistered)
sets the comet task async interest flag in the comet task

Parameters:
-

isComethandlerAsyncRegistered

public boolean isComethandlerAsyncRegistered()
returns true if the comet handler is registered for async io

Returns:

getCometContext

public CometContext getCometContext()
Return the CometContext associated with this instance.

Returns:
CometContext the CometContext associated with this instance.

getAsyncProcessorTask

public AsyncProcessorTask getAsyncProcessorTask()
returns the AsyncProcessorTask

Returns:

setAsyncProcessorTask

public void setAsyncProcessorTask(AsyncProcessorTask asyncProcessorTask)
sets the AsyncProcessorTask

Parameters:
{@link - AsyncProcessorTask }

getSelectionKey

public java.nio.channels.SelectionKey getSelectionKey()
returns selection key

Returns:

getCometHandler

public CometHandler getCometHandler()
returns the CometHandler

Returns:
CometHandler

isDetectConnectionClose

public boolean isDetectConnectionClose()
Returns true if connection terminate detection is on. If this feature is on - HTTP pipelining can not be used.



Copyright © 2013 Oracle Corporation. All Rights Reserved.