Using the Context class default constructor
The com.apama.jmon.Context class default constructor, public Context(), creates a dummy context that provides the same functionality as an uninitialized context variable in EPL. A JMon dummy context does not correspond to an actual correlator context. The JMon dummy context corresponds to the implicit context that is created in EPL for uninitialized context variables. The default constructor is provided for convenience. Use it when you want to enqueue an event to another context from a JMon application and the event happens to have a context field that contains an irrelevant value. As with other JMon types, this value cannot be null. Following is an example, beginning with the event definition:
import com.apama.jmon.*;
public class ContextEvent extends Event {
public long id;
public boolean req;
public Context c;
public ContextEvent(long id) {
this.id = id;
this.req = true;
this.c = new Context();
}
}
Here is the JMon application:
public class SampleJMonApp implements Monitor {
...
public void onLoad() {
...
ContextEvent req = new ContextEvent(service_id);
...
// send requests here
req.route();
...
EventExpression cexpr =
new EventExpression("all ContextEvent(*,false,*):ackEvt");
cexpr.addMatchListener(new MatchListener() {
public void match(MatchEvent event){
ContextEvent ackEvt =
(ContextEvent)event.getMatchingEvents().get("ackEvt");
// extract the context here
Context serviceContext = ackEvt.evt;
...
}
});
}
...
}
Here is the EPL application:
monitor ContextFactory
{
...
action onload() {
...
on all ContextEvent(*, true, *) as req {
integer svcid;
...
context serviceContext := context("svc");
ContextEvent ack :=
ContextEvent(svcid, false, serviceContext);
route ack;
...
}
}
...
}