Apama Documentation : Developing Apama Applications : Developing Apama Applications in EPL : Implementing Parallel Processing : Spawning to contexts
Spawning to contexts
In a monitor, you can spawn to a context. The format for doing this is as follows:
spawn ActionIdentifier([ArgumentList]) to ContextExpression;
Replace ContextExpression with any valid EPL expression that is of the context type. Typically, this is the name of a context variable. It is possible to spawn to only a context; it is not possible to spawn to a channel.
This statement asynchronously creates a new monitor instance in the target context. The correlator can immediately create the new monitor instance and begin processing it. The correlator does not need to finish processing the monitor instance that spawned to the context before it starts processing the spawned instance. The correlator might create the spawned monitor instance before it finishes processing the action that spawned the new instance. Or, the correlator might create the spawned monitor instance some time after it completes processing the action that spawned the new instance. The order is unpredictable. For example:
action analyse(string symbol) {
   context c:=context(symbol);
   spawn submon(symbol) to c;
   ...
}
action submon(string symbol) {
   ...
}
If the target context does not yet exist, the correlator creates it.
It is possible for an operation that spawns to a context to block if the input queue of the target context is full. See Deadlock avoidance when parallel processing.
Like the regular spawn operation, the spawn...to operation does the following:
*Creates a new monitor instance by taking a deep copy of all of the spawning monitor instance's global variables
*Does not copy any listeners into the new monitor instance
*Runs the specified action in the new monitor instance
For general information about spawning, see Spawning monitor instances.
Unlike the regular spawn operation, the correlator runs the new monitor instance in the specified context. The correlator concurrently processes the new monitor instance and the instance that spawned it.
A context processes spawn operations and events in the order in which they arrive. For example, suppose a monitor contains the following statements:
spawn action1() to ctx;
send e1 to ctx;
spawn action2() to ctx;
send e2 to ctx;
The ctx context processes this in the following order: action1(), e1, action2(), e2.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback