4 WebLogic Server ログからのメ ッ セージのリ スン
手順 2 : 通知リ スナの登録
4 WebLogic Server
ログからの メ ッ セージの リ ス ンaddNotificationListener API の使用
addNotificationListener
API の構文は次の と お り です。
MBeanServer.addNotificationListener(ObjectName name, NotificationListener listener,
NotificationFilter filter, java.lang.Object handback) 以下の値を指定し ます。
nameは、 WebLogic Server イ ン ス タ ン スの LogBroadcasterRuntimeMBean のオブジ ェ ク ト 名です。 こ のオブジ ェ ク ト 名は、 以下のいずれかを行 う こ と に よ っ て 取得でき ます。
イ ン ス タ ン ス weblogic.management.WebLogicObjectNameを作成する。
詳細については、WebLogicObjectName
Javadoc を参照し てく だ さ い。
実行時に
weblogic.management.runtime.LogBroadcasterRuntimeMBeanをル ッ ク ア ッ プ し て .getObjectName()
を呼び出す。 詳細については、
LogBroadcasterRuntimeMBean
Javadoc を参照し てく だ さ い。
weblogic.Admin GETコ マン ド を使用する。 詳細については、 『管理者ガ イ ド 』 の 「GET コ マン ド」 を参照し て く だ さ い。
listenerは、
4-2
ページの 「手順 1 : 通知 リ スナの作成」 で作成し た通知 リ スナの イ ン ス タ ン スです。filterは、 フ ィ ルタ オブジ ェ ク ト です。 フ ィ ルタ が nullの場合、 通知の 処理前にフ ィ ル タ処理は実行 さ れません。 フ ィ ルタ オブジ ェ ク ト の作成およ び登録については、
4-12
ページの 「手順 3 : 通知フ ィ ル タの作成 と 登録」 で 説明し ます。handbackは、 通知のブ ロー ド キ ャ ス ト 時に リ スナに送信 さ れる コ ンテキ ス ト です。
addNotificationListener
API
の詳細については、javax.managment.MBeanServer
の Javadoc
(http://jcp.org/aboutJava/communityprocess/final/jsr003/index.html) を参照し て く だ さ い。
手順
2 :
通知 リ ス ナの登録通知リ スナの登録例
以下に、 「手順 1 : 通知 リ スナの作成」 で定義し た リ スナの登録例を示し ます。
コー ド リ ス ト 4-3 とコー ド リ ス ト 4-4の例は、 以下の こ と を行います。
1.
weblogic.management.HelperAPI
を使用し て、peach と い う サーバ用の サーバ固有の MBeanHome イ ン タ フ ェース を取得し ます。MBeanHomeイ ン タ
フ ェースの取得については、『WebLogic JMX Service プ ロ グ ラ マーズ ガ イ ド 』 の 「WebLogic Server MBean
ヘのア ク セス」 を参照し て く だ さ い。2.
MBeanHomeイ ン タ フ ェース を使用し て 、 対応する MBeanServerイ ン タ フ ェース を取得し ます。3.
LogBroadcasterRuntimeMBeanオブジ ェ ク ト 名を取得する ための別の メ ソ ッ ド を使用し ます。4.
「手順 1 : 通知 リ スナの作成」 で定義し た リ スナ オブジ ェ ク ト を イ ン ス タ ン ス 化し ます。5.
リ スナ オブジ ェ ク ト を LogBroadcasterRuntimeMBeanに登録し ます。コー ド リ ス ト 4-3では、WebLogicObjectNameを使用し て
LogBroadcasterRuntimeMBeanオブジ ェ ク ト 名を指定し ています。
コー ド リ ス ト
4-3 WebLogicObjectName の使用
public void find(String host, int port,
String username String password){
String url = "t3://" + host + ":" + port;
//サーバの MBeanHome インタフェースを取得 try {
serverSpecificHome = (MBeanHome)Helper.getMBeanHome(username, password,
url, peach);
} catch (IllegalArgumentException iae) {
System.out.println("Illegal Argument Exception: " + iae);
}
4 WebLogic Server
ログからの メ ッ セージの リ ス ン//MBeanHome を使用してサーバの MBeanServer インタフェースを取得 MBeanServer mServer = serverSpecificHome.getMBeanServer();
//サーバの LogBroadcasterRuntimeMBean の WebLogicObjectName を作成
WebLogicObjectName logBCOname = new WebLogicObjectName("WebLogicLogBroadcaster",
"LogBroadcasterRuntime", myDomain,
myServer);
//リスナ オブジェクトをインスタンス化
MyRemoteNotificationListener myListener = new MyRemoteNotificationListener();
//リスナを登録
mServer.addNotificationListener( logBCOname, myListener,
null, null);
}
コー ド リ ス ト 4-4では、MBeanHome.getMBeanByClass を使用し て LogBroadcasterRuntimeMBeanオブジ ェ ク ト 名を検索し ています。
コー ド リ ス ト
4-4 getObjectName()
の使用 public void find(String host,int port,
String username String password){
String url = "t3://" + host + ":" + port;
//サーバの MBeanHome インタフェースを取得 try {
serverSpecificHome = (MBeanHome)Helper.getMBeanHome(username, password,
url, peach);
} catch (IllegalArgumentException iae) {
System.out.println("Illegal Argument Exception: " + iae);
}
手順
2 :
通知 リ ス ナの登録//MBeanHome を使用してサーバの MBeanServer インタフェースを取得 MBeanServer mServer = serverSpecificHome.getMBeanServer();
//getMBeanByClass を使用してオブジェクトを検索
LogBroadcasterRuntimeMBean logBCOname = (LogBroadcasterRuntimeMBean) home.getMBeanByClass(Class.forName
("weblogic.management.runtime.LogBroadcasterRuntimeMBean") );
//リスナ オブジェクトをインスタンス化
MyRemoteNotificationListener myListener = new MyRemoteNotificationListener();
//リスナを登録
mServer.addNotificationListener( logBCOname, myListener,
null, null);
}
コー ド リ ス ト 4-5は、weblogic.Admin GETを使用し て
LogBroadcasterRuntimeMBeanオブジ ェ ク ト 名を検索し た こ と を前提 と し てい ます。 ま た、 こ の例には weblogic.Admin GETが返すオブジ ェ ク ト 名のフ ォー マ ッ ト も示 さ れて い ます。
コー ド リ ス ト
4-5 weblogic.Admin GET
の使用MyRemoteNotificationListener myListener = new MyRemoteNotificationListener();
MBeanServer mServer = home.getMBeanServer();
ObjectName logBCOname = new
ObjectName("mydomain:Location=myserver,Name=TheLogBroadcaster,Type=LogBroadcast erRuntime");
mServer.addNotificationListener( logBCOname, myListener,
null, null);