カスタム Common Base Event ファクトリー・ホームを使用して、
固有のイベント・ファクトリーの構成および実装を制御します。
始める前に
イベント・ファクトリー・ホームでは、イベント・ファクトリー・インスタンス用のホームが作成および提供されます。
各イベント・ファクトリー・ホームには、コンテンツ・ハンドラーがあります。
このコンテンツ・ハンドラーは、イベント・ファクトリー・ホームが作成するイベント・ファクトリーにそれぞれ割り当てられます。
同様に、Common Base Event が作成されると、その Common Base Event には、イベント・ファクトリーからコンテンツ・ハンドラーが割り当てられます。イベント・ファクトリー・インスタンスは、その固有の名前を基にした関連イベント・ファクトリー・ホームによって保守されます。
例えば、アプリケーション・コードによって名前付きのイベント・ファクトリーが要求された場合、新規に作成されたイベント・ファクトリー・インスタンスが返され、そのイベント・ファクトリーに対して将来、要求があった場合に備えて保持されます。
Common Base Event をロギングする際のイベント・ファクトリー・ホームの使用を容易にするために、以下のクラスが追加されました。
クラス名 |
説明 |
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 のロギングで Common Base Event の使用がサポートされており、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 クラスを実装および使用することができます。
- このコードを使用して、custom 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();
}
}
図 4 CustomTemplateEventFactoryHome クラス
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 ...
結果
ここに用意されている情報を使用して、カスタム・コンテンツ・ファクトリー・ホームおよび指定の設定に基づいた関連のクラスを実装します。