Apama 10.7.2 | Developing Apama Applications | Developing Apama Applications in EPL | Using Correlator Persistence | Sample code for persistence applications | Sample code that recovers subscription to non-persistent monitor
 
Sample code that recovers subscription to non-persistent monitor
This sample code defines a persistent monitor that subscribes to a non-persistent service monitor. Note that the service monitor can handle the case where the subscription is received before the adapter is connected.
monitor service_monitor {
boolean connected;
sequence <Subscribe> pendingSubscribes;
action onload() {
on all Subscribe() as s {
if not connected {
pendingSubscribes.append(s);
} else {
if(incrRefCount(s.subkey)) {
send Adapter_Subscribe(s.subkey) to "output";
}
}
}
on all wait(1.0) {
send IsAdapterUp() to "output";
}
on all AdapterUp() {
connected:=true;
Subscribe s;
for s in pendingSubscribes {
route s;
}
pendingSubscribes.clear();
}
}
action incrRefCount(string subkey) returns boolean {
return false; }
}

persistent monitor eg2 {
listener l;
Instance i;
context svcCtx;
action spawnedInstance(context c) {
svcCtx:=c; // Contains anything required to recover subscription.
send Subscribe(i.subkey) to svcCtx;
l:=on all Data() as d { process(d); }
}
action onConcludeRecovery() {
// Non-persistent service monitor is now reset to its onload state.
// Re-subscribe.
send Subscribe(i.subkey) to svcCtx;
}
}