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

DefaultAsyncExecutor

public class DefaultAsyncExecutor extends Object implements com.sun.enterprise.web.connector.grizzly.AsyncExecutor
Default implementation of the AsyncExecutor. This class will execute a ProcessorTask asynchronously, by interrupting the process based on the logic defined in its associated AsyncFilter If no AsyncFilter are defined, the ProcessorTask will not be interrupted and executed synchronously.
author
Jeanfrancois Arcand

Fields Summary
private static final String
ASYNC_FILTER
private com.sun.enterprise.web.connector.grizzly.AsyncTask
asyncProcessorTask
The AsyncTask used to wrap the ProcessorTask
private com.sun.enterprise.web.connector.grizzly.ProcessorTask
processorTask
The associated ProcessorTask
private static String[]
sharedAsyncFilters
The AsyncFilter to execute asynchronous operations on a ProcessorTask.
private ArrayList
asyncFilters
The AsyncFilter to execute asynchronous operations on a ProcessorTask.
private boolean
invokeFilter
Do we need to invoke filters?
private com.sun.enterprise.web.connector.grizzly.AsyncHandler
asyncHandler
The AsyncHandler associated with this object.
Constructors Summary
public DefaultAsyncExecutor()

        init();
    
Methods Summary
public voidaddAsyncFilter(com.sun.enterprise.web.connector.grizzly.AsyncFilter asyncFilter)
Add an AsyncFilter

        asyncFilters.add(asyncFilter);
    
public booleanexecute()
Interrupt the ProcessorTask if AsyncFilter has been defined.

return
true if the execution can continue, false if delayed.

        processorTask.invokeAdapter();
        return true;
    
public com.sun.enterprise.web.connector.grizzly.AsyncHandlergetAsyncHandler()
Get the AsyncHandler who drive the asynchronous process.

        return asyncHandler;
    
public com.sun.enterprise.web.connector.grizzly.AsyncTaskgetAsyncTask()
Return AsyncTask.

        return asyncProcessorTask;
    
private voidinit()

        if (sharedAsyncFilters != null){
            for (String filterName: sharedAsyncFilters){
                asyncFilters.add(loadInstance(filterName));
            }
        }
    
public booleaninterrupt()
Interrupt the ProcessorTask if AsyncFilter has been defined.

return
true if the execution can continue, false if delayed.

        if ( asyncFilters == null || asyncFilters.size() == 0 ) {
            execute();
            return false;
        } else {
            asyncHandler.addToInterruptedQueue(asyncProcessorTask); 
            return invokeFilters();
        }
    
private booleaninvokeFilters()
Invoke the AsyncFilter

        boolean continueExec = true;
        for (AsyncFilter asf: asyncFilters){
            continueExec = asf.doFilter(this);
            if ( !continueExec ){
                break;
            }
        }
        return continueExec;
    
protected static voidloadFilters()
Load the list of AsynchFilter.

      
        if ( System.getProperty(ASYNC_FILTER) != null){
            StringTokenizer st = new StringTokenizer(
                    System.getProperty(ASYNC_FILTER),",");
            
            sharedAsyncFilters = new String[st.countTokens()];    
            int i = 0;
            while (st.hasMoreTokens()){
                sharedAsyncFilters[i++] = st.nextToken();                
            } 
        }   
    
private static com.sun.enterprise.web.connector.grizzly.AsyncFilterloadInstance(java.lang.String property)
Instanciate a class based on a property.

        
        Class className = null;                               
        try{                              
            className = Class.forName(property);
            return (AsyncFilter)className.newInstance();
        } catch (ClassNotFoundException ex){
            SelectorThread.logger().log(Level.WARNING,ex.getMessage(),ex);
        } catch (InstantiationException ex){
            SelectorThread.logger().log(Level.WARNING,ex.getMessage(),ex);            
        } catch (IllegalAccessException ex){
            SelectorThread.logger().log(Level.WARNING,ex.getMessage(),ex);            
        }
        return null;
    
public booleanpostExecute()
Post-execute the ProcessorTask by preparing the response, flushing the response and then close or keep-alive the connection.

        processorTask.postResponse();
        processorTask.postProcess();        
        processorTask.terminateProcess();
        
        // De-reference so under stress we don't have a simili leak.
        processorTask = null;
        return false;
    
public booleanpreExecute()
Pre-execute a ProcessorTask by parsing the request line.

        processorTask = asyncProcessorTask.getProcessorTask(); 
        if ( processorTask == null ){
            throw new IllegalStateException("Null ProcessorTask");
        }
        processorTask.preProcess();
        processorTask.parseRequest();
        return true;
    
public booleanremoveAsyncFilter(com.sun.enterprise.web.connector.grizzly.AsyncFilter asyncFilter)
Remove an AsyncFilter

        return asyncFilters.remove(asyncFilter);
    
public voidsetAsyncHandler(com.sun.enterprise.web.connector.grizzly.AsyncHandler asyncHandler)
Set the AsyncHandler who drive the asynchronous process.

        this.asyncHandler = asyncHandler;
    
public voidsetAsyncTask(com.sun.enterprise.web.connector.grizzly.AsyncTask asyncProcessorTask)
Set the AsyncTask.

        this.asyncProcessorTask = asyncProcessorTask;