class StockTick { 
    name :: STRING
    price :: FLOAT
    def StockTick(n, p){
        name = n
        price = p
    }
} 
class SimpleShareSearch : CEPMonitor {
	newTick :: StockTick // Save the latest StockTick event
	// Define constructor
	def SimpleShareSearch(){
		newTick = StockTick("init", 0.0)
	}
	def processTick(stockTickEvent)
	// After creating the CEP sub-engine, the system will automatically instantiate the SimpleShareSearch class as the monitor and call the onload function
	def onload() {
		// Listen for StockTick events
		addEventListener(handler=processTick, eventType="StockTick", times="all")
	}
	// Callback function executed after receiving the StockTick event, which logs the related information of StockTick
	def processTick(stockTickEvent) { 
		newTick = stockTickEvent
		str = "StockTick event received" + 
			" name = " + newTick.name + 
			" Price = " + newTick.price.string()
		writeLog(str)
	}
}

dummy = table(array(STRING, 0) as eventType, array(BLOB, 0) as eventBody)
try { dropStreamEngine(`simpleMonitor)} catch(ex) {}
createCEPEngine(name="simpleMonitor", monitors=<SimpleShareSearch()>, dummyTable=dummy, eventSchema=[StockTick])

stockTick1 = StockTick('600001',6.66)
getStreamEngine(`simpleMonitor).appendEvent(stockTick1)
stockTick2 = StockTick('300001',1666.66)
getStreamEngine(`simpleMonitor).appendEvent(stockTick2)