WebSphere WebSphere Enterprise Service Bus, Version 6.0.1 Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

Creating and populating an event

After obtaining an event factory, you can create event objects and populate them with property data.

Why and when to perform this task

Most event properties are defined as optional by the Common Base Event specification, but the following properties are required:
Note: The version attribute is defined as optional by the Common Base Event specification, but if it is not specified, the default value 1.0 is assumed. Because the Common Event Infrastructure supports only version 1.0.1 of the specification, this value must be specified.

If you try to send an event that is missing any of these properties, the emitter rejects the event and throws an EventsException exception.

The following code fragment creates an event and populates it with the minimal required property data:

CommonBaseEvent event = eventFactory.createCommonBaseEvent();

event.setVersion("1.0.1");                     // set version

long currentTime = System.currentTimeMillis(); // get current time
event.setCreationTimeAsLong(currentTime);      // and set creationTime

// set sourceComponentId (a complex type) 
event.setSourceComponentId("Windows",          // application
                           "svchost.exe",      // component
                           "tlntsvr.exe",      // subcomponent
                           "http://www.ibm.com/namespaces/autonomic/Windows",
                                               // componentType
                           "win386_svc",       // componentIdType
                           "9.45.72.138",      // location
                           "IPV4"              // locationType
                           );

// create situation object
Situation situation = eventFactory.createSituation();

// set situationType to AvailableSituation (a complex type)
situation.setAvailableSituation("EXTERNAL",          // reasoningScope
                                "NOT AVAILABLE",     // availabilityDisposition
                                "STARTABLE",         // operationDisposition
                                "FUNCTION_PROCESS"); // processingDisposition

// set situation
event.setSituation(situation);

This example first uses an event factory to create a new event instance, event. First it sets the version property; then it retrieves the current system time and uses the setCreationTimeAsLong(long) method to set the value of the creationTime property. An alternative is to use the setCreationTime(String) method, which sets the creation time using the XML dateTime format (for example, "2004-07-29T13:12:00-05:00").

The next required property, sourceComponentId, is a complex property represented by an instance of ComponentIdentification, which has properties of its own. However, it is not necessary to directly instantiate or interact with this object (although it is possible to do so). Instead, the next statement in the example uses a helper method, setSourceComponentId(), to specify the nested properties; the helper method uses these values to create an instance of ComponentIdentification, which it then uses to set the value of the sourceComponentId property of the event.

Similar helper methods exist for setting other complex properties (for example, setMsgDataElement(), addAssociatedEvent, and addExtendedDataElement()). Many of these methods exist in multiple versions with different signatures, making it possible to specify property values in different ways. Refer to the Javadoc API documentation for complete information on these methods.

The last required property in the example, Situation, is another complex property. In this case the situation object must be instantiated directly using an event factory; the example then uses a helper method to set the situationType property, which is itself a complex subelement.

In an actual application, a useful event needs to include more information than is shown here, but this is the minimum required by the Common Base Event specification and the Common Event Infrastructure. The event is now valid and can be submitted to an emitter.


Task topic

Terms of Use | Rate this page

Timestamp iconLast updated: 13 Dec 2005
http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.websphere.wesb.doc\doc\tcei_admin_populatingEvent.html

(C) Copyright IBM Corporation 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)