Developing Apama Applications > Developing Apama Applications in EPL > Implementing Parallel Processing > Obtaining context references
Obtaining context references
To obtain a reference to the context that a piece of code is running in, call the context.current() method. This is a static method that returns a context object that is a reference to the current context. The current context is the context that contains the EPL that calls this method.
For a monitor instance to interact with the EPL in another context, the monitor instance must have a reference to that context. A monitor instance can obtain a reference to another context in only the following ways:
*By creating the context.
*By receiving a context reference, which must be of type context. A monitor instance can receive this reference by means of a routed or enqueued event, or a spawn operation.
For example:
Calculate calc;
on all Calculate():calc {
   integer calcId:=integer.getUnique();
   spawn doCalculation(calc, calcId, context.current())
      to context(“Calculation”);
do something
}
action doCalculation(Calculate req, integer id, context caller) {
   do something   
enqueue CalculationResponse(id, value) to caller;
}
If a monitor instance that creates a context does not send a context reference outside itself, no other context can send events to that context, except by means of correlator plug-ins. This affords some degree of privacy for the context.
A context object (a context reference) does not do anything. It is simply the target of the following:
*spawn ActionIdentifier([ArgumentList]) to ContextExpression;
See Spawning to contexts.
*enqueue EventExpression to ContextExpression;
See Enqueuing an event to a particular context.
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.