Apama 10.15.0 | Developing Apama Applications | Developing EPL Plug-ins | Writing EPL Plug-ins in C++ | Creating a plug-in using C++ | Sending events
 
Sending events
Method calls on plug-ins are synchronous and generally should be written not to take too long or hold up processing in the correlator (see Blocking behavior of plug-ins). 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 CorrelatorInterface returned from getCorrelator() 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 map_t type where the keys are strings corresponding to the field names in the event, and the values are the values for those fields, in the appropriate type/format for the type of the field. In the latter case, you also need to supply the name of the event type to parse the map as.
You can select the destination of the event in several 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 context, external receivers, connectivity chains or other plug-ins which are subscribed to receive events on that channel (see Receiving events).
Send as string:
getCorrelator().sendEventTo("MyEvent(42)", "channelName");
Send as object:
map_t event;
event.insert(data_t("number"), data_t(int64_t(42));

getCorrelator().sendEventTo("MyEvent", std::move(event), "channelName");
*Context by ID. You can deliver the event to a specific context by context ID. Context IDs can either be passed into a plug-in from an EPL context() object, or they can be obtained with the CorrelatorInterface.getCurrentContextId() method.
Send as string:
getCorrelator().sendEventTo("MyEvent(42)", ctxId);
Send as object:
map_t event;
event.insert(data_t("number"), data_t(int64_t(42));

getCorrelator().sendEventTo("MyEvent", std::move(event), ctxId);
You can send events from within a method called from EPL, from any callback handler method, or from threads spawned by the plug-in itself.