FileDocCategorySizeDatePackage
TaskBase.javaAPI DocGlassfish v2 API9570Fri May 04 22:37:06 BST 2007com.sun.enterprise.web.connector.grizzly

TaskBase

public abstract class TaskBase extends Object implements Task, TaskListener
Abstract implementation of a Task object.
author
Jean-Francois Arcand

Fields Summary
protected int
type
This number represent a specific implementation of a Task instance.
protected ArrayList
listeners
List of listeners
protected Pipeline
pipeline
The Pipeline object associated with this Task
protected SelectionKey
key
The SelectionKey used by this task.
protected boolean
recycle
Recycle this task
protected SelectorThread
selectorThread
The SelectorThread who created this task.
Constructors Summary
Methods Summary
public voidaddTaskListener(TaskListener task)
Add the given TaskListener to this Task.

        initListener();
        listeners.add(task);
    
public java.lang.Objectcall()
By default, do nothing when a Callable is invoked.

       return null;
    
public voidcancelTask(java.lang.String message, java.lang.String code)
Cancel the task.

param
message the HTTP message to included within the html page
param
code The http code to use. If null, automatically close the connection without sending an error page.

        SocketChannel channel = getChannel(); 

        if (code != null) {
            SelectorThread.logger().log(Level.WARNING,message);
            try {
                ByteBuffer byteBuffer = HtmlHelper.getErrorPage(message, code);
                OutputWriter.flushChannel(channel,byteBuffer);
            } catch (IOException ex){
                SelectorThread.logger().log(Level.FINE,"CancelTask failed", ex);
            }
        }
        
        if ( selectorThread.isEnableNioLogging() ){
            SelectorThread.logger().log(Level.INFO, "Cancelling SocketChannel " 
                    + getChannel());
        }
        
        if ( key != null){
            selectorThread.cancelKey(key);
        } else if ( getSocket() != null ){
            try{
                getSocket().close();
            } catch (IOException ex){
                ;
            }
        }
    
public voidclearTaskListeners()
Clean all the listeners of this Task

        if (listeners == null) return;
        listeners.clear();
    
public voidexecute()
Execute the task based on its Pipeline. If the Pipeline is null, then execute the task on using the calling thread.

        if (pipeline != null){
            pipeline.addTask(this);
        } else {
            run();
        }
    
protected voidfireTaskEvent(TaskEvent event)
Notify listeners.

        if (listeners == null) return;        
        for (int i=0; i < listeners.size(); i++){
            listeners.get(i).taskEvent(event);
        }
    
private java.nio.channels.SocketChannelgetChannel()
Return the underlying Channel, independent of the NIO mode we are using.

        if ( key == null ) {
            return getSocket().getChannel();
        } else {
            return (SocketChannel)key.channel();
        }
    
public KeepAliveStatsgetKeepAliveStats()
Gets the KeepAliveStats associated with this task.

        return (selectorThread != null?
                selectorThread.getKeepAliveStats() : null);
    
public PipelinegetPipeline()
Return the pipeline used by this object.

        return pipeline;
    
public booleangetRecycle()
Return true if this Task is recyclable.

        return recycle;
    
public org.apache.coyote.RequestGroupInfogetRequestGroupInfo()
Gets the RequestGroupInfo from this task.

        return (selectorThread != null?
                selectorThread.getRequestGroupInfo() : null);
    
public java.nio.channels.SelectionKeygetSelectionKey()
Return the SelectionKey associated with this task.

        return key;
    
public SelectorThreadgetSelectorThread()
Return the SelectorThread

        return selectorThread;
    
public java.net.SocketgetSocket()
Return the current Socket used by this instance

return
socket the current Socket used by this instance

        return null;
    
public java.util.ArrayListgetTaskListeners()
Return all listeners of this Task.

return
ArrayList containing all TaskListener instances registered with this Task

        initListener();
        return listeners;
    
public intgetType()



    // ------------------------------------------------------------------//
    
      
        return type;
    
private voidinitListener()

        if ( listeners == null ){
           listeners  = new ArrayList<TaskListener>();
        }
    
public booleanisMonitoringEnabled()
Returns true if monitoring has been enabled, false otherwise.

        return (selectorThread != null ?
                selectorThread.isMonitoringEnabled() : false);
    
public voidrecycle()
Recycle internal state.

       ;
    
public voidremoveTaskListener(TaskListener task)
Remove the given TaskListener/code> from this Task.

        if (listeners == null) return;
        listeners.remove(task);
    
public voidrun()
Some Pipeline implementation requires a instance of Runnable instance.

        try{
            doTask();
        } catch (IOException ex){
            throw new RuntimeException(ex);
        }
    
public voidsetPipeline(Pipeline pipeline)
Set the pipeline on which Worker Threads will synchronize.

        this.pipeline = pipeline;
    
public voidsetRecycle(boolean recycle)
Declare whether this Task is recyclable. If so, this Task will be recycled after every invocation of doTask().

        this.recycle = recycle;
    
public voidsetSelectionKey(java.nio.channels.SelectionKey key)
Set the SelectionKey

        this.key = key;
    
public voidsetSelectorThread(SelectorThread selectorThread)
Set the SelectorThread object.

        this.selectorThread = selectorThread;
    
public voidtaskEvent(TaskEvent event)

        // Do nothing