Developing Apama Applications > Developing Apama Applications in EPL > Defining What Happens When Matching Events Are Found > Generating events > Generating events with the enqueue command
Generating events with the enqueue command
The enqueue command generates an event and places the event on a special queue just for events generated by the enqueue command. A separate thread moves these events to the input queue of each public context. This arrangement ensures that if the input queue of a public context is full, the event generated by enqueue still arrives on its special queue, and is moved to each public context's input queue as soon as that queue has room. Active listeners will eventually receive events that are enqueue’d, once those events make their way to the head of the input queue alongside normal events.
There are two formats available for using enqueue. You can directly enqueue an event, as the example below does first, or else place the event in a string and enqueue that. If you use this latter format, you must ensure that you define the string to represent a valid event.
Use the enqueue statement when you want to ensure that the correlator processes the generated event after it has processed all routed events. Note that other external or enqueued events may be processed prior to processing this enqueued event. To defer processing an event until after processing of all routed events, enqueueing to context.current() might be preferable. The enqueue statement is also useful when you want to send events into all public contexts.
For example, consider a further revised version of the earlier example:
event StockTickPriceChange {
   string owner;
   string name;
   float price;
}
 
// A new processTicks action that dispatches an event to
// the input queue instead of logging
action processTicks() {
 
// The following enqueue format sends the event itself.
   enqueue StockTickPriceChange(currentStock.owner,
     newTick.name, newTick.price);
 
// Or, use the following enqueue format, which sends a string that
// contains the event.
   enqueue "StockTickPriceChange(\""+currentStock.owner+
    "\",\""+newTick.name+"\", "+newTick.price.toString()+")";
}
If the string does not represent an event that fully complies with an event type that has been defined elsewhere in EPL then it will be thrown away before being placed on the input queue. This is the same behavior as for any normal event received by the correlator. Unless the correlator understands its event type (by having had it defined in EPL) it ignores it.
You cannot enqueue the following events:
*An event whose type is defined inside a monitor.
*An unroutable event type, that is, an event type that contains a field whose type is something other than a primitive type, a location type, or a context type.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.