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 {
action onload {
Subscribe s;
on all Subscribe():s {
if not connected then {
pendingSubscribes.append(s);
} else {
if(incrRefCount(s.subkey) then {
emit Adapter_Subscribe(s.subkey);
}
}
}
on all wait(1.0) {
emit IsAdapterUp();
}
on all AdapterUp() {
connected:=true;
for s in pendingSubsscribes {
route s;
}
pendingSubscribes.clear();
}
}
}

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