Developing Apama Applications > Developing Apama Applications in EPL > Implementing Parallel Processing > Sending an event to a particular context
Sending an event to a particular context
In a monitor, you can send an event to a particular context, as described here, or you can send an event to a sequence of contexts, described in the next topic. The format for sending an event to a particular context is as follows:
send EventExpression to Expression;
or:
enqueue EventExpression to ContextExpression;
Note: The enqueue...to statement will be deprecated in a future release. Use the send...to statement. Both statements perform the same operation.
*Replace EventExpression with any valid EPL expression that is of an event type. You cannot specify a string representation of an event. For example, you cannot send &TIME pseudo-ticks.
*Replace Expression, in the first format, with any valid EPL expression that is of the context type or with a com.apama.Channel object that contains a context. See Sending events to com.apama.Channel objects.
*Replace ContextExpression with any valid EPL expression that is of the context type. This can be the name of a context variable or a method that returns a context. This cannot be a com.apama.Channel object that contains a context.
This statement asynchronously sends an event to the specified context. The event goes to the back of the context’s input queue.
In the target context, the correlator can immediately process the sent event. The correlator does not need to finish executing the action that sent the event before it processes the sent event in the target context. The correlator might process the sent event before it finishes executing the action that sent the event. Or, the correlator might process the sent event some time after it completes executing the action that sent the event. The order is unpredictable. The order in which the target contexts receive the sent event is also unpredictable. For example:
action analyse(string symbol) {
   context c:=context(symbol);
   spawn submon(symbol) to c;
   com.apama.marketdata.Tick tick;
   log "Listening for "+symbol;
   on all com.apama.marketdata.Tick(symbol=symbol):tick {
      send tick to c;
   }
   on com.apama.marketdata.Finished() {
      send com.apama.marketdata.Finished() to c;
   }
}
action submon(string symbol) {
   ...
}
The send...to and enqueue...to statements do not place the event on the special enqueued events queue. Instead, they put the event on the end of the target context’s input queue. Consequently, it is possible for a send...to or enqueue...to operation to block the sending context from further processing if the input queue of the target context is full. Either an event that you send to a particular context arrives on the target context’s input queue or the sending context waits for room on the target context’s input queue.
If you send an event to a context that does not contain any monitor instances, the correlator discards the event because there are no listeners for it.
If you do not have a reference to a particular context, then send an event to a channel. See Generating events with the send command.
In some situations, for example when you change a single-context application to use parallel processing, you might want to explicitly send an event to only the context that contains the monitor instance that contains the send statement. To send an event to only this context specify:
send eventExpression to context.current()
You must set a valid value to a context variable before you send an event to the context. You cannot send an event to a context that you have declared but has not been set to a valid value. For example, the following code causes the correlator to terminate the monitor instance:
monitor m {
   context c;
   action onload()
   {
      send A() to c;
   }
}
See also Generating events with the enqueue command. and Generating events with the send command.
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.