Apama 10.7.2 | Developing Apama Applications | Developing Apama Applications in EPL | Using Correlator Persistence | Sample code for persistence applications | Sample code for recovery behavior based on downtime duration
 
Sample code for recovery behavior based on downtime duration
The following sample is the same as the discard-stale-data sample with some changes that provide a downtime policy. Downtime is the duration between the last committed snapshot and the time of day upon recovery.
This code sample ignores downtimes that are less than two hours. However, if recovery starts just under the two-hour limit the processing of old data might appear to be beyond the two hour threshold. The downtime policy must take this into account.
persistent monitor eg1 {
import "TimeFormatPlugin" as timeFormatPlugin;
// ... onload() and so on
listener l;
listener lt;
action onload() {
initiateListeners();
// on all ControlEvent() as c { handleControl(c); }
}
action initiateListeners() {
// l:=on all Data() as d { process(d); } // Process is moderately expensive
//lt:=on all wait(0.1) { send Average(state) to "output"; }
}
boolean longDowntime;
action onBeginRecovery() {
// currentTime is the time of the last snapshot, which is
// approximately when the correlator went down.
// timeFormatPlugin.getTime() is the actual time of recovery.
if (timeFormatPlugin.getTime() - currentTime > (60.0 * 60.0 * 2.0) )
{
// If we were down for less than 2 hours, pretend nothing
// happened. For longer gaps, skip stale data as it will be
// too expensive to process it.
longDowntime:=true;
log "Correlator was down for a long time - will discard stale
data.";
l.quit(); // Discard all recovered Data events.
lt.quit(); // Stop sending intermittent updates.
// Do not flood receivers.
}
}
action onConcludeRecovery() {
if longDowntime {
longDowntime:=false;
initiateListeners(); // Go back to normal.
}
}
}