es.rediris.aarr.rules
Class RuleProcessor

java.lang.Object
  extended by es.rediris.aarr.rules.RuleProcessor
All Implemented Interfaces:
java.lang.Runnable, java.util.Observer

public class RuleProcessor
extends java.lang.Object
implements java.util.Observer, java.lang.Runnable

This class is used for processing all rules in a ruleset, by checking that all conditions are satisfied and then, performing the actions in every rule.

Author:
kan

Field Summary
(package private) static java.lang.Object lastInput
          The last received request
(package private) static ProfileManager profileManager
          A ProfileManager
(package private) static java.lang.String requestName
           
(package private) static int requestStatus
           
(package private) static java.lang.String[] requestValues
           
static int RP_ENDED
           
static int RP_RECEIVED
           
static int RP_STARTING
          Request status values
static int RP_WAIT_TIMEOUT
           
static int RP_WAITING
           
protected  Ruleset ruleSet
          An internal Ruleset object for storing rules
(package private)  RuleProcessor self
           
(package private)  java.lang.Thread thread
          A thread
private  long timeout
          A boolean token to control if the thread is suspended while waiting for a request
 
Constructor Summary
RuleProcessor(org.w3c.dom.Element ruleset)
          The main constructor receives a Ruleset object previously loaded
 
Method Summary
protected static void dropQuery()
          Removes last query from the input queue
protected static void endExecution()
          Sets the end execution token to true
protected static java.lang.String getInputQuery()
          Returns a String with the name of the last input element (the first in the input query)
protected static java.lang.String[] getParam(java.lang.String name)
          Gets the value of a param (defined by data) for the protocol adaptor in use
 void init(ProfileManager pm)
          Init the ruler processor by creating a ProfileManager, input and output queues, and starting a new Thread
protected static boolean isFinished()
          Checks if the rule processor has finished its execution.
private  void parseRuleset(org.w3c.dom.Element ruleset)
          Parses a document (or XML Element) that defines a rule set, loading all the states, rules, conditions and actions inside it
protected static void putOutput(java.lang.String[] ids, java.lang.String[] values)
          Send a response back to the ProtocolAdaptor
 void run()
          Executes actual states and sends information about the current status to the diagnostics module
private  Action searchAction(org.w3c.dom.Element actionElem)
          Similar to searchCondition() but for Actions.
private  Condition searchCondition(org.w3c.dom.Element condElem)
          Match the kind of condition being processed at the moment and returns a condition defined in element (org.w3c.dom.Element Object) of the document.
 void setTimeout(long millisecs)
          Sets the timemout for the rule processor
 void update(java.util.Observable obs, java.lang.Object data)
          Adds a new query to the input queue
 void waitInput(long millisecs)
          Wait for a request the amount of time provided as a param
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastInput

static java.lang.Object lastInput
The last received request


requestName

static java.lang.String requestName

requestValues

static java.lang.String[] requestValues

requestStatus

static int requestStatus

RP_STARTING

public static final int RP_STARTING
Request status values

See Also:
Constant Field Values

RP_WAITING

public static final int RP_WAITING
See Also:
Constant Field Values

RP_RECEIVED

public static final int RP_RECEIVED
See Also:
Constant Field Values

RP_WAIT_TIMEOUT

public static final int RP_WAIT_TIMEOUT
See Also:
Constant Field Values

RP_ENDED

public static final int RP_ENDED
See Also:
Constant Field Values

profileManager

static ProfileManager profileManager
A ProfileManager


timeout

private long timeout
A boolean token to control if the thread is suspended while waiting for a request


thread

java.lang.Thread thread
A thread


self

RuleProcessor self

ruleSet

protected Ruleset ruleSet
An internal Ruleset object for storing rules

Constructor Detail

RuleProcessor

public RuleProcessor(org.w3c.dom.Element ruleset)
The main constructor receives a Ruleset object previously loaded

Parameters:
ruleset - A Ruleset already loaded
Method Detail

init

public void init(ProfileManager pm)
Init the ruler processor by creating a ProfileManager, input and output queues, and starting a new Thread

Parameters:
pm - A ProfileManager Object

parseRuleset

private void parseRuleset(org.w3c.dom.Element ruleset)
Parses a document (or XML Element) that defines a rule set, loading all the states, rules, conditions and actions inside it

Parameters:
ruleset - An (XML) ruleset element previously loaded

searchCondition

private Condition searchCondition(org.w3c.dom.Element condElem)
Match the kind of condition being processed at the moment and returns a condition defined in element (org.w3c.dom.Element Object) of the document.

Parameters:
condElem - An element (org.w3c.dom.Element) defining a condition
Returns:
A Condition object: one of ConditionDefault, ConditionField, or ConditionReceive.

update

public void update(java.util.Observable obs,
                   java.lang.Object data)
Adds a new query to the input queue

Specified by:
update in interface java.util.Observer
Parameters:
obs - An ObservableVector with queries
data - @deprecated Not used

dropQuery

protected static void dropQuery()
Removes last query from the input queue


putOutput

protected static void putOutput(java.lang.String[] ids,
                                java.lang.String[] values)
Send a response back to the ProtocolAdaptor

Parameters:
ids - An array of ids
values - The corresponding array of values for the ids

searchAction

private Action searchAction(org.w3c.dom.Element actionElem)
Similar to searchCondition() but for Actions. Matches the kind of action being processed at the moment returning the action defined in an element (org.w3c.dom.Element Object) of the ruleset being processed.

Parameters:
actionElem - An element (org.w3c.dom.Element) defining an action
Returns:
A Action object: one of ActionSend, ActionNext, or ActionFinish

getInputQuery

protected static java.lang.String getInputQuery()
Returns a String with the name of the last input element (the first in the input query)


getParam

protected static java.lang.String[] getParam(java.lang.String name)
Gets the value of a param (defined by data) for the protocol adaptor in use

Parameters:
name - The param to ask for
Returns:
The value associated with the param expressed by data

endExecution

protected static void endExecution()
Sets the end execution token to true


isFinished

protected static boolean isFinished()
Checks if the rule processor has finished its execution.

Returns:
True if execution has finished, false otherwise.

setTimeout

public void setTimeout(long millisecs)
Sets the timemout for the rule processor

Parameters:
millisecs - Time in milliseconds

run

public void run()
Executes actual states and sends information about the current status to the diagnostics module

Specified by:
run in interface java.lang.Runnable

waitInput

public void waitInput(long millisecs)
Wait for a request the amount of time provided as a param

Parameters:
millisecs - Time in milliseconds to wait until a request is received or a timeout condition is reached