사용자 정의 공통 기본 이벤트 팩토리 홈을 사용하여 고유 이벤트 팩토리의 구성 및 구현을 제어할 수 있습니다.
시작하기 전에
이벤트 팩토리 홈은 이벤트 팩토리 인스턴스의 홈을 작성하고 제공합니다. 각 이벤트 팩토리 홈에는 컨텐츠 핸들러가 있습니다.
이 컨텐츠 핸들러는 이벤트 팩토리 홈이 작성하는
모든 이벤트 팩토리에 지정됩니다. 결과적으로 공통 기본 이벤트가 작성되면
이벤트 팩토리의 컨텐츠 핸들러가 여기에 지정됩니다. 이벤트 팩토리 인스턴스는 해당 고유 이름을 기반으로 연관된
이벤트 팩토리 홈에 의해 유지보수됩니다. 예를 들어, 애플리케이션 코드가 이름 지정된 이벤트 팩토리를 요청하면
새로 작성된 이벤트 팩토리 인스턴스가 리턴되고 이 이름 지정된 이벤트 팩토리에 대한 나중 요청을 위해
지속됩니다.
공통 기본 이벤트 로깅에 이벤트 팩토리 홈을 사용하는 것을 용이하게 하기 위해 다음 클래스가 추가되었습니다.
클래스 이름 |
설명 |
WsEventFactoryHomeImpl |
이 클래스는 org.eclipse.hyades.logging.events.cbe.impl.AbstractEventFactoryHome
클래스를 확장합니다. 이 이벤트 팩토리 홈은 WsContentHandlerImpl 컨텐츠 핸들러와
연관된 이벤트 팩토리 인스턴스를 리턴합니다. WsContentHandlerImpl은 사용 중인 이벤트 팩토리 템플리트가 없을 때
WebSphere®
Application Server가 기본적으로 사용하는 컨텐츠 핸들러입니다. |
WsTemplateEventFactory
HomeImpl
|
이 클래스는 org.eclipse.hyades.logging.events.cbe.impl.EventXMLFileEventFactoryHomeImpl
클래스를 확장합니다. 이 이벤트 팩토리 홈은 WsTemplateContentHandlerImpl 컨텐츠 핸들러와
연관된 이벤트 팩토리 인스턴스를 리턴합니다. WsTemplateContentHandlerImpl은 이벤트 팩토리 템플리트가 필요할 때
WebSphere Application Server가
사용하는 컨텐츠 핸들러입니다. |
이 태스크 정보
사용자 정의 이벤트 팩토리 홈은 WebSphere Application
Server에서 로깅하며 로깅을 쉽게 하고 WebSphere Application
Server 런타임과 이 API의 이용자 간 일관성을 유지하기 위해 공통 기본 이벤트의 사용을 지원합니다. 이벤트 팩토리를 얻기 위해
CustomEventFactoryHome 및
CustomTemplateEventFactoryHome 클래스가 사용됩니다. 이러한 클래스는
올바른 컨텐츠 핸들러가 특정 이벤트 팩토리와 함께 사용되는지 확인하기 위한 것입니다.
CustomEventFactoryHelper 클래스는
인프라 제공자가 적합한 이벤트 팩토리를 결정하기 위해 고유한 매개변수 세트를 사용하여
인프라 사용자로부터 팩토리 선택 세부사항을 숨기는 방법의 예입니다.
프로시저
- 다음 코드 샘플은 CustomEventFactoryHome 클래스를 구현하고 사용하는 방법의 예를 제공합니다.
- CustomEventFactoryHome 클래스의 구현은 다음과 같습니다.
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();
}
}
- 다음은 CustomEventFactoryHome 클래스를 사용하는 방법의 예입니다.
// get the event factory
EventFactory eventFactory=(new CustomEventFactoryHome()).getEventFactory("XYZ");
// create an event - call appropriate method
eventFactory.createCommonBaseEvent();
// log event ...
- CustomTemplateEventFactoryHome 클래스의 구현 및 사용을 위해 다음 코드를 사용할 수 있습니다.
- 다음 코드를 사용하여 CustomTemplateEventFactoryHome 클래스를 구현하십시오.
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();
}
}
- 다음 샘플 코드에 따라 CustomTemplateEventFactoryHome 클래스를 사용하십시오.
// get the event factory
EventFactory eventFactory=(new
CustomTemplateEventFactoryHome()).getEventFactory("XYZ");
// create an event - call appropriate method
eventFactory.createCommonBaseEvent();
// log event ...
- 다음 코드에 따라 CustomEventFactoryHelper 클래스를 구현하고 사용할 수 있습니다.
- 이 코드를 사용하여 사용자 정의 CustomEventFactoryHelper 클래스를 구현하십시오.
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;
}
}
- CustomEventFactoryHelper 클래스를 사용하려면 다음 코드를 사용하십시오.
// get the event factory
EventFactory eventFactory=
CustomEventFactoryHelper.getEventFactory("param1","param2","param3");
// create an event - call appropriate method
eventFactory.createCommonBaseEvent();
// log event ...
결과
여기에 제공된 정보를 사용하여 사용자가 지정하는 설정을 기반으로 사용자 정의 컨텐츠 팩토리 홈 및 연관된 클래스를 구현할 수 있습니다.