Apama 10.7.2 | Developing Apama Applications | Developing Apama Applications in EPL | Defining Monitors | Spawning monitor instances | About executing ondie() actions
 
About executing ondie() actions
A monitor instance can terminate for any of the following reasons:
*It executes all its code and has no active listeners or streaming elements.
*It executes a die statement in one of its actions.
*The engine_delete utility or an Apama client API removes the monitor from the correlator.
*A runtime error is detected in the monitor's code, which causes that instance of the monitor to die.
In all of these situations, if the monitor defines an ondie() action, the correlator invokes it. Like the onload() and onunload() actions, ondie() is a special action because the correlator invokes it automatically in certain situations.
Suppose that a monitor that defines the ondie() action spawns ten times, and each monitor instance dies. The correlator invokes ondie() eleven times: once for each spawned monitor instance, and once for the initial monitor instance. Then, just before the monitor's EPL is unloaded from the correlator, the correlator invokes the onunload()action only once, and it does so in the context of the last remaining monitor instance.
The correlator executes each ondie() operation in the context of its monitor instance. Therefore, the ondie() operation can access the variables in the monitor instance being terminated.
You cannot spawn in an ondie() or an onunload() action.
There are two forms of the ondie action: one form can have no argument and the other form can have optional<com.apama.exceptions.Exception> and optional<string> arguments. If the monitor instance terminates due to an uncaught exception, this exception is passed as a first argument to the ondie action. The second argument of the ondie action is populated with the reason if monitor instance terminated without an exception. Constants for the reason string are defined on the monitor type. See the API Reference for EPL (ApamaDoc) for more information.
Example:
action ondie(optional<com.apama.exceptions.Exception> exc, optional<string>
reasonCode) {
ifpresent exc {
// do something
}
ifpresent reasonCode {
if reasonCode = monitor.DIE or reasonCode = monitor.NO_LISTENERS
or reasonCode = monitor.ENGINE_DELETE {
//do something
}
}
}