eu.xtreemos.xosd.resmng.data
Class ConditionTreeCondition

java.lang.Object
  extended by eu.xtreemos.xosd.resmng.data.ConditionTreeCondition
All Implemented Interfaces:
IConditionTreeNode

public class ConditionTreeCondition
extends java.lang.Object
implements IConditionTreeNode

A class that implements the comparison of the end values that represent a resource against the conditions passed as the parameter. An instance of ConditionTreeCondition is a leaf node of the condition tree.

Author:
matej.artac@xlab.si

Field Summary
protected  int attribute
          Identifies which attribute the node refers to.
protected  int conditionType
          The type of condition.
static int EXACT
          This value represents a condition type where the value in the resource descriptor must be equal to the value of the node: x == E.
static int GREATERANDEQUALTO
          This value represents a condition type where the value in the resource descriptor must be greater than or equal to the value of the node: x >= U.
static int GREATERTHAN
          This value represents a condition type where the value in the resource descriptor must be greater than the value of the node: x > U.
protected  boolean hasBeenEvaluated
          True if a call to evaluateNode() has been performed, and false otherwise.
(package private) static org.apache.log4j.Logger logger
           
static int LOWERANDEQUALTO
          This value represents a condition type where the value in the resource descriptor must be lower than or equal to the value of the node: x <= U.
static int LOWERTHAN
          This value represents a condition type where the value in the resource descriptor must be lower than the value of the node: x < U.
static int NODECPUARCHITECTURENAME
          This value represents the node attribute which refers to the CPU architecture name (instruction set).
protected  INodeEvaluation nodeEvaluationFunction
          The class implementing an evaluation function for scoring the resource against the resource query.
static int NODEINDIVIDUALCPUCOUNT
          This value represents the node attribute which refers to the number of physical CPUs in the host.
static int NODEINDIVIDUALCPUSPEED
          This value represents the node attribute which refers to the individual CPU speed.
static int NODEINDIVIDUALPHYSICALRAM
          This value represents the node attribute refers to the individual physical RAM.
static int NODEOSSYSTEMNAME
          This value represents the node attribute which refers to the OS system name.
protected  java.lang.Object referenceValue
          The value we compare the resource against.
 
Constructor Summary
ConditionTreeCondition(double reference, int attribute, int conditionType)
           
ConditionTreeCondition(java.lang.String reference, int attribute)
          Instantiate a condition tree lead node that represents the comparison of a case insensitive equality to the string provided as the reference value of the node.
 
Method Summary
protected  boolean evalExact(java.lang.Object value)
           
protected  boolean evalGreaterThan(java.lang.Double value, boolean excl)
           
protected  boolean evalLowerThan(java.lang.Double value, boolean excl)
           
 boolean evaluateNode(ResourceDescriptorRecord resource)
          Check the compliance of the input resource with the node of the condition subtree originating from this node.
 double evaluateScore(ResourceDescriptorRecord resource)
          Check the compliance of the input resource with the node of the condition subtree originating from this node, and evaluate the score of the resource.
 double evaluateScore(ResourceDescriptorRecord resource, java.util.Hashtable<java.lang.Integer,java.lang.Double> attributeWeight)
          Check the compliance of the input resource with the node of the condition subtree originating from this node, and evaluate the score of the resource.
 int getAttribute()
           
 int getConditionType()
           
protected  java.lang.Object getMatchingResourceValue(ResourceDescriptorRecord resource)
          Returns the value of the resource attribute that corresponds the condition tree node's attribute.
 INodeEvaluation getNodeEvaluationFunction()
           
 java.lang.Object getReferenceValue()
           
 boolean getSubtreeScorekeeper(ResourceDescriptorRecord resource, java.util.Hashtable<java.lang.Integer,AttributeScorekeeper> scorekeepers)
          The method builds a hash table of AttributeScorekeeper instances for each of the attribute that takes part in the subtree of the condition tree that starts at the provided node.
 void setNodeEvaluationFunction(INodeEvaluation nodeEvaluationFunction)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger

EXACT

public static final int EXACT
This value represents a condition type where the value in the resource descriptor must be equal to the value of the node: x == E.

See Also:
Constant Field Values

LOWERTHAN

public static final int LOWERTHAN
This value represents a condition type where the value in the resource descriptor must be lower than the value of the node: x < U.

See Also:
Constant Field Values

GREATERTHAN

public static final int GREATERTHAN
This value represents a condition type where the value in the resource descriptor must be greater than the value of the node: x > U.

See Also:
Constant Field Values

LOWERANDEQUALTO

public static final int LOWERANDEQUALTO
This value represents a condition type where the value in the resource descriptor must be lower than or equal to the value of the node: x <= U.

See Also:
Constant Field Values

GREATERANDEQUALTO

public static final int GREATERANDEQUALTO
This value represents a condition type where the value in the resource descriptor must be greater than or equal to the value of the node: x >= U.

See Also:
Constant Field Values

NODEOSSYSTEMNAME

public static final int NODEOSSYSTEMNAME
This value represents the node attribute which refers to the OS system name. The reference value is a String.

See Also:
Constant Field Values

NODECPUARCHITECTURENAME

public static final int NODECPUARCHITECTURENAME
This value represents the node attribute which refers to the CPU architecture name (instruction set). The reference value is a String.

See Also:
Constant Field Values

NODEINDIVIDUALCPUSPEED

public static final int NODEINDIVIDUALCPUSPEED
This value represents the node attribute which refers to the individual CPU speed. The reference value is an Integer denoting the speed in Hz.

See Also:
Constant Field Values

NODEINDIVIDUALCPUCOUNT

public static final int NODEINDIVIDUALCPUCOUNT
This value represents the node attribute which refers to the number of physical CPUs in the host.

See Also:
Constant Field Values

NODEINDIVIDUALPHYSICALRAM

public static final int NODEINDIVIDUALPHYSICALRAM
This value represents the node attribute refers to the individual physical RAM. The reference value is an Integer denoting the RAM size in bytes.

See Also:
Constant Field Values

conditionType

protected int conditionType
The type of condition.


referenceValue

protected java.lang.Object referenceValue
The value we compare the resource against.


attribute

protected int attribute
Identifies which attribute the node refers to. Use the NODE* static members.


hasBeenEvaluated

protected boolean hasBeenEvaluated
True if a call to evaluateNode() has been performed, and false otherwise.


nodeEvaluationFunction

protected INodeEvaluation nodeEvaluationFunction
The class implementing an evaluation function for scoring the resource against the resource query.

Constructor Detail

ConditionTreeCondition

public ConditionTreeCondition(java.lang.String reference,
                              int attribute)
Instantiate a condition tree lead node that represents the comparison of a case insensitive equality to the string provided as the reference value of the node.

Parameters:
reference - The value to test the resources against.
attribute - Identifies which attribute the node refers to. Use the NODE* static members.

ConditionTreeCondition

public ConditionTreeCondition(double reference,
                              int attribute,
                              int conditionType)
Method Detail

evalExact

protected boolean evalExact(java.lang.Object value)

evalLowerThan

protected boolean evalLowerThan(java.lang.Double value,
                                boolean excl)

evalGreaterThan

protected boolean evalGreaterThan(java.lang.Double value,
                                  boolean excl)

evaluateNode

public boolean evaluateNode(ResourceDescriptorRecord resource)
                     throws java.lang.IllegalArgumentException
Description copied from interface: IConditionTreeNode
Check the compliance of the input resource with the node of the condition subtree originating from this node.

Specified by:
evaluateNode in interface IConditionTreeNode
Parameters:
resource - The resource to check the compliance of.
Returns:
True if the resource fits the conditions of the condition subtree, and false otherwise.
Throws:
java.lang.IllegalArgumentException

evaluateScore

public double evaluateScore(ResourceDescriptorRecord resource)
                     throws java.lang.IllegalArgumentException
Check the compliance of the input resource with the node of the condition subtree originating from this node, and evaluate the score of the resource. Higher values of the score mean better compliance with the query.

Specified by:
evaluateScore in interface IConditionTreeNode
Parameters:
resource - The resource to check the compliance of.
Returns:
The score of the resource. The higher the score, the better the resource fits the query. Returns -1 for resources that do not fit the conditions of the query.
Throws:
java.lang.IllegalArgumentException

evaluateScore

public double evaluateScore(ResourceDescriptorRecord resource,
                            java.util.Hashtable<java.lang.Integer,java.lang.Double> attributeWeight)
                     throws java.lang.IllegalArgumentException
Description copied from interface: IConditionTreeNode
Check the compliance of the input resource with the node of the condition subtree originating from this node, and evaluate the score of the resource. Higher values of the score mean better compliance with the query. The attributes have uniform influence to the score.

Specified by:
evaluateScore in interface IConditionTreeNode
Parameters:
resource - The resource to check the compliance of.
attributeWeight - A hash table of pairs (attribute identifier, the weight)
Returns:
The score of the resource. The higher the score, the better the resource fits the query. Returns -1 for resources that do not fit the conditions of the query.
Throws:
java.lang.IllegalArgumentException

getSubtreeScorekeeper

public boolean getSubtreeScorekeeper(ResourceDescriptorRecord resource,
                                     java.util.Hashtable<java.lang.Integer,AttributeScorekeeper> scorekeepers)
The method builds a hash table of AttributeScorekeeper instances for each of the attribute that takes part in the subtree of the condition tree that starts at the provided node. The caller function should pass an already initialised Hashtable.

Specified by:
getSubtreeScorekeeper in interface IConditionTreeNode
Parameters:
resource - The resource record to get the scores of.
scorekeepers - The hash table that receives the attribute's scores. The contents of the hash table will change during the call execution. The method encounters a single attribute, and thus it updates a single entry in the hash table. If the attribute fits the condition of the node, the evaluated attribute's score will be added to the hashtable, otherwise a negative score will be noted if the attribute does not have any entry in the hash table before the call of the method.
Returns:
True if the resource fits the conditions of the condition subtree, and false otherwise.

getMatchingResourceValue

protected java.lang.Object getMatchingResourceValue(ResourceDescriptorRecord resource)
Returns the value of the resource attribute that corresponds the condition tree node's attribute.

Parameters:
resource - The descriptor record to retrieve the matching value from.
Returns:
The value represented in the resource descriptor that corresponds to the query's attribute.

getNodeEvaluationFunction

public INodeEvaluation getNodeEvaluationFunction()

setNodeEvaluationFunction

public void setNodeEvaluationFunction(INodeEvaluation nodeEvaluationFunction)

getConditionType

public int getConditionType()

getReferenceValue

public java.lang.Object getReferenceValue()

getAttribute

public int getAttribute()