CEI provides an event access interface that you can use to query historical events. In order to query events, you need to specify an event group and, optionally, an event selector (see the sidebar Event selectors and event groups for more information). CEI includes an application -- CBEViewer -- that you can use to query events based on the specified event group. But before you can create an event group, you need to test the corresponding event selector. In addition, you might also want to test an event selector along with an event group before using such a combination in the code. This paper presents an application -- EventTester -- that you can use to test event selectors, event groups, and event groups with event selectors. It also shows you how to use this application in combination with the CBEViewer application to create event selectors.
CEI supports a subset of XPath syntax to query events. You can query events using the Event Access interface, which the EventAccess session bean imiplements. You can create an instance of the EventAccess bean using the corresponding home interface, as Listing 1 shows.
Listing 1. Create an instance of EventAccess bean
// use home interface to create remote event access bean
InitialContext context = new InitialContext();
Object eventAccessHomeObj =
context.lookup("ejb/com/ibm/events/access/EventAccess");
EventAccessHome eventAccessHome = (EventAccessHome)
PortableRemoteObject.narrow(eventAccessHomeObj,
EventAccessHome.class);
eventAccess = (EventAccess) eventAccessHome.create();
|
The Event Access interface supports the following ways to query events:
- Global instance identifier -- Get the event using its
globalInstandIdevent property that can be used as a primary key.
CommonBaseEvent event =
eventAccess.queryEventByGlobalInstanceId(eventId);
- Event group -- Retrieve events that belong to a specified event group and (optionally) meet a criterion which is specified using an event selector. The
ascendingOrderparameter is used to order events in either ascending or descending order according to creation time. ThemaxEventparameter is used to specify the maximum number of events to be returned from the event query.
CommonBaseEvent[] events =
eventAccess.queryEventsByEventGroup(eventGroup, eventSelector,
- Association type -- Retrieve the associated events by
associationTypefor a given event. An event can have other related or associated events. An association type attribute defines the relationship type such as:contains,cleared,causedBy,multiPart, orcorrelated.
CommonBaseEvent[] events =
eventAccess.queryEventsByAssocation(associationType,
eventId);
The EventTester application is an Event Access interface-based application that you can use to test event selectors and event groups. Complete code is available in the Download section (click the code icon at the top or bottom of this paper to download). Figure 1 shows the graphic user interface for the application. Given an event group and an event selector, this application returns the corresponding events. You can also test an event selector separately by using the default value for event group, or All events. Similarly, you can test an event group separately by using the default value for event selector, or CommonBaseEvent[@globalInstanceId]. The events are shown in a table format, with each row representing an event.
Figure 1. Event Tester application

The application includes a Java Server Page (JSP) and a servlet. Listing 2 and Listing 3 (code listings appear in sidefiles) show the JSP and the servlet code for the application, respectively. The JSP provides the front-end for the application. When you click the Display Events button, it invokes the DisplayEvents servlet. This servlet uses the Event Access interface to query the events and forwards the result to the JSP. The JSP then formats the events and presents them to the user. In order to format the events, the JSP assumes that the events are CBE version 1.0.1 (for details on CBE, refer to Standardize messages with the Common Base Event model in the Resources section).
Using the EventTester application
You can use the EventTester application with or without the CBEViewer application. Since CBEViewer has a better user interface and filtering mechanism, I recommend using the EventTester application with the CBEViewer application. You can first use the CBEViewer to query all events (using the All Events event group) and understand the structure or pattern of the events in which you are interested, then create the corresponding XPath query and test it using the EventTester application.
For example, let?s say you have a process called MileStoneManager, which is marked as "BusinessRelevant;" in other words, it emits an event whenever it starts and stops, and you are interested in querying all the start and the corresponding stop events. In order to understand the structure of the events, you use the CBEViewer application. Figure 2 shows the required events in CBEViewer, and Figure 3 and Figure 4 show their details. From the start event details, you can see that the extensionName for the event is "WPC:ProcessInstanceEvent." It has an extendedDataElement called "processTemplateName" that shows that this event was emitted by MileStoneManager, and the categoryName for the situation is "StartSituation," which indicates that this event was emitted when process started. Similarly, from the stop event details, you can see that the extensionName for this event is also "WPC:ProcessInstanceEvent." It does not have any field that indicates that this event was emitted by MileStoneManager, but its contextDataElement is the same as the contextDataElement for the start event, and the categoryName for the situation is "StopSituation."
Figure 2. CBEViewer application

Below are the details of the MileStoneManager start event:
Table 1. MileStoneManager start event details
| Name | Value |
| version | -1.0.1 |
| globalInstanceId | CEC05DB5C52F6E90339824ECD0334F11D9 |
| extensionName | WPC:ProcessInstanceEvent |
| localInstanceId | |
| creationTime | 2004-11-10T19:34:53.213Z |
| severity | 10 |
| msg | |
| priority | - |
| sequenceNumber | 1 |
| repeatCount | 0 |
| elapsedTime | 0 |
| ContextDataElement: ECSCurrentID / contextValue | _PI:10030100.23fb340d.ac3cd9f6.136200b8 |
| ContextDataElement: ECSParentID / contextValue | _PI:10030100.23fb33fe.ac3cd9f6.136200a6 |
| ExtendedDataElement: Username | UNAUTHENTICATED |
| ExtendedDataElement: processTemplateName | MileStoneManager |
| ExtendedDataElement: processTemplateId | _PT:90010100.22fcafbd.ac3cd9f6.cfc80161 |
| ExtendedDataElement: processInstanceId | _PI:10030100.23fb340d.ac3cd9f6.136200b8 |
| ExtendedDataElement: processInstanceExecutionState | 2 - STATE_RUNNING |
| ExtendedDataElement: processTemplateValidFrom | Wed 2003-01-01 00:00:00.000 |
| reporterComponentId | |
| sourceComponentId / component | WBI-SF#Platform 5.1 [BASE 5.1.1 a0426.01] [JDK 1.4.1 ${build.level}] [PME 5.1.1 o0429.02] |
| sourceComponentId / subComponent | WPC |
| sourceComponentId / componentIdType | ProductName |
| sourceComponentId / instanceId | localhost\localhost\server1 |
| sourceComponentId / application | |
| sourceComponentId / executionEnvironment | Windows 2000[x86]#5.0 |
| sourceComponentId / location | naveen.transarc.ibm.com |
| sourceComponentId / locationType | Hostname |
| sourceComponentId / processId | 1520 |
| sourceComponentId / threadId | Servlet.Engine.Transports : 0 |
| sourceComponentId / componentType | http://www.ibm.com/namespaces/autonomic/Workflow_Engine |
| msgDataElement | |
| situation / categoryName | StartSituation |
| situation / situationType / reasoningScope | EXTERNAL |
| situation / StartSituation / successDisposition | SUCCESSFUL |
| situation / StartSituation / situationQualifier | START_COMPLETED |
The following table outlines the MileStoneManager stop event details:
Table 2. MileStoneManager stop event details
| Name | Value |
| version | 1.0.1 |
| globalInstanceId | CEC05DB5C52F6E9033D38E4690334F11D9 |
| extensionName | WPC:ProcessInstanceEvent |
| localInstanceId | |
| creationTime | 2004-11-10T19:36:32.889Z |
| severity | 10 |
| msg | |
| priority | - |
| sequenceNumber | 1 |
| repeatCount | 0 |
| elapsedTime | 0 |
| ContextDataElement: ECSCurrentID / contextValue | _PI:10030100.23fb340d.ac3cd9f6.136200b8 |
| ContextDataElement: ECSParentID / contextValue | _PI:10030100.23fb340d.ac3cd9f6.136200b8 |
| ExtendedDataElement: WPCEventCode | 21004 |
| ExtendedDataElement: processInstanceExecutionState | 3 - STATE_FINISHED |
| reporterComponentId | |
| sourceComponentId / component | WBI-SF#Platform 5.1 [BASE 5.1.1 a0426.01] [JDK 1.4.1 ${build.level}] [PME 5.1.1 o0429.02] |
| sourceComponentId / subComponent | WPC |
| sourceComponentId / componentIdType | ProductName |
| sourceComponentId / componentIdType | localhost\localhost\server1 |
| sourceComponentId / application | |
| sourceComponentId / executionEnvironment | Windows 2000[x86]#5.0 |
| sourceComponentId / location | naveen.transarc.ibm.com |
| sourceComponentId / locationType | Hostname |
| sourceComponentId / processId | 1520 |
| sourceComponentId / threadId | Servlet.Engine.Transports : 0 |
| sourceComponentId / componentType | http://www.ibm.com/namespaces/autonomic/Workflow_Engine |
| msgDataElement | |
| situation / categoryName | StopSituation |
| situation / situationType / reasoningScope | EXTERNAL |
| situation / StopSituation / successDisposition | SUCCESSFUL |
| situation / StopSituation / situationQualifier | STOP_COMPLETED |
Based on the start event details, you can create the following event selector to query all the MileStoneManager start events:
CommonBaseEvent[extensionName='WPC:ProcessInstanceEvent'] and extendedDataElement[name='processTemplateName' and type='string' and values='MileStoneManager'] and situation[categoryName='StartSituation'] |
You can test this event selector using the EventTester application, as Figure 3 shows. The page displays the details of the event based on the above event selector. Now that you have verified that the event selector works, you can create the corresponding event group -- MileStoneManagerStartEventGroup (for details on how to create event groups, refer to "On demand business process life cycle, Part 8: Business process monitoring -- Create key performance indicators" in the Resources section), and test it again using the EventTester application.
Figure 3. Testing the start event selector

To query the stop event for a given start event, you can use the following event selector:
CommonBaseEvent[extensionName='WPC:ProcessInstanceEvent' and situation[categoryName='StopSituation'] and contextDataElements[name='ECSCurrentID' and type='ECSID' and values='<start event values>']] |
where <start event values> ( such as PI:10030100.23fb340d.ac3cd9f6.136200b8) is specified at run-time.
Since event groups can only be created for static event selectors, you cannot create an event group corresponding to this event selector. But you can break this event selector into two event selectors, as shown below:
CommonBaseEvent[extensionName='WPC:ProcessInstanceEvent' and situation[categoryName='StopSituation']]CommonBaseEvent[contextDataElements[name='ECSCurrentID' and type='ECSID' and values='<start event values>']]
Now you can create ProcessStopEventGroup, corresponding to the first event selector, and use it with the second event selector to query the appropriate stop event (for details on how to create event groups, refer to "On demand business process life cycle, Part 8: Business process monitoring -- Create key performance indicators" in the Resources section). But before you write the corresponding code, you can use the EventTester application to test this scenario as well, as Figure 4 shows.
Figure 4. Testing the stop event selector

In this paper, you learned how to build a Common Event Infrastructure (CEI) -based application for testing event groups and event selectors. You learned how this application uses the event access interface for querying historical events based on the specified event selector and event group amd how to use create event selectors for the processes that are marked as "Business Relevant."
| Description | Name | Size | Download method |
|---|---|---|---|
| Event tester WAR file | ws-ceicode.zip | 9 KB | HTTP |
Information about download methods
- Visit the Information center for WebSphere Business Integration Server Foundation -- Writing event selectors to learn more about XPath restrictions.
- Learn how to create event groups in the paper "On demand business process life cycle, Part 8: Business process monitoring -- Create key performance indicators" (developerWorks, March 2005).
- Learn more about the Common Base Event model in the paper "Standardize messages with the Common Base Event model" (developerWorks, February 2004).
- Browse for books on these and other technical topics.
- Get involved in the developerWorks community by participating in
developerWorks blogs.
- The IBM developerWorks team hosts hundreds of technical briefings around the world which you can attend at no charge.
- Want more? The developerWorks SOA and Web services zone hosts hundreds of informative articles and introductory, intermediate, and advanced tutorials on how to develop Web services applications.
Naveen Sachdeva is an Advisory Software Engineer with the IBM Application Integration Middleware group. He has over 10 years of experience in large-scale systems integration and in the design and development of distributed computing systems. He currently helps IBM business partners with technical enablement and proof-of-concept using the WebSphere Studio family of products.




