Use the createCommonBaseEvent method to create and populate an
event. The following code fragment starts a new event correlation
sphere, newECSID, and then uses the createCommonBaseEvent method to create
an event object. For more information on event correlation spheres, see
ECSEmitter myEmitter = new ECSEmitter("JNDI Emitter Factory Name", "newECSID");
CommonBaseEvent myEvent = myEmitter.createCommonBaseEvent("myEventType");
// get situation object
Situation mySituation = myEvent.getSituation();
// set situation properties
mySituation.setCategoryName("ReportSituation");
mySituation.setReportSituation("EXTERNAL", "STATUS");
// add other information to the the event
// send the event
myEmitter.sendEvent(myEvent);
This example uses the constructor method of the ECSEmitter
class to create an emitter, passing the JNDI name of an existing Common Event
Infrastructure emitter and the identification of a new event correlation sphere.
The
new emitter is then used to create a Common Base Event that contains a situation
object that is accessed using the getSituation call. The setCategoryName and
setReportSituation methods are used to set the mandatory data in the situation
object to emit an event with a ReportSituation. To create
other situation types, use different category names in the setCategoryName
call and different setter method calls for the situation.
All other
mandatory information is provided automatically by the runtime environment.
If mandatory information is set explicitly in the Common Base Event, this
information is not overwritten with the default information. The event is
now valid and can be submitted to an emitter using the sendEvent method.
In
an actual application, a useful event needs to include more information than
is shown in this example, but these properties are the minimum required by
the Common Base Event specification and the Common Event Infrastructure.
Use the addUserDataEvent method to create and populate an event. The following code fragment uses the addUserDataEvent method to
create an event object in the current event correlation sphere.
ECSEmitter myEmitter = new ECSEmitter("JNDI Emitter Factory Name", null);
// prepare a set of user data properties
Properties myUserData = new Properties();
myUserData.setProperty("UserData1","UserDataValue1");
myUserData.setProperty("UserData2","UserDataValue2");
// create and send the event
myEmitter.addUserDataEvent(myUserData);
This example uses the constructor method of the ECSEmitter
class to create an emitter, passing the JNDI name of an existing Common Event
Infrastructure emitter. An event correlation sphere identifier is not passed
(null) and therefore a new event correlation sphere is not
started. If an event correlation sphere exists, the user data event is added
to this correlation sphere.
A set of user data properties is then
prepared. Name and value pairs are added to a property list.
The last
step in the example creates and sends a Common Base Event using the addUserDataEvent
method of the new emitter. The extensionName property of the new Common Base
Event is set to ECS:UserDataEvent, the situation is set
to ReportSituation, and all other mandatory information is
provided automatically by the runtime environment.