emitEvent

Syntax

emitEvent(event, [eventTimeField], [outputName])

Details

An event sent by emitEvent asychronously goes to the end of the output queue. When multiple event stream serializers are specified in the CEP engine, emitEvent must specify the target serializer via the outputName parameter, which indicates the name of the StreamEventSerializer. The CEP engine matches the serializer accordingly and outputs the event to the corresponding one or more stream tables.

Parameters

event is an event instance.

eventTimeField is a STRING scalar indicating the time field of the event. To specify this parameter, event must contain a time field. If useSystem is set to true when creating the engine, the output events will be timestamped with the system time. If false, it will be output with the latest event time.

outputName(optional) is a STRING scalar specifying the name of the StreamEventSerializer.
  • If only one output table is specified in the CEP engine, this parameter is not required.
  • If multiple output tables are specified, outputName must be specified so that the engine can route the event to the corresponding serializer.

Returns

None

Examples

This example demonstrates how to specify different event stream serializers via the outputName parameter. The CEP engine matches the specified serializer and outputs events to the corresponding streamtables.
class MarketData{
    market :: STRING
    code :: STRING
    price :: DOUBLE
    qty :: INT
    def MarketData(m,c,p,q){
        market = m
        code = c
        price = p
        qty = q
    }
}

class Orders{
    trader :: STRING
    market :: STRING
    code :: STRING
    price :: DOUBLE
    qty :: INT
    def Orders(t, m,c,p,q){
        trader = t
        market = m
        code = c
        price = p
        qty = q
    }
}

class Trades{
    trader :: STRING
    market :: STRING
    code :: STRING
    price :: DOUBLE
    qty :: INT
    def Trades(t, m,c,p,q){
        trader = t
        market = m
        code = c
        price = p
        qty = q
    }
}

share streamTable(array(STRING, 0) as eventType, array(BLOB, 0) as blobs) as MarketDataChannel
serializer1 = streamEventSerializer(name=`MarketDataChannel, eventSchema=[MarketData], outputTable=MarketDataChannel)

share streamTable(array(STRING, 0) as eventType, array(BLOB, 0) as blobs) as OrdersChannel
serializer2 = streamEventSerializer(name=`OrdersChannel, eventSchema=[Orders], outputTable=OrdersChannel)

share streamTable(array(STRING, 0) as eventType, array(BLOB, 0) as blobs) as TradesChannel
serializer3 = streamEventSerializer(name=`TradesChannel, eventSchema=[Trades], outputTable=TradesChannel)

class SimpleShareSearch:CEPMonitor {
	// Constructor
	def SimpleShareSearch(){
	}
    // Specify the name of the event stream serializer to which the event should be sent via emitEvent
	def processMarketData(event){
        emitEvent(event,,"MarketDataChannel")
    }
    def processOrders(event){
        emitEvent(event,,"OrdersChannel")
    }
    def processTrades(event){
        emitEvent(event,,"TradesChannel")
    }
	// After the CEP sub-engine is created, the system automatically constructs a SimpleShareSearch object as a Monitor instance and invokes the onload function
	def onload() {

		addEventListener(handler=processMarketData, eventType="MarketData", times="all")
		addEventListener(handler=processOrders, eventType="Orders", times="all")
		addEventListener(handler=processTrades, eventType="Trades", times="all")
	}
}

dummy = table(array(STRING, 0) as eventType, array(BLOB, 0) as blobs)

// Create a CEP engine and specify three event stream serializers
engine = createCEPEngine(name='cep1', monitors=<SimpleShareSearch()>, dummyTable=dummy, eventSchema=[MarketData,Orders,Trades], outputTable=[serializer1,serializer2,serializer3])

m= MarketData("m", "c", 10.0, 100)

appendEvent(engine, m)

o = Orders("a","m", "c", 10.0, 100)
t = Trades("a","m", "c", 10.0, 100)

appendEvent(engine, o)
appendEvent(engine, t)