イベントを listen するアプリケーション・コンポーネントは、EventSource.addListener() メソッドを使用して、
イベントのパブリッシュ先のイベント・ソースと共にイベント・リスナー・オブジェクト (非同期 Bean の一種) を登録することができます。 また、イベント・ソースは、
任意のインターフェースを使用して、タイプが異なっても支障のない方法でイベントを発行することができます。
このタスクについて
単一 EAR ファイル内のコンポーネント間の通知は、特別なイベント・ソースによって処理されます。 トピック
アプリケーション通知サービスの使用を参照してください。
プロシージャー
- 任意のタイプのイベント・リスナー・オブジェクトを作成します。 例えば、以下のインターフェース・コードを参照してください。
interface SampleEventGroup
{
void finished(String message);
}
class myListener implements SampleEventGroup
{
public void finished(String message)
{
// This will be called when we 'finish'.
}
}
- イベント・リスナー・オブジェクトをイベント・ソースに登録します。
例えば、以下のコードのようになります。
InitialContext ic = ...;
EventSource es = (EventSource)ic.lookup("java:comp/websphere/ApplicationNotificationService");
myListener l = new myListener();
es.addListener(l);
これにより、イベントが発行されるたびに myListener.finished() メソッドが呼び出されます。 以下のコード例に、イベントが発行される仕組みを示します。InitialContext ic = ...;
EventSource es = (EventSource)ic.lookup("java:comp/websphere/ApplicationNotificationService");
myListener proxy = es.getEventTrigger(myListener.class);
// fire the 'event' by calling the method
// representing the event on the proxy
proxy.finished("done");