Developing Apama Applications > Developing Apama Applications in EPL > Using Correlator Persistence > Sample code for persistence applications > Sample code for discarding stale state during recovery
Sample code for discarding stale state during recovery
The following code provides an example of discarding stale data during recovery. This application discards all recovered Data events because their data has become stale. However, the application always processes and does not discard ControlEvent events.
persistent monitor eg1 {
listener l;
listener lt;
action onload {
initializeState();
initiateListeners();
ControlEvent c;
on all ControlEvent():c { handleControl(c); }
}
action initiateListeners;
Data d;
l:=on all Data():d { process(d); } // Process is moderately expensive
lt:=on all wait(0.1) { emit Average(state); }
}
action onBeginRecovery() {
l.quit(); // Discard all recovered Data events.
lt.quit(); // Stop sending intermittent updates.
// Do not flood receivers.
// Note that the ControlEvent listener is still present.
// The code throttles only Data events. If the
// ControlEvent listener is not present, this monitor
// would have no listeners and would terminate
// after this action.
}
action onConcludeRecovery() {
initiateListeners(); // Go back to normal.
}
}
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.