com.sun.grizzly.http
Class TaskBase

java.lang.Object
  extended by com.sun.grizzly.http.TaskBase
All Implemented Interfaces:
Task, TaskListener, Runnable, Callable
Direct Known Subclasses:
AsyncProcessorTask, CometTask, DefaultProcessorTask

public abstract class TaskBase
extends Object
implements Task, TaskListener

Abstract implementation of a Task object.

Author:
Jean-Francois Arcand

Field Summary
protected  SelectionKey key
          The SelectionKey used by this task.
protected  ArrayList<TaskListener> listeners
          List of listeners
protected  Pipeline pipeline
          The Pipeline object associated with this Task
protected  boolean recycle
          Recycle this task
protected  SelectorThread selectorThread
          The SelectorThread who created this task.
protected  int type
          This number represent a specific implementation of a Task instance.
 
Fields inherited from interface com.sun.grizzly.http.Task
ACCEPT_TASK, PROCESSOR_TASK, READ_TASK
 
Constructor Summary
TaskBase()
           
 
Method Summary
 void addTaskListener(TaskListener task)
          Add the given TaskListener to this Task.
 Object call()
          By default, do nothing when a Callable is invoked.
 void cancelTask(String message, String code)
          Cancel the task.
 void clearTaskListeners()
          Clean all the listeners of this Task
 void execute()
          Execute the task based on its Pipeline.
protected  void fireTaskEvent(TaskEvent<?> event)
          Notify listeners.
 KeepAliveStats getKeepAliveStats()
          Gets the KeepAliveStats associated with this task.
 Pipeline getPipeline()
          Return the pipeline used by this object.
 boolean getRecycle()
          Return true if this Task is recyclable.
 RequestGroupInfo getRequestGroupInfo()
          Gets the RequestGroupInfo from this task.
 SelectionKey getSelectionKey()
          Return the SelectionKey associated with this task.
 SelectorThread getSelectorThread()
          Return the SelectorThread
 Socket getSocket()
          Return the current Socket used by this instance
 ArrayList getTaskListeners()
          Return all listeners of this Task.
 int getType()
          Return this Tash type.
 boolean isMonitoringEnabled()
          Returns true if monitoring has been enabled, false otherwise.
 void recycle()
          Recycle internal state.
 void removeTaskListener(TaskListener task)
          Remove the given TaskListener/code> from this Task.
 void run()
          Some Pipeline implementation requires a instance of Runnable instance.
 void setPipeline(Pipeline pipeline)
          Set the pipeline on which Worker Threads will synchronize.
 void setRecycle(boolean recycle)
          Declare whether this Task is recyclable.
 void setSelectionKey(SelectionKey key)
          Set the SelectionKey
 void setSelectorThread(SelectorThread selectorThread)
          Set the SelectorThread object.
 void taskEvent(TaskEvent event)
          Base implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.grizzly.http.Task
doTask
 

Field Detail

type

protected int type
This number represent a specific implementation of a Task instance.


listeners

protected ArrayList<TaskListener> listeners
List of listeners


pipeline

protected Pipeline pipeline
The Pipeline object associated with this Task


key

protected SelectionKey key
The SelectionKey used by this task.


recycle

protected boolean recycle
Recycle this task


selectorThread

protected SelectorThread selectorThread
The SelectorThread who created this task.

Constructor Detail

TaskBase

public TaskBase()
Method Detail

getType

public int getType()
Description copied from interface: Task
Return this Tash type.

Specified by:
getType in interface Task

setSelectorThread

public void setSelectorThread(SelectorThread selectorThread)
Set the SelectorThread object.

Specified by:
setSelectorThread in interface Task

getSelectorThread

public SelectorThread getSelectorThread()
Return the SelectorThread

Specified by:
getSelectorThread in interface Task

setPipeline

public void setPipeline(Pipeline pipeline)
Set the pipeline on which Worker Threads will synchronize.

Specified by:
setPipeline in interface Task

getPipeline

public Pipeline getPipeline()
Return the pipeline used by this object.

Specified by:
getPipeline in interface Task

setSelectionKey

public void setSelectionKey(SelectionKey key)
Set the SelectionKey

Specified by:
setSelectionKey in interface Task

getSelectionKey

public SelectionKey getSelectionKey()
Return the SelectionKey associated with this task.

Specified by:
getSelectionKey in interface Task

getRequestGroupInfo

public RequestGroupInfo getRequestGroupInfo()
Gets the RequestGroupInfo from this task.

Specified by:
getRequestGroupInfo in interface Task

isMonitoringEnabled

public boolean isMonitoringEnabled()
Returns true if monitoring has been enabled, false otherwise.

Specified by:
isMonitoringEnabled in interface Task

getKeepAliveStats

public KeepAliveStats getKeepAliveStats()
Gets the KeepAliveStats associated with this task.

Specified by:
getKeepAliveStats in interface Task

execute

public void execute()
Execute the task based on its Pipeline. If the Pipeline is null, then execute the task on using the calling thread.

Specified by:
execute in interface Task

addTaskListener

public void addTaskListener(TaskListener task)
Add the given TaskListener to this Task.

Specified by:
addTaskListener in interface Task

removeTaskListener

public void removeTaskListener(TaskListener task)
Remove the given TaskListener/code> from this Task.

Specified by:
removeTaskListener in interface Task

clearTaskListeners

public void clearTaskListeners()
Clean all the listeners of this Task

Specified by:
clearTaskListeners in interface Task

fireTaskEvent

protected void fireTaskEvent(TaskEvent<?> event)
Notify listeners.


recycle

public void recycle()
Recycle internal state.

Specified by:
recycle in interface Task

getTaskListeners

public ArrayList getTaskListeners()
Return all listeners of this Task.

Specified by:
getTaskListeners in interface Task
Returns:
ArrayList containing all TaskListener instances registered with this Task

run

public void run()
Some Pipeline implementation requires a instance of Runnable instance.

Specified by:
run in interface Runnable

setRecycle

public void setRecycle(boolean recycle)
Declare whether this Task is recyclable. If so, this Task will be recycled after every invocation of doTask().

Specified by:
setRecycle in interface Task

getRecycle

public boolean getRecycle()
Return true if this Task is recyclable.

Specified by:
getRecycle in interface Task

getSocket

public Socket getSocket()
Return the current Socket used by this instance

Returns:
socket the current Socket used by this instance

cancelTask

public void cancelTask(String message,
                       String code)
Cancel the task.

Specified by:
cancelTask in interface Task
Parameters:
message - the HTTP message to included within the html page
code - The http code to use. If null, automatically close the connection without sending an error page.

call

public Object call()
            throws Exception
By default, do nothing when a Callable is invoked.

Specified by:
call in interface Callable
Throws:
Exception

taskEvent

public void taskEvent(TaskEvent event)
Base implementation.

Specified by:
taskEvent in interface TaskListener


Copyright © 2009 SUN Microsystems. All Rights Reserved.