org.javasimon.callback
Class CompositeFilterCallback

java.lang.Object
  extended by org.javasimon.callback.CompositeFilterCallback
All Implemented Interfaces:
Callback, CompositeCallback, FilterCallback

public final class CompositeFilterCallback
extends Object
implements FilterCallback, CompositeCallback

This callback combines Composite and Filter behavior. Filter can be configured via addRule(FilterRule.Type, String, String, Callback.Event...) method and if the rule is satisfied the event is propagated to all children callbacks added via addCallback(Callback). XML facility for configuration is provided via ManagerConfiguration.readConfig(java.io.Reader).

Filter without any rules does not propagate events (default DENY behavior). Any number of global rules (for Callback.Event.ALL) and per event rules can be added. Event rules have higher priority and if the filter passes on event rules, global rules are not consulted. Rules are checked in the order they were added to the filter.

Author:
Richard "Virgo" Richter
See Also:
FilterRule

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.javasimon.callback.Callback
Callback.Event
 
Field Summary
private  CompositeCallbackImpl callback
           
private  Map<Callback.Event,List<FilterRule>> rules
           
 
Constructor Summary
CompositeFilterCallback()
          Constructs composite filter callback.
 
Method Summary
 void addCallback(Callback callback)
          Adds another callback as a child to this callback.
 void addRule(FilterRule.Type type, String condition, String pattern, Callback.Event... events)
          Adds the rule to the filter.
 List<Callback> callbacks()
          Returns the list of all child-callbacks.
 void cleanup()
          Lifecycle method called when the callback is removed from the manager.
private  boolean checkRules(Simon simon, Callback.Event event, Object... params)
           
 void initialize()
          Lifecycle method called when the callback is added to a manager.
 void onCounterDecrease(Counter counter, long dec, CounterSample sample)
          Counter decrease event.
 void onCounterIncrease(Counter counter, long inc, CounterSample sample)
          Counter increase event.
 void onCounterSet(Counter counter, long val, CounterSample sample)
          Counter set event.
 void onManagerClear()
          Event called when the manager is cleared.
 void onManagerMessage(String message)
          Message event is used to propagate arbitrary messages from the manager, or it can be used by the other Callback methods internally.
 void onManagerWarning(String warning, Exception cause)
          Warning event containing warning and/or cause.
 void onSimonCreated(Simon simon)
          Simon created event is called when Simon is successfully created by the Manager.
 void onSimonDestroyed(Simon simon)
          Simon destroyed event is called when Simon is successfully destroyed by the Manager.
 void onSimonReset(Simon simon)
          Simon reset event.
 void onStopwatchAdd(Stopwatch stopwatch, long ns, StopwatchSample sample)
          Stopwatch add time event.
 void onStopwatchAdd(Stopwatch stopwatch, Split split, StopwatchSample sample)
          Stopwatch add split event.
 void onStopwatchStart(Split split)
          Stopwatch start event.
 void onStopwatchStop(Split split, StopwatchSample sample)
          Stopwatch stop event.
private  boolean patternAndConditionCheck(Simon simon, FilterRule rule, Object... params)
           
 void removeAllCallbacks()
          Removes all callbacks from this callback.
 void removeCallback(Callback callback)
          Removes specified callback from this callback.
private  boolean rulesApplyTo(Simon simon, Callback.Event checkedEvent, Object... params)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

callback

private CompositeCallbackImpl callback

rules

private Map<Callback.Event,List<FilterRule>> rules
Constructor Detail

CompositeFilterCallback

public CompositeFilterCallback()
Constructs composite filter callback.

Method Detail

callbacks

public List<Callback> callbacks()
Description copied from interface: CompositeCallback
Returns the list of all child-callbacks.

Specified by:
callbacks in interface CompositeCallback
Returns:
children list

addCallback

public void addCallback(Callback callback)
Description copied from interface: CompositeCallback
Adds another callback as a child to this callback.

Specified by:
addCallback in interface CompositeCallback
Parameters:
callback - added callback

removeCallback

public void removeCallback(Callback callback)
Description copied from interface: CompositeCallback
Removes specified callback from this callback.

Specified by:
removeCallback in interface CompositeCallback
Parameters:
callback - removed child-callback

removeAllCallbacks

public void removeAllCallbacks()
Description copied from interface: CompositeCallback
Removes all callbacks from this callback.

Specified by:
removeAllCallbacks in interface CompositeCallback

initialize

public void initialize()
Description copied from interface: Callback
Lifecycle method called when the callback is added to a manager.

Specified by:
initialize in interface Callback

cleanup

public void cleanup()
Description copied from interface: Callback
Lifecycle method called when the callback is removed from the manager. It should implement any necessary cleanup or resources - e.g. release JDBC connection if one was used for Callback functionality.

Specified by:
cleanup in interface Callback

onSimonReset

public void onSimonReset(Simon simon)
Description copied from interface: Callback
Simon reset event.

Specified by:
onSimonReset in interface Callback
Parameters:
simon - reset Simon

onStopwatchAdd

public void onStopwatchAdd(Stopwatch stopwatch,
                           long ns,
                           StopwatchSample sample)
Description copied from interface: Callback
Stopwatch add time event. StopwatchSample valid for the moment after the add is provided because the callback is executed out of synchronized block.

Specified by:
onStopwatchAdd in interface Callback
Parameters:
stopwatch - modified Stopwatch
ns - added split time in ns
sample - stopwatch sampled after the add

onStopwatchAdd

public void onStopwatchAdd(Stopwatch stopwatch,
                           Split split,
                           StopwatchSample sample)
Description copied from interface: Callback
Stopwatch add split event. StopwatchSample valid for the moment after the add is provided because the callback is executed out of synchronized block.

Specified by:
onStopwatchAdd in interface Callback
Parameters:
stopwatch - modified Stopwatch
split - added split object
sample - stopwatch sampled after the add

onStopwatchStart

public void onStopwatchStart(Split split)
Description copied from interface: Callback
Stopwatch start event. Duration of all callbacks is included into the split time! StopwatchSample valid for the moment after the start is provided because the callback is executed out of synchronized block.

Specified by:
onStopwatchStart in interface Callback
Parameters:
split - started Split

onStopwatchStop

public void onStopwatchStop(Split split,
                            StopwatchSample sample)
Description copied from interface: Callback
Stopwatch stop event. This action is executed after the split time is calculated and does not affect the measuring. StopwatchSample valid for the moment after the stop is provided because the callback is executed out of synchronized block.

Specified by:
onStopwatchStop in interface Callback
Parameters:
split - stopped Split
sample - stopwatch sampled after the stop

onCounterDecrease

public void onCounterDecrease(Counter counter,
                              long dec,
                              CounterSample sample)
Description copied from interface: Callback
Counter decrease event. CounterSample valid for the moment after the operation is provided because the callback is executed out of synchronized block.

Specified by:
onCounterDecrease in interface Callback
Parameters:
counter - modified Counter
dec - decrement amount
sample - counter sampled after the operation

onCounterIncrease

public void onCounterIncrease(Counter counter,
                              long inc,
                              CounterSample sample)
Description copied from interface: Callback
Counter increase event. CounterSample valid for the moment after the operation is provided because the callback is executed out of synchronized block.

Specified by:
onCounterIncrease in interface Callback
Parameters:
counter - modified Counter
inc - increment amount
sample - counter sampled after the operation

onCounterSet

public void onCounterSet(Counter counter,
                         long val,
                         CounterSample sample)
Description copied from interface: Callback
Counter set event. CounterSample valid for the moment after the operation is provided because the callback is executed out of synchronized block.

Specified by:
onCounterSet in interface Callback
Parameters:
counter - modified Counter
val - new value
sample - counter sampled after the operation

onSimonCreated

public void onSimonCreated(Simon simon)
Description copied from interface: Callback
Simon created event is called when Simon is successfully created by the Manager.

Specified by:
onSimonCreated in interface Callback
Parameters:
simon - created Simon

onSimonDestroyed

public void onSimonDestroyed(Simon simon)
Description copied from interface: Callback
Simon destroyed event is called when Simon is successfully destroyed by the Manager.

Specified by:
onSimonDestroyed in interface Callback
Parameters:
simon - destroyed Simon

onManagerClear

public void onManagerClear()
Description copied from interface: Callback
Event called when the manager is cleared.

Specified by:
onManagerClear in interface Callback

onManagerMessage

public void onManagerMessage(String message)
Description copied from interface: Callback
Message event is used to propagate arbitrary messages from the manager, or it can be used by the other Callback methods internally.

Specified by:
onManagerMessage in interface Callback
Parameters:
message - message text

onManagerWarning

public void onManagerWarning(String warning,
                             Exception cause)
Description copied from interface: Callback
Warning event containing warning and/or cause.

Specified by:
onManagerWarning in interface Callback
Parameters:
warning - arbitrary warning message - can be null, unless concrete implementation states otherwise
cause - exception causing this warning - can be null, unless concrete implementation states otherwise

addRule

public void addRule(FilterRule.Type type,
                    String condition,
                    String pattern,
                    Callback.Event... events)
Description copied from interface: FilterCallback
Adds the rule to the filter.

Specified by:
addRule in interface FilterCallback
Parameters:
type - rule type (must, suffice, must-not)
condition - further conditions of the rule
pattern - Simon pattern
events - event list (empty applies to all, can be omitted)

rulesApplyTo

private boolean rulesApplyTo(Simon simon,
                             Callback.Event checkedEvent,
                             Object... params)

checkRules

private boolean checkRules(Simon simon,
                           Callback.Event event,
                           Object... params)

patternAndConditionCheck

private boolean patternAndConditionCheck(Simon simon,
                                         FilterRule rule,
                                         Object... params)
                                  throws ScriptException
Throws:
ScriptException


Copyright © 2013. All Rights Reserved.