spawnMonitor

Syntax

spawnMonitor(name, handler, arguments...)

Details

Spawns additional monitor instances within a single monitor instance.

It implements the following steps:

  1. Creates a new instance of the monitor that is spawning.

  2. Deep copies all copyable attributes and functions from the spawning monitor instance.

  3. Executes the specified handler action in the new monitor instance.

Parameters

Name is a STRING scalar indicating the name of the spawned instance, which cannot be duplicate with an existing instance.

handler is the action to be invoked to process the events monitored by this spawned instance.

arguments is argument(s) passed to handler.

Returns

A monitor instance.

Examples

class NewStock {
    code :: STRING
    price :: DOUBLE
    def NewStock(c, p){
        code = c
        price = p
    }
}
class SimpleShareSearch : CEPMonitor { 
    numberTicks :: INT
    price :: DOUBLE
    stockName :: STRING
    def SimpleShareSearch(){
        stockName = ""
		numberTicks = 0
		price = 0.0
	}
    def matchTicks(newStock)
    def spawnTicks(newStock){
        numberTicks = numberTicks+1
        spawnMonitor("MonitorOf"+newStock.code, matchTicks, newStock)
    }
    // Listens for all NewStock events. When a NewStock event is detected, 
    // a new monitor instance is created by deep-copying the current monitor, and the matchTicks() method is executed.
    // This operation deep-copies the state of the current monitor.
    def onload() { 
        addEventListener(handler=spawnTicks, eventType="NewStock", times="all")
    } 
    def processTick(ticks)
    def matchTicks(newStock) { 
        stockName=newStock.code
        price = newStock.price
        addEventListener(handler=processTick, eventType="StockTick", condition=<StockTick.code==stockName>,times="all")
    } 
   def processTick(ticks) { 
		str = "StockTick event received" + 
			" name = " + ticks.code + 
			" Price = " + ticks.price.string()
		writeLog(str)
   } 
}