FileDocCategorySizeDatePackage
IsolationPipeline.javaAPI DocGlassfish v2 API6655Fri May 04 22:37:02 BST 2007com.sun.enterprise.web.ara

IsolationPipeline

public class IsolationPipeline extends com.sun.enterprise.web.connector.grizzly.LinkedListPipeline implements com.sun.enterprise.web.connector.grizzly.TaskListener
Customized Pipeline which wrap the original Task instance with an instance of IsolatedTask
author
Jeanfrancois Arcand

Fields Summary
private static final String
ALGORITHM_CLASS
private static final String
RULE_EXECUTOR_CLASS
private ConcurrentLinkedQueue
isolatedTasks
Cache instance of IsolatedTask
Constructors Summary
public IsolationPipeline()

    
      
    // ------------------------------------------------------ Constructor ---/
    
    
     
    
Methods Summary
public voidaddTask(com.sun.enterprise.web.connector.grizzly.Task task)
Execute the wrapped Task

    
        // SSL not yet supported.
        if (task.getType() == Task.READ_TASK){
            super.addTask(wrap(task));
        } else {
            super.addTask(task);
        }
    
public voidinitPipeline()
Initialize this pipeline by first initializing its parent, and then by creating the caches and the rule executor engine.

        // 1. first, init this pipeline.
        super.initPipeline();
        
        // 2. Create cache
        isolatedTasks = new ConcurrentLinkedQueue<IsolatedTask>();
        
        // 3. Cache IsolatedTask
        for (int i=0; i < maxThreads; i++){
            isolatedTasks.offer(newIsolatedTask());
        }  
    
private java.lang.ObjectloadInstance(java.lang.String property)
Instanciate a class based on a property.

        
        Class className = null;                               
        Pipeline pipeline = null;                               
        try{                              
            className = Class.forName(property);
            return className.newInstance();
        } catch (ClassNotFoundException ex){
        } catch (InstantiationException ex){
        } catch (IllegalAccessException ex){
        }
        
        // Default
        if ( property.equals(ALGORITHM_CLASS)){
            return new ContextRootAlgorithm();
        } else if ( property.equals(RULE_EXECUTOR_CLASS)){
            return new IsolationRulesExecutor();
        }
        throw new IllegalStateException();
    
private com.sun.enterprise.web.connector.grizzly.StreamAlgorithmnewAlgorithm()
Create a new StreamAlgorithm.

        return (StreamAlgorithm)loadInstance(ALGORITHM_CLASS);
    
private IsolatedTasknewIsolatedTask()
Create a new IsolatedTask

        IsolatedTask task = new IsolatedTask();
        
        task.setAlgorithm(newAlgorithm());
        task.setRulesExecutor(newRulesExecutor());
        task.addTaskListener(this);
        task.pipeline = this;
        return task;
    
private RulesExecutornewRulesExecutor()
Create the new RulesExecutor

        return (IsolationRulesExecutor)loadInstance(RULE_EXECUTOR_CLASS);
    
public voidtaskEvent(com.sun.enterprise.web.connector.grizzly.TaskEvent event)
Return the IsolatedTask to the pool.

        if ( event.getStatus() == TaskEvent.COMPLETED)
            isolatedTasks.offer((IsolatedTask)event.attachement());
    
public voidtaskStarted(com.sun.enterprise.web.connector.grizzly.TaskEvent event)

        ; // Do nothing.
    
private com.sun.enterprise.web.connector.grizzly.Taskwrap(com.sun.enterprise.web.connector.grizzly.Task task)
Wrap the current Task using an IsolatedTask

        IsolatedTask isolatedTask = isolatedTasks.poll();
        if ( isolatedTask == null){
            isolatedTask = newIsolatedTask();
        }
        isolatedTask.wrap(task);
        return isolatedTask;