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.
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 enqueued events in the order in which they arrive. For example, suppose a monitor contains the following statements:
spawn action1() to ctx;
enqueue e1 to ctx;
spawn action2() to ctx;
enqueue e2 to ctx;
The ctx context processes this in the following order: action1(), e1, action2(), e2.
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.