net.sourceforge.hiveevents
Class ConstraintFilter<T>

java.lang.Object
  extended by net.sourceforge.hiveevents.ConstraintFilter<T>
All Implemented Interfaces:
Filter<T>

public class ConstraintFilter<T>
extends java.lang.Object
implements Filter<T>

Event filter that is based on a constraint expressed in a specific language, OCL (Object Constraint Language). Allows to easily define filters that have complex constraints.

The OCL is a simple language that allows evaluation of a boolean expression based on various operators (comparison, boolean arithmetic). It also can reflect any property of the vent to be evaluated (for further checks).

Example:

 event.id != 0 && (event.type == 1 || event.type == 2) && event.priority > 2
 
In that example event is the variable name that can be used to represent the event to be evaluated by the filter.

Author:
Jean-Francois Poilpret

Field Summary
static java.lang.String EVENT_NAME
           
 
Constructor Summary
ConstraintFilter(java.lang.String constraint, java.lang.Class eventClass)
          Build a new ConstraintFilter.
ConstraintFilter(java.lang.String constraint, java.lang.Class eventClass, java.lang.String argName, java.lang.Class argClass, java.lang.Object argValue)
          Build a new ConstraintFilter with one additional variable in the expression.
ConstraintFilter(java.lang.String constraint, java.util.Map<java.lang.String,java.lang.Class> classes, java.util.Map<java.lang.String,java.lang.Object> values)
          Build a new ConstraintFilter with additional variables in the expression.
 
Method Summary
 boolean passEvent(T event)
          Check if an event must pass to the consumer or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EVENT_NAME

public static final java.lang.String EVENT_NAME
See Also:
Constant Field Values
Constructor Detail

ConstraintFilter

public ConstraintFilter(java.lang.String constraint,
                        java.lang.Class eventClass)
Build a new ConstraintFilter.

Parameters:
constraint - the expression to evaluate for each event
eventClass - class of the event (used for event reflection control)

ConstraintFilter

public ConstraintFilter(java.lang.String constraint,
                        java.lang.Class eventClass,
                        java.lang.String argName,
                        java.lang.Class argClass,
                        java.lang.Object argValue)
Build a new ConstraintFilter with one additional variable in the expression.

This is seldom used.

Parameters:
constraint - the expression to evaluate for each event
eventClass - class of the event (used for event reflection control)
argName - the name of the additional variable (as used in the constraint expression)
argClass - the class of the additional variable (used for reflection control)
argValue - the value of the additional variable

ConstraintFilter

public ConstraintFilter(java.lang.String constraint,
                        java.util.Map<java.lang.String,java.lang.Class> classes,
                        java.util.Map<java.lang.String,java.lang.Object> values)
Build a new ConstraintFilter with additional variables in the expression.

This is seldom used.

Parameters:
constraint - the expression to evaluate for each event
classes - the classes of additional variables (used for reflection control) indexed by name (must contain "event")
values - the values of additional variables indexed by name (must contain "event")
Method Detail

passEvent

public boolean passEvent(T event)
Description copied from interface: Filter
Check if an event must pass to the consumer or not.

Specified by:
passEvent in interface Filter<T>
Parameters:
event - the event to be checked
Returns:
true if the event must be notified to the consumer