MultiExpressionEvaluator (ActiveMQ 1.1 API)
Keywords: org.codehaus.activemq.filter.MultiExpressionEvaluator class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.activemq.filter
Class MultiExpressionEvaluator

    java.lang.Object
      org.codehaus.activemq.filter.MultiExpressionEvaluator

public class MultiExpressionEvaluator
extends Object

A MultiExpressionEvaluator is used to evaluate multiple expressions in single method call.

Multiple Expression/ExpressionListener pairs can be added to a MultiExpressionEvaluator object. When the MultiExpressionEvaluator object is evaluated, all the registed Expressions are evaluated and then the associated ExpressionListener is invoked to inform it of the evaluation result.

By evaluating multiple expressions at one time, some optimizations can be made to reduce the number of computations normally required to evaluate all the expressions.

When this class adds an Expression it wrapps each node in the Expression's AST with a CacheExpression object. Then each CacheExpression object (one for each node) is placed in the cachedExpressions map. The cachedExpressions map allows us to find the sub expressions that are common across two different expressions. When adding an Expression in, if a sub Expression of the Expression is allready in the cachedExpressions map, then instead of wrapping the sub expression in a new CacheExpression object, we reuse the CacheExpression allready int the map.

To help illustrate what going on, lets try to give an exmample: If we denote the AST of a Expression as follows: [AST-Node-Type,Left-Node,Right-Node], then A expression like: "3*5+6" would result in "[*,3,[+,5,6]]"

If the [*,3,[+,5,6]] expression is added to the MultiExpressionEvaluator, it would really be converted to: [c0,[*,3,[c1,[+,5,6]]]] where c0 and c1 represent the CacheExpression expression objects that cache the results of the * and the + operation. Constants and Property nodes are not cached.

If later on we add the following expression [=,11,[+,5,6]] ("11=5+6") to the MultiExpressionEvaluator it would be converted to: [c2,[=,11,[c1,[+,5,6]]]], where c2 is a new CacheExpression object but c1 is the same CacheExpression used in the previous expression.

When the expressions are evaluated, the c1 CacheExpression object will only evaluate the [+,5,6] expression once and cache the resulting value. Hence evauating the second expression costs less because that [+,5,6] is not done 2 times.

Problems: - cacheing the values introduces overhead. It may be possible to be smarter about WHICH nodes in the AST are cached and which are not. - Current implementation is not thread safe. This is because you need a way to invalidate all the cached values so that the next evaluation re-evaluates the nodes. By going single threaded, chache invalidation is done quickly by incrementing a 'view' counter. When a CacheExpressionnotices it's last cached value was generated in an old 'view', it invalidates its cached value.

Version:
  $Revision: 1.2 $ $Date: 2004/08/23 15:22:11 $

Nested Class Summary
`class` | `MultiExpressionEvaluator.CacheExpression` A UnaryExpression that caches the result of the nested expression.
`(package private) static interface` | `MultiExpressionEvaluator.ExpressionListener` Objects that are interested in the results of an expression should implement this interface.
`(package private) static class` | `MultiExpressionEvaluator.ExpressionListenerSet` Multiple listeners my be interested in the results of a single expression.

Field Summary
`(package private) HashMap` | `cachedExpressions`
`(package private) HashMap` | `rootExpressions`
`(package private) int` | `view`

Constructor Summary
`MultiExpressionEvaluator()`

Method Summary
`void` | `addExpressionListner(Expression selector, MultiExpressionEvaluator.ExpressionListener c)` Adds an ExpressionListener to a given expression.
`void` | `evaluate(Message message)` Evaluates the message against all the Expressions added to this object.
`boolean` | `removeEventListner(String selector, MultiExpressionEvaluator.ExpressionListener c)` Removes an ExpressionListener from receiving the results of a given evaluation.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### rootExpressions

    HashMap rootExpressions

### cachedExpressions

    HashMap cachedExpressions

### view

    int view

Constructor Detail

### MultiExpressionEvaluator

    public MultiExpressionEvaluator()

Method Detail

### addExpressionListner

    public void addExpressionListner(Expression selector,
                                     MultiExpressionEvaluator.ExpressionListener c)

  Adds an ExpressionListener to a given expression. When evaluate is called, the ExpressionListener will be provided the results of the Expression applied to the evaluated message.

### removeEventListner

    public boolean removeEventListner(String selector,
                                      MultiExpressionEvaluator.ExpressionListener c)

  Removes an ExpressionListener from receiving the results of a given evaluation.

### evaluate

    public void evaluate(Message message)

  Evaluates the message against all the Expressions added to this object. The added ExpressionListeners are notified of the result of the evaluation.

  Parameters:
    `message` -

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2004 Protique, Ltd.. All Rights Reserved.