org.javasimon.callback
Class FilterRule

java.lang.Object
  extended by org.javasimon.callback.FilterRule

public class FilterRule
extends Object

Represents filtering rule that checks whether subcallbacks will get the event. Rule can be one of the following types:

As the order is important not all MUST rules must pass if there is any satisfied SUFFICE rule before.

Since:
3.1 (previously was FilterCallback.Rule)
Author:
Richard "Virgo" Richter

Nested Class Summary
static class FilterRule.Type
          Enumeration of rule types that determines the evaluation of mutliple rules in a chain.
 
Field Summary
private  String condition
           
private static Replacer[] CONDITION_REPLACERS
           
private static ScriptEngine ECMA_SCRIPT_ENGINE
           
private  CompiledScript expression
           
private  SimonPattern pattern
           
private  FilterRule.Type type
           
static String VAR_ACTIVE
          Name of the rule variable for number of concurrently active splits of a particular Simon (active).
static String VAR_COUNTER
          Name of the rule variable for current value of the counter (counter).
static String VAR_MAX
          Name of the rule variable for maximal value of the Simon - stopwatch in ns, counter without unit (max).
static String VAR_MAX_ACTIVE
          Name of the rule variable for maximal number of concurrently active splits (maxactive).
static String VAR_MIN
          Name of the rule variable for minimal value of the Simon - stopwatch in ns, counter without unit (min).
static String VAR_SPLIT
          Name of the rule variable for last split time in ns (split).
static String VAR_TOTAL
          Name of the rule variable for total split time (total).
static String VAR_VALUE
          Name of the rule variable for increment or decrement value (value).
 
Constructor Summary
FilterRule(FilterRule.Type type, String condition, SimonPattern pattern)
          Creates the rule with a specified type, condition and pattern.
 
Method Summary
private  boolean eval(Bindings bindings)
           
 String getCondition()
          Returns the additional condition of this rule.
 SimonPattern getPattern()
          Retruns the Simon pattern of this rule.
 FilterRule.Type getType()
          Returns the type of this rule.
 boolean checkCondition(Simon simon, Object... params)
          Checks the Simon and optional parameters against the condition specified for a rule.
private  boolean checkCounter(Counter counter, Object... params)
           
private  boolean checkStopwtach(Stopwatch stopwatch, Object... params)
           
private  void processParams(Bindings bindings, Object... params)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VAR_SPLIT

public static final String VAR_SPLIT
Name of the rule variable for last split time in ns (split).

See Also:
Constant Field Values

VAR_ACTIVE

public static final String VAR_ACTIVE
Name of the rule variable for number of concurrently active splits of a particular Simon (active).

See Also:
Constant Field Values

VAR_MAX_ACTIVE

public static final String VAR_MAX_ACTIVE
Name of the rule variable for maximal number of concurrently active splits (maxactive).

See Also:
Constant Field Values

VAR_COUNTER

public static final String VAR_COUNTER
Name of the rule variable for current value of the counter (counter).

See Also:
Constant Field Values

VAR_MAX

public static final String VAR_MAX
Name of the rule variable for maximal value of the Simon - stopwatch in ns, counter without unit (max).

See Also:
Constant Field Values

VAR_MIN

public static final String VAR_MIN
Name of the rule variable for minimal value of the Simon - stopwatch in ns, counter without unit (min).

See Also:
Constant Field Values

VAR_TOTAL

public static final String VAR_TOTAL
Name of the rule variable for total split time (total).

See Also:
Constant Field Values

VAR_VALUE

public static final String VAR_VALUE
Name of the rule variable for increment or decrement value (value).

See Also:
Constant Field Values

ECMA_SCRIPT_ENGINE

private static final ScriptEngine ECMA_SCRIPT_ENGINE

CONDITION_REPLACERS

private static final Replacer[] CONDITION_REPLACERS

type

private FilterRule.Type type

condition

private String condition

expression

private CompiledScript expression

pattern

private SimonPattern pattern
Constructor Detail

FilterRule

public FilterRule(FilterRule.Type type,
                  String condition,
                  SimonPattern pattern)
Creates the rule with a specified type, condition and pattern. Rule can have a condition and/or a pattern. Pattern is not relevant for manager-level callback operations (Callback.onManagerWarning(String, Exception), Callback.onManagerMessage(String)). Both condition and pattern are optional and can be null.

Parameters:
type - rule type determining the role of the rule in the chain of the filter
condition - additional conditional expression that must be true
pattern - Simon pattern that must match
Method Detail

getType

public FilterRule.Type getType()
Returns the type of this rule.

Returns:
type of this rule

getCondition

public String getCondition()
Returns the additional condition of this rule. Values from the affected Simon can be checked and compared.

Returns:
additional condition of this rule

getPattern

public SimonPattern getPattern()
Retruns the Simon pattern of this rule.

Returns:
Simon pattern of this rule

checkCondition

public boolean checkCondition(Simon simon,
                              Object... params)
                       throws ScriptException
Checks the Simon and optional parameters against the condition specified for a rule.

Parameters:
simon - related Simon
params - optional parameters, e.g. value that is added to a Counter
Returns:
true if no condition is specified or the condition is satisfied, otherwise false
Throws:
ScriptException - possible exception raised by the expression evaluation

checkCounter

private boolean checkCounter(Counter counter,
                             Object... params)
                      throws ScriptException
Throws:
ScriptException

checkStopwtach

private boolean checkStopwtach(Stopwatch stopwatch,
                               Object... params)
                        throws ScriptException
Throws:
ScriptException

processParams

private void processParams(Bindings bindings,
                           Object... params)

eval

private boolean eval(Bindings bindings)
              throws ScriptException
Throws:
ScriptException


Copyright © 2013. All Rights Reserved.