Use custom Common Base Event factory homes to control configuration
and implementation of unique event factories.
Before you begin
Event factory homes create and provide homes for Event
Factory instances. Each event factory home has a content handler.
This content handler is assigned to every event factory the event
factory home creates. In turn, when a Common Base Event is created,
the content handler from the event factory is assigned to it. Event
factory instances are maintained by the associated event factory home,
based on their unique name. For example, when application code requests
a named event factory, the newly created event factory instance is
returned and persisted for future requests for that named event factory.
The
following classes were added to facilitate the use of event eactory
homes for logging Common Base Events:
Class name |
Description |
WsEventFactoryHomeImpl |
This class extends the org.eclipse.hyades.logging.events.cbe.impl.AbstractEventFactoryHome
class. This event factory home returns event factory instances associated
with the WsContentHandlerImpl content handler. The WsContentHandlerImpl
is the content handler used by the WebSphere® Application
Server by default when no event factory template is in use. |
WsTemplateEventFactory
HomeImpl
|
This class extends the org.eclipse.hyades.logging.events.cbe.impl.EventXMLFileEventFactoryHomeImpl
class. This event factory home returns event factory instances associated
with the WsTemplateContentHandlerImpl Content Handler. The WsTemplateContentHandlerImpl
is the content handler used by the WebSphere Application
Server when an Event Factory template is required. |
About this task
Custom event factory homes support the use of Common Base
Event for logging in WebSphere Application Server
and make logging easy and consistent between the WebSphere Application
Server runtime and the exploiters of this API. The
CustomEventFactoryHome and
CustomTemplateEventFactoryHome classes
will be used to obtain an event factory. These classes are there to
make sure the correct content handler is being used with a particular
event factory. The
CustomEventFactoryHelper class
is an example of how the infrastructure provider can hide the factory
selection details from infrastructure users, using their own set of
parameters to decide which the appropriate event factory is.
Procedure
- The following code samples provide examples of
how to implement and use the CustomEventFactoryHome class.
- Implementation of the CustomEventFactoryHome class is
as follows:
public class CustomEventFactoryHome extends AbstractEventFactoryHome {
public CustomEventFactoryHome() {
super();
// TODO Custom intialization code goes here
}
public ContentHandler createContentHandler(String arg0) {
// Always use custom content handler
return resolveContentHandler();
}
public ContentHandler resolveContentHandler() {
// Always use custom content handler
return new CustomContentHandler();
}
}
- The following is an example of how to use the CustomEventFactoryHome
class:
// get the event factory
EventFactory eventFactory=(new CustomEventFactoryHome()).getEventFactory("XYZ");
// create an event - call appropriate method
eventFactory.createCommonBaseEvent();
// log event ...
- For the CustomTemplateEventFactoryHome class
you can use the following code for implementation and use:
- Implement the CustomTemplateEventFactoryHome class by
using this code:
public class CustomTemplateEventFactoryHome extends
EventXMLFileEventFactoryHomeImpl {
public CustomTemplateEventFactoryHome() {
super();
// TODO Custom intialization code goes here
}
public ContentHandler createContentHandler(String arg0) {
// Always use custom content handler
return resolveContentHandler();
}
public ContentHandler resolveContentHandler() {
// Always use custom content handler
return new CustomTemplateContentHandler();
}
}
- Use the CustomTemplateEventFactoryHome class by following
this sample code:
// get the event factory
EventFactory eventFactory=(new
CustomTemplateEventFactoryHome()).getEventFactory("XYZ");
// create an event - call appropriate method
eventFactory.createCommonBaseEvent();
// log event ...
- The CustomEventFactoryHelper class can be implemented
and used by following the code below:
- Implement the custom CustomEventFactoryHelper class
using this code:
public class CustomTemplateEventFactoryHome extends
EventXMLFileEventFactoryHomeImpl {
public CustomTemplateEventFactoryHome() {
super();
// TODO Custom intialization code goes here
}
public ContentHandler createContentHandler(String arg0) {
// Always use custom content handler
return resolveContentHandler();
}
public ContentHandler resolveContentHandler() {
// Always use custom content handler
return new CustomTemplateContentHandler();
}
}
Figure 4 CustomTemplateEventFactoryHome class
public class CustomEventFactoryHelper {
// name of the event factory to use
public static final String FACTORY_NAME="XYZ";
public static EventFactory getEventFactory(String param1, String param2) {
EventFactory factory=null;
switch (resolveFactory(param1,param2)) {
case 1:
factory=(new CustomEventFactoryHome()).getEventFactory(FACTORY_NAME);
break;
case 2:
factory=(new
CustomTemplateEventFactoryHome()).getEventFactory(FACTORY_NAME);
break;
default:
// Add default for event factory
break;
}
return factory;
}
private static int resolveFactory(String param1, String param2) {
int factory=0;
// Add code here to resolve which factory to use
return factory;
}
}
- To use the CustomEventFactoryHelper class, use the following
code:
// get the event factory
EventFactory eventFactory=
CustomEventFactoryHelper.getEventFactory("param1","param2","param3");
// create an event - call appropriate method
eventFactory.createCommonBaseEvent();
// log event ...
Results
Use the information provided here to implement a custom content
factory home and the associated classes based on the settings that
you specify.