Apama 10.15.0 | Developing Apama Applications | Developing EPL Plug-ins | Writing EPL Plug-ins in Python | Creating a plug-in using Python | Sending events
 
Sending events
Method calls on plug-ins are synchronous. Generally, they should be written not to take too long or hold up processing in the correlator. One technique to enable asynchronous behavior in the plug-in is to interact with EPL by sending events which can be handled asynchronously, potentially from a background thread which is processing events as well as from methods themselves.
The apama.eplplugin.Correlator class contains several methods for sending events into the correlator. You can send events either as the string representation of the event in Apama's internal string format (for example, MyEvent(1.3, true)) or as a dictionary either with the event type specified explicitly or as an apama.eplplugin.Event type. In the dictionary case, the keys are strings corresponding to field names in the event, and the values are the value for those fields in the appropriate type/format for the type of the field.
You can select the destination of the event in two ways:
*Named channel. The preferred method is to deliver the event to a specific named channel. This will go to everything which has subscribed to that named channel. Subscribers can either be contexts, external receivers, connectivity chains or other plug-ins which are subscribed to receive events on that channel.
Send as string:
Correlator.sendTo("channelName", "MyEvent(42)")
Send as object:
event = {}
event["number"] = 42
Correlator.sendTo("channelName", event, type="MyEvent")
*Context. You can deliver the event to a specific context using an apama.eplplugin.Context object. Contexts can either be passed into a plug-in from an EPL context object, or they can be obtained with the apama.eplplugin.Correlator.getCurrentContext() method.
Send as string:
Correlator.sendTo(Correlator.getCurrentContext(), "MyEvent(42)")
Send as object:
apama.eplplugin.Event event;
event.fields["number"] = 42
event.type = "MyEvent"
Correlator.sendTo(contextObject, event)