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

IsolationRulesExecutor

public class IsolationRulesExecutor extends Object implements RulesExecutor
This class execute sequentialy Rules on a Task
author
Jeanfrancois Arcand

Fields Summary
public static final int
RULE_OK
public static final int
RULE_DELAY
public static final int
RULE_BLOCKED
public static final int
RULE_OK_NOCACHE
public static final int
RULE_CONTINUE
private static final String
RULE_CLASS
private static final String
DELAY_VALUE
private static final int
INITIAL_RULE_COUNT
Initial number of Rule to cache.
protected ArrayList
rules
The list of Rule to apply to a Task
private static int
currentThreadCount
The current number of thread used.
private static long
delayValue
The time this thread will sleep when a rule is delayed.
private boolean
isCachingAllowed
Is caching allowed
Constructors Summary
public IsolationRulesExecutor()

    
    // ---------------------------------------------------------------------//
    
     
      
        loadRules();
        
        if ( System.getProperty(DELAY_VALUE) != null){
            delayValue = Long.valueOf(System.getProperty(DELAY_VALUE));         
        }
    
Methods Summary
public booleanexecute(IsolatedTask isolatedTask)
Execute the Rules on the IsolatedTask

param
isolatedTask the task used.
return
true if the request processing can continue.

        ReadTask task = (ReadTask)isolatedTask.getWrappedTask();
                       
        Integer status = 0;
        int i = 0;
        isCachingAllowed = true;
        while(true) {
            rules.get(i).attach(task);
            
            try{
                status = (Integer)rules.get(i).call();  
            } catch(Exception ex) { 
                SelectorThread.logger().log(Level.SEVERE,"Rule exception",ex);
                return true;
            }
            
            isCachingAllowed = (status == RULE_OK_NOCACHE ? false:true);
            
            if (status == RULE_DELAY){   
                
                // Wait until the delay expire. The current thread will 
                // wait and then re-execute the rules.
                try{
                    Thread.sleep(delayValue);
                } catch (InterruptedException ex) {
                    SelectorThread.logger().
                            log(Level.SEVERE,"Rule delay exception",ex);
                }
                i = 0;
                continue;
            }  else if ( status == RULE_BLOCKED ){
                task.cancelTask("No resources available.", HtmlHelper.OK);
                return true;
            } 
            
            i++;
            if (i == rules.size()){
                break;
            }
        }
        
        return (status == RULE_OK || status == RULE_OK_NOCACHE);
 
    
public booleanisCachingAllowed()
Is caching of Rule results allowed

        return isCachingAllowed;
    
private com.sun.enterprise.web.connector.grizzly.RuleloadInstance(java.lang.String property)
Instanciate a class based on a property.

        
        Class className = null;                               
        try{                              
            className = Class.forName(property);
            return (Rule)className.newInstance();
        } catch (ClassNotFoundException ex){
        } catch (InstantiationException ex){
        } catch (IllegalAccessException ex){
        }
        return new PathRule();
    
protected voidloadRules()
Load the list of Rules to apply to a Task

      
        if ( System.getProperty(RULE_CLASS) != null){
            StringTokenizer st = new StringTokenizer(
                    System.getProperty(RULE_CLASS),",");
            while (st.hasMoreTokens()){
                rules.add(loadInstance(st.nextToken()));                
            } 
        }   
        
        if ( rules.size() == 0){
            rules.add(new PathRule());
        }