Apama 10.7.2 | Developing Apama Applications | Developing Apama Applications in Java | Defining Event Expressions | Specifying temporal sequencing | Using temporal operators
 
Using temporal operators
Let us return to how to express searching for a temporal sequence. If there is no requirement to execute any arbitrary code in between events and there is no requirement to link searches as illustrated above, then you can embed a temporal event expression within a single listener.
The first code excerpt could be re-written as follows,
// Code within the monitor class
   public void onLoad() {
     EventExpression eventExpr
       = new EventExpression("NewsItem(*,*) -> Tick(*,*)");
     eventExpr.addMatchListener(matchListener1);
  }
 
// Code within the first (and only) Match Listener class – matchListener1
   public void match(MatchEvent event) {
     System.out.println("Detected a NewsItem followed"
       + " by a Tick event, both regarding any company.");
  }
The event expression definition for eventExpr no longer consists of a single event template. It now has multiple clauses and contains a temporal operator.
In this case, the operator used is ->, or the followed-by operator. This is the primary temporal operator for use in event expressions. It allows a developer to express a sequence of events to match against within a single listener, with the listener triggering once the whole sequence is encountered.
In Java, an event sequence does not imply that the events have to occur right after each other, or that no other events are allowed to occur in the meantime.
For the sake of brevity, let A, B, C and D represent event templates, and A', B', C' and D' be individual events that match those templates, respectively. If a listener is created to seek the event expression (A -> B), the event feed {A',C',B',D'} would result in a match once the B' is received by the correlator.
Followed-by operators can be chained to express longer sequences. Therefore you could write,
A -> B -> C -> D
within an event expression definition.
The next section focuses on the use of temporal operators in event expressions.