FileDocCategorySizeDatePackage
AsyncProcessorTask.javaAPI DocGlassfish v2 API6584Fri May 04 22:37:06 BST 2007com.sun.enterprise.web.connector.grizzly.async

AsyncProcessorTask

public class AsyncProcessorTask extends com.sun.enterprise.web.connector.grizzly.TaskBase implements com.sun.enterprise.web.connector.grizzly.AsyncTask
A Task that wraps the execution of an asynchronous execution of a ProcessorTask. Internaly, this class invoke the associated AsyncExecutor method to execute the ProcessorTask lifecycle operations.
author
Jeanfrancois Arcand

Fields Summary
private com.sun.enterprise.web.connector.grizzly.AsyncExecutor
asyncExecutor
The AsyncExecutor which drive the execution of the ProcesssorTask
private com.sun.enterprise.web.connector.grizzly.ProcessorTask
processorTask
The ProcessorTask
private int
stage
The current execution stage.
Constructors Summary
Methods Summary
public voiddoTask()
Execute the AsyncExecutor based on the stage of the ProcessorTask execution.

    
    
                    
         
        boolean contineExecution = true;
        while ( contineExecution ) {
            try{
                switch(stage){
                    case AsyncTask.PRE_EXECUTE:
                       stage = AsyncTask.INTERRUPTED;                       
                       contineExecution = asyncExecutor.preExecute();
                       break;                
                    case AsyncTask.INTERRUPTED:
                       stage = AsyncTask.POST_EXECUTE;                        
                       contineExecution = asyncExecutor.interrupt();
                       break;  
                    case AsyncTask.EXECUTE:    
                       contineExecution = asyncExecutor.execute();
                       stage = AsyncTask.POST_EXECUTE;
                       break;                           
                    case AsyncTask.POST_EXECUTE:    
                       contineExecution = asyncExecutor.postExecute();
                       stage = AsyncTask.COMPLETED;
                       break;                
                }
            } catch (Throwable t){
                SelectorThread.logger().log(Level.SEVERE,t.getMessage(),t);
                if ( stage <= AsyncTask.INTERRUPTED) {
                    // We must close the connection.
                    stage = AsyncTask.POST_EXECUTE;
                } else {
                    stage = AsyncTask.COMPLETED;
                    throw new RuntimeException(t);
                }
            } finally {
                // If the execution is completed, return this task to the pool.
                if ( stage == AsyncTask.COMPLETED){
                    stage = AsyncTask.PRE_EXECUTE;
                    asyncExecutor.getAsyncHandler().returnTask(this);
                }
            }
        } 
    
public com.sun.enterprise.web.connector.grizzly.AsyncExecutorgetAsyncExecutor()
Get the AsyncExecutor.

        return asyncExecutor;
    
public com.sun.enterprise.web.connector.grizzly.ProcessorTaskgetProcessorTask()
Return the ProcessorTask.

        return processorTask;
    
public intgetStage()
Return the stage of the current execution.

        return stage;
    
public voidrecycle()
Reset the object.

        stage = AsyncTask.PRE_EXECUTE;
        processorTask = null;
    
public voidsetAsyncExecutor(com.sun.enterprise.web.connector.grizzly.AsyncExecutor asyncExecutor)
Set the AsyncExecutor used by this Task to delegate the execution of a ProcessorTask.

        this.asyncExecutor = asyncExecutor;
    
public voidsetProcessorTask(com.sun.enterprise.web.connector.grizzly.ProcessorTask processorTask)
Set the ProcessorTask that needs to be executed asynchronously.

        this.processorTask = processorTask;
        if ( pipeline == null && processorTask != null) {
            setPipeline(processorTask.getPipeline());
        }        
    
public voidsetStage(int stage)

        this.stage = stage;
    
public voidtaskEvent(com.sun.enterprise.web.connector.grizzly.TaskEvent event)
Not used.