Developing Apama Applications > Developing Apama Applications in EPL > Defining What Happens When Matching Events Are Found > Getting the current time
Getting the current time
In the correlator, the current time is the time indicated by the most recent clock tick. However, there are some exceptions to this:
*If you specify the -Xclock option when you start the correlator, the correlator does not generate clock ticks. Instead, you must send time events (&TIME) to the correlator. The current time is the time indicated by the most recent received, externally generated, time event. See Generating events that keep time.
*If you have multiple contexts, it is possible for the current time to be different in different contexts. A particular context might be doing so much processing that it cannot keep up with the time ticks on its queue. In other words, if contexts are mostly idle, then they would all have the same current time.
*When the correlator fires a timer, the current time in the context that contains the timer is the timer’s trigger time. See About timers and their trigger times.
The information in the remainder of this topic assumes that the current time is the time indicated by the most recent clock tick.
Use the currentTime variable to obtain the current time, which is represented as seconds since the epoch, January 1st, 1970 in UTC. The currentTime variable is similar to a global read-only constant of type float. However, the value of the currentTime variable is always changing to reflect the correlator’s current time.
In the correlator, the current time is never the same as the current system time. In most circumstances it is a few milliseconds behind the system time. This difference increases when the input queues of public contexts grow.
When a listener executes an action, it executes the entire action before the correlator starts to process another event. Consequently, while the listener is executing an action, time and the value of the currentTime variable do not change. Consider the following code snippet,
float a;
action checkTime() {
   a := currentTime;
}
 
// ... Lots of additional code
// A listener calls the following action some time later
action logTime() {
   log a.toString(); // The time when checkTime was called
   log currentTime.toString(); // The time now
}
In this code, an event listener sets float variable a to the value of currentTime, which is the time indicated by the most recent clock tick. Some time later, a different event listener logs the value of a and the value of currentTime. The values logged might not be the same. This is because the first use of currentTime might return a value that is different from the second use of currentTime. If the two event listeners have processed the same event, the logged values are the same. If the two event listeners have processed different events, the logged values are different.
Copyright © Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its Subsidiaries and or/its Affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.