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 Java dummy context does not correspond to an actual correlator context. The Java 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 Java application and the event happens to have a context field that contains an irrelevant value. As with other Apama Java 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 Apama Java 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() {
...
ContextEvent req;
on all ContextEvent(*, true, *):req {
integer svcid;
...
context serviceContext := context("svc");
ContextEvent ack :=
ContextEvent(svcid, false, serviceContext);
route ack;
...
}
}
...
}
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.