Query historical events
------------------------------------------------------------------------
public boolean start() {
boolean result = true;
try {
//Get Event Access EJB
…
//get OTMPS start events
CommonBaseEvent [] mmStartCbes =
eAccessEjb.queryEventsByEventGroup(EventSelectors.START_EVENT_GROUP,
EventSelectors.MILESTONEMANAGER_EVENT_SELECTOR, true);
//for every start event get the related events and
//initialize the corresponding metric classes
for (int i = 0; i < mmStartCbes.length; i++) {
// create OTMPSStartEvent
OTMPSStartEvent otmpsStartEvent = new
OTMPSStartEvent(mmStartCbes[i]);
// get the context id from the start event
String contextId = otmpsStartEvent.getContextId();
//complete the context event selector
Object [] args = {contextId};
String contextEventSelector =
EventSelectors.contextEventSelector.format(args);
// get the corresponding stop event
CommonBaseEvent [] stopCbes =
eAccessEjb.queryEventsByEventGroup(EventSelectors.STOP_EVENT_GROUP,
contextEventSelector, true);
//if the process instance has not stopped yet then
skip to the next instance we will revisit this process instance when we
receive the stop event
if (stopCbes.length > 0) {
OTMPSStopEvent otmpsStopEvent = new
OTMPSStopEvent(stopCbes[0]);
//get the corresponding orders data event
CommonBaseEvent [] ordersDataCbes =
eAccessEjb.queryEventsByEventGroup(EventSelectors.ORDERS_DATA_EVENT_GRO
UP, contextEventSelector, true);
OrdersDataEvent ordersDataEvent = new
OrdersDataEvent(ordersDataCbes[0]);
//create ThroughPut metric and add it to
ThroughPutCollection
ThroughPut throughPut = new
ThroughPut(otmpsStartEvent, ordersDataEvent, otmpsStopEvent);
ThroughPutCollection.eINSTANCE.addMetric(throughPut);
//create Outcome metric and add it to
OutcomeCollection
Outcome outcome = new Outcome(otmpsStopEvent);
OutcomeCollection.eINSTANCE.addMetric(outcome);
//get the corresponding invalid orders data
event which is created by a sub-process therefore we need to first get
the sub-process start
String validationSubprocessEventSelector =
EventSelectors.validationSubprocessEventSelector.format(args);
CommonBaseEvent [] vpStartCbes =
eAccessEjb.queryEventsByEventGroup(EventSelectors.START_EVENT_GROUP,
validationSubprocessEventSelector, true);
if (vpStartCbes.length > 0){
// get the context id from the start
event
String vpContextId =
Event.getContextId(vpStartCbes[0]);
//complete the context event selector
Object [] vpArgs = {vpContextId};
String vpContextEventSelector =
EventSelectors.contextEventSelector.format(vpArgs);
CommonBaseEvent [] invalidOrdersDataCbes = eAccessEjb.queryEventsByEventGroup
(EventSelectors.INVALID_ORDERS_DATA_
EVENT_GROUP, vpContextEventSelector, true);
if (invalidOrdersDataCbes.length > 0) {
InvalidOrdersDataEvent
invalidOrdersDataEvent = new InvalidOrdersDataEvent
(invalidOrdersDataCbes[0]);
//create NumberOfInvalidOrders
metric and add it to NumberOfInvalidOrdersCollection
NumberOfInvalidOrders
numberOfInvalidOrders = new
NumberOfInvalidOrders(invalidOrdersDataEvent);
NumberOfInvalidOrdersCollection.eINSTANCE.addMetric(numberOfInvalidOrders);
}
}
}
}
//get ExceptionHandler start events
CommonBaseEvent [] ehStartCbes =
eAccessEjb.queryEventsByEventGroup(EventSelectors.START_EVENT_GROUP,
EventSelectors.EXCEPTIONHANDLER_EVENT_SELECTOR, true);
//for every start event get the related events and
//initialize the corresponding metric classes
…
} catch (Exception e) {
e.printStackTrace(System.out);
result = false;
}
return result;
}
|