BEA ホーム | 製品 | dev2dev | support | askBEA
 ドキュメントのダウンロード   サイト マップ   Glossary 
検索

WebLogic JMX Service プログラマーズ ガイド

 Previous Next Contents Index PDF で侮ヲ  

実行時の情報へのアクセス

WebLogic Server には、管理対象リソースの実行時の状態に関する情報を提供する MBean が数多く用意されています。この実行時データを参照および変更するアプリケーションを作成するには、まず MBeanServer インタフェースまたは WebLogic Server 型保障インタフェースを使用して実行時 MBean を取得する必要があります。その後に、weblogic.management.runtime パッケージの API を使用して実行時データを参照または変更します。 API ドキュメントの表示については、実行時 MBean API のドキュメントを参照してください。

以下の節では、WebLogic Server ドメインとサーバ インスタンスに関する実行時情報を取得および修正する例を示します。

 


例 : アクティブなドメインとサーバの判別

MBeanHome インタフェースには、現在アクティブなドメインの名前およびサーバ インスタンスの名前を判別するために使用できる API があります。 この情報は、引数としてドメイン名やサーバ名をとる他の API で使用できます。

リスト4-1 のクラス例では以下の処理を実行します。

  1. 管理 MBeanHome インタフェースを取得します。

    この例では管理 MBeanHome を使用していますが、ローカル MBeanHome インタフェースを使用することもできます。 ローカル MBeanHome インタフェースを使用する場合は、現在のドメインの名前とサーバ インスタンスしか取得できません。 管理 MBeanHome インタフェースを使用すると、ドメイン内で現在アクティブになっているすべてのサーバの名前を取得できます。

  2. MBeanHome.getActiveDomain().getName() を使用して、ドメインの名前を取得します。

  3. getMBeansByType メソッドを使用して、ドメイン内のすべての ServerRuntime MBean のセットを取得します。

  4. 取得したセットを検索し、ServerRuntimeMBean インスタンスの名前と WebLogic Server インスタンスの名前を比較します。インスタンスがアクティブであれば、そのサーバの名前を出力します。

  5. インスタンスがアクティブであれば、そのサーバの名前を出力します。

次の例で、weblogic は MBean の属性を参照および変更するパーミッションを持つユーザのユーザ名とパスワードです。 MBean を変更するパーミッションについては、『管理者ガイド』の「システム管理操作の保護」を参照してください。

コード リスト 4-1 アクティブなドメインとサーバの判別

import java.util.Set;
import java.util.Iterator;
import javax.naming.Context;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.runtime.ServerRuntimeMBean;
public class getActiveDomainAndServers {
public static void main(String[] args) {
MBeanHome home = null;
        //管理サーバの url
String url = "t3://localhost:7001";
String username = "weblogic";
String password = "weblogic";
        //初期コンテキストを設定
try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
            //管理 MBeanHome を取得
home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
} catch (Exception e) {
System.out.println("Exception caught:" +e);
}
        //アクティブなドメインの名前を取得
try {
System.out.println("Active Domain: " +
home.getActiveDomain().getName() );
} catch (Exception e) {
System.out.println("Exception:" +e);
}
        //ドメイン内のサーバの名前を取得
System.out.println("Active Servers: ");
Set mbeanSet = home.getMBeansByType("ServerRuntime");
Iterator mbeanIterator = mbeanSet.iterator();
while(mbeanIterator.hasNext()) {
ServerRuntimeMBean serverRuntime =
(ServerRuntimeMBean)mbeanIterator.next();
//アクティブなサーバの名前を出力
if(serverRuntime.getState().equalsIgnoreCase("RUNNING")) {
System.out.println("Name: " + serverRuntime.getName());
System.out.println("ListenAddress: " +
serverRuntime.getListenAddress());
System.out.println("ListenPort: " +
serverRuntime.getListenPort());
//count++;
}
}
        System.out.println("Number of servers active in the domain: " +
mbeanSet.size());
}
}

weblogic.Admin を使用したアクティブなドメインおよびサーバの判別

リスト4-1 のコード例をコンパイルおよび実行してアクティブなドメインとサーバを判別することも可能ですが、weblogic.Admin ユーティリティを使用すると、Java クラスをコンパイルしなくても同様のタスクを実行できます。

次のコマンドでは、現在アクティブなドメインの名前が返されます。AdminServer はドメインの管理サーバ、MyHost は管理サーバのホスト コンピュータ、weblogic は MBean の属性を参照するパーミッションを持つユーザの名前とパスワードです。

java weblogic.Admin -url MyHost:8001 -username weblogic -password
weblogic GET -type DomainRuntime -property Name

コマンドの出力には、DomainRuntimeMBeanWebLogicObjectName およびその Name 属性の値が含まれます。

{MBeanName="myDomain:Location=AdminServer,Name=myDomain,ServerRun
time=AdminServer,Type=DomainRuntime"{Name=myDomain}}

 


例 : WebLogic Server インスタンスの実行時の状態の参照および変更

weblogic.management.runtime.ServerRuntimeMBean インタフェースは、WebLogic Server インスタンスの実行時の情報を提供します。たとえば、サーバが使用しているリスン ポートとアドレスを示します。 また、このインタフェースにはサーバを正常にまたは強制的に停止する操作が組み込まれています。

この節では、ServerRuntimeMBean を検索し、その MBean を使用してサーバ インスタンスを正常に停止する例を示します。 正常な停止を開始すると、サーバはサブシステムに作業中のすべての要求を完了するように指示します。 サブシステムが作業を完了した後、サーバは停止します。

各例には、ServerRuntimeMBean を取得するための異なる方法を示してあります。

weblogic.Admin ユーティリティでは、実行時 MBean の属性値を変更できません。

ローカル MBeanHome と getRuntimeMBean() の使用

各 WebLogic Server インスタンスは、独自の MBeanHome インタフェースをホストします。このインタフェースは、そのサーバ インスタンス上のローカル コンフィグレーション MBean と実行時 MBean へのアクセスを提供します。管理 MBeanHome インタフェースを使用する場合とは異なり、ローカル MBeanHome を使用すると、フィルタ処理によって現在のサーバに適用される実行時 MBean を見つけ出す手間が省けます。また、管理サーバを経由して要求をルーティングするのではなく、直接ローカル サーバに接続しているので、より少ないネットワーク ホップで MBean にアクセスできます。

MBeanHome インタフェースには、現在の WebLogic Server に存在する最上位の実行時 MBean だけを返す getRuntimeMBean() メソッドがあります (ローカルのコンフィグレーション MBean と実行時 MBean の階層を辿るを参照)。MBeanHome.getRuntimeMBean() メソッドを管理サーバ上で呼び出した場合、管理サーバを管理およびモニタする実行時 MBean だけが返されます。

リスト4-2 のクラス例では以下の処理を実行します。

  1. t3://ServerHost:7001 で要求をリスンするサーバ インスタンスに接続するための情報をもとに javax.naming.Context オブジェクトをコンフィグレーションします。

  2. Context.lookup メソッドを使用して、サーバ インスタンスのローカル MBeanHome インタフェースを取得します。

    MBeanHome.LOCAL_JNDI_NAME フィールドに、現在のサーバのローカル MBeanHomeの JNDI 名が返されます。

  3. MBeanHome.getRuntimeMBean(String name,String type) メソッドを使用して、現在のサーバ インスタンスの ServerRuntimeMBean を取得します。

  4. ServerRuntimeMBean メソッドを呼び出して、サーバの状態を取得および変更します。

次の例で、weblogic は MBean の属性を参照および修正するパーミッションを持つユーザのユーザ名とパスワードで、Server1 は状態を参照および変更する必要のある WebLogic Server インスタンスの名前です。 MBean を変更するパーミッションについては、『管理者ガイド』の「システム管理操作の保護」を参照してください。

コード リスト 4-2 ローカル MBeanHome と getRuntimeMBean() の使用

import javax.naming.Context;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.runtime.ServerRuntimeMBean;
public class serverRuntime1 {
    public static void main(String[] args) {
MBeanHome home = null;
        //ドメイン変数
String url = "t3://ServerHost:7001";
String serverName = "Server1";
String username = "weblogic";
String password = "weblogic";
ServerRuntimeMBean serverRuntime = null;
        //初期コンテキストを設定
try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
           //ローカル MBeanHome を取得
home = (MBeanHome) ctx.lookup(MBeanHome.LOCAL_JNDI_NAME);
System.out.println("Got the MBeanHome: " + home + " for server: " +
serverName);
} catch (Exception e) {
System.out.println("Caught exception:" +e);
}
        // ここで、getRuntimeMBean メソッドを使用してサーバ インスタンスの
//ServerRuntimeMbean にアクセスする
       try {
serverRuntime =
(ServerRuntimeMBean)home.getRuntimeMBean
(serverName,"ServerRuntime");
System.out.println("Got serverRuntimeMBean: " + serverRuntime);
           //ServerRuntimeMBean を使用して状態を取得および変更する
System.out.println("Current state: " + serverRuntime.getState() );
} catch (javax.management.InstanceNotFoundException e) {
System.out.println("Caught exception:" +e);
}
       try{
serverRuntime.shutdown();
System.out.println("Current state: " + serverRuntime.getState() );
} catch (weblogic.server.ServerLifecycleException e) {
System.out.println("Caught exception:" +e);
}
}
}

管理 MBeanHome と getMBeansByType() の使用

リスト4-1の例と同じように、この節のクラス例では管理 MBeanHome インタフェースを使用して ServerRuntime MBean を取得します。管理 MBeanHome はドメイン内のすべての MBean への単一のアクセス ポイントとなりますが、これを使用するには、取得する MBean の WebLogicObjectName を構築するか、またはフィルタ処理を行って特定のサーバに存在する MBean を見つけ出す必要があります。

リスト4-3 のクラス例では以下の処理を実行します。

  1. 管理 MBeanHome インタフェースを取得します。

  2. MBeanHome.getMBeansByType メソッドを使用して、ドメイン内のすべての ServerRuntime MBean のセットを取得します。

  3. MBean のリストを Set オブジェクトに割り当て、Set インタフェースおよび Iterator インタフェースを使用してリスト内を検索します。

  4. ServerRuntimeMBean.getName メソッドを使用して、MBean の WebLogicObjectNameName コンポーネントを取得し、Name の値を別の値と比較します。

  5. 特定のサーバ インスタンスの ServerRuntimeMBean が見つかると、ServerRuntimeMBean.getState メソッドを使用してサーバの現在の状態を返します。

  6. ServerRuntimeMBean.shutdown() メソッドを呼び出して、正常な停止を開始します。

次の例で、weblogic はサーバの状態を変更するパーミッションを持つユーザのユーザ名とパスワードで、Server1 は状態を参照および変更する必要のある WebLogic Server インスタンスの名前です。 MBean を変更するパーミッションについては、『管理者ガイド』の「システム管理操作の保護」を参照してください。

コード リスト 4-3 管理 MBeanHome と getMBeansByType() の使用

import java.util.Set;
import java.util.Iterator;
import javax.naming.Context;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.runtime.ServerRuntimeMBean;
public class serverRuntimeInfo {
public static void main(String[] args) {
MBeanHome home = null;
        //ドメイン変数
String url = "t3://localhost:7001";
String serverName = "Server1";
String username = "weblogic";
String password = "weblogic";
ServerRuntimeMBean serverRuntime = null;
Set mbeanSet = null;
Iterator mbeanIterator = null;
        //初期コンテキストを設定
try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
            // 管理 MBeanHome を取得
home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
System.out.println("Got the Admin MBeanHome: " + home );
} catch (Exception e) {
System.out.println("Exception caught:" +e);
}
        //getMBeansByType メソッドを使用して
//ServerRuntime MBean を取得する
try {
mbeanSet = home.getMBeansByType("ServerRuntime");
mbeanIterator = mbeanSet.iterator();
// 各 ServerRutime MBean 内のサーバの名前を serverName
// で指定された値と比較する
while(mbeanIterator.hasNext()) {
serverRuntime = (ServerRuntimeMBean)mbeanIterator.next();
if(serverRuntime.getName().equals(serverName)) {
System.out.println("Found the serverRuntimembean: " +
serverRuntime + " for: " + serverName);
System.out.println("Current state: " +
serverRuntime.getState() );
System.out.println("Stopping the server ...");
serverRuntime.shutdown();
System.out.println("Current state: " +
serverRuntime.getState() );
}
}
} catch (Exception e) {
System.out.println("Caught exception:" +e);
}
}
}

管理 MBeanHome と getMBean() の使用

すべての MBean のリストを取得し、そのリストをフィルタ処理して特定のサーバの ServerRuntimeMBean を見つけ出す代わりに、この例では、MBean 命名規約を使用して Server1 というサーバ インスタンス上の ServerRuntimeMBeanWebLogicObjectName を構築します。 WebLogicObjectName の構築については、WebLogic Server MBean の WebLogicObjectName の使用を参照してください。

正しいオブジェクト名を確実に指定するには、weblogic.Admin GET コマンドを使用します。 たとえば次のコマンドでは、MyHost というホスト コンピュータで実行されるサーバ インスタンスの ServerRuntimeMBean のオブジェクト名と属性のリストが返されます。

java weblogic.Admin -url http://MyHost:7001 -username weblogic
-password weblogic GET -pretty -type ServerRuntime

weblogic.Admin ユーティリティを使用した MBean 情報の検索については、『管理者ガイド』の「MBean 管理コマンド リファレンス」を参照してください。

リスト4-4 で、weblogic は MBean の属性を参照および修正するパーミッションを持つユーザのユーザ名とパスワード、Server1 は状態を参照および変更する必要のある WebLogic Server インスタンスの名前、mihirDomain は WebLogic Server 管理ドメインの名前です。 MBean を変更するパーミッションについては、『管理者ガイド』の「システム管理操作の保護」を参照してください。

コード リスト 4-4 管理 MBeanHome と getMBean() の使用

import java.util.Set;
import java.util.Iterator;
import javax.naming.Context;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.runtime.ServerRuntimeMBean;
import weblogic.management.WebLogicObjectName;
public class serverRuntimeInfo2 {
public static void main(String[] args) {
MBeanHome home = null;
//ドメイン変数
String url = "t3://localhost:7001";
String serverName = "Server1";
String username = "weblogic";
String password = "weblogic";
String domain = "examples";
ServerRuntimeMBean serverRuntime = null;
        //初期コンテキストを設定
try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
            home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
System.out.println("Got Admin MBeanHome from the Admin server: "
+ home);
} catch (Exception e) {
System.out.println("Exception caught:" +e);
}
        try {
WebLogicObjectName objName = new WebLogicObjectName(serverName,
"ServerRuntime",home.getDomainName(),serverName);
System.out.println("Created WebLogicObjectName: " + objName);
serverRuntime = (ServerRuntimeMBean)home.getMBean(objName);
System.out.println("Got the serverRuntime using the adminHome: " +
serverRuntime );
System.out.println("Current state: " + serverRuntime.getState() );
System.out.println("Stopping the server ...");
            //状態を SHUTDOWN に変更
serverRuntime.shutdown();
System.out.println("Current state: " + serverRuntime.getState() );
} catch(Exception e) {
System.out.println("Exception:" +e);
}
}
}

MBeanServer インタフェースの使用

この節の例は、標準的な JMX の手法で MBean と対話します。管理 MBeanHome インタフェースを使用して javax.management.MBeanServer インタフェースを取得し、MBeanServer を使用して Server1 というサーバ インスタンスの ServerRuntimeMBeanListenPort 属性の値を取得します。

次の例で、weblogic は MBean の属性を参照および修正するパーミッションを持つユーザのユーザ名とパスワードで、mihirDomain は WebLogic Server 管理ドメインの名前です。 MBean を変更するパーミッションについては、『管理者ガイド』の「システム管理操作の保護」を参照してください。

コード リスト 4-5 管理 MBeanHome と getMBean() の使用

import java.util.Set;
import java.util.Iterator;
import javax.naming.Context;
import javax.management.MBeanServer;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicObjectName;
public class serverRuntimeInfo3 {
public static void main(String[] args) {
MBeanHome home = null;
        //ドメイン変数
String url = "t3://localhost:7001";
String serverName = "Server1";
String username = "weblogic";
String password = "weblogic";
Object attributeValue = null;
MBeanServer homeServer = null;
        //初期コンテキストを設定
try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
            // 管理 MBeanHome を取得
home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
System.out.println("Got Admin MBeanHome from the Admin server: " +
home);
} catch (Exception e) {
System.out.println("Exception caught:" +e);
}
try {
// MBean オブジェクト名を作成
WebLogicObjectName objName = new WebLogicObjectName(serverName,
"ServerRuntime",home.getDomainName(),serverName);
System.out.println("Created WebLogicObjectName: " + objName);
            //MBeanServer インタフェースを取得
homeServer = home.getMBeanServer();
            //ServerRuntimeMBean の ListenPort 属性を取得
attributeValue = homeServer.getAttribute(objName, "ListenPort");
System.out.println("ListenPort for " + serverName + " is:" +
attributeValue);
} catch(Exception e) {
System.out.println("Exception:" +e);
}
}
}

 


例 : クラスタに関する実行時の情報の参照

この節の例では、クラスタ内で現在実行されている WebLogic Server インスタンスの数と名前を取得します。この例では、weblogic.management.runtime.ClusterRuntimeMBean を使用します。この MBean は、1 つの管理対象サーバから見た WebLogic クラスタのメンバーの情報を提供します。

ClusterRuntimeMBean のインスタンスは管理対象サーバだけがホストします。また、ClusterRuntimeMBean のインスタンスはクラスタに参加しているアクティブな管理対象サーバから取得できます。

クラスタにあるアクティブな管理対象サーバから ClusterRuntimeMBean を取得するために、この例では次のことを行います。

  1. 管理 MBeanHome を取得します。このインタフェースは管理サーバ上で実行され、ドメイン内のすべての ClusterRuntimeMBean へのアクセスを提供します。

  2. すべての ClusterRuntimeMBeans を取得し、それらが対象クラスタに属しているかどうかを調べます。

  3. 対象クラスタ内の管理対象サーバの ClusterRuntimeMBean を 1 つ見つけます。

  4. 管理対象サーバの ClusterRuntimeMBean の API を使用して、クラスタ内のアクティブ サーバの数と名前を調べます。

この例で、weblogic は MBean の属性を参照および変更するパーミッションを持つユーザのユーザ名とパスワードです。 MBean を変更するパーミッションについては、『管理者ガイド』の「システム管理操作の保護」を参照してください。

コード リスト 4-6 クラスタ内で実行中のサーバのリストの取得

import java.util.Set;
import java.util.Iterator;
import java.rmi.RemoteException;
import javax.naming.Context;
import weblogic.jndi.Environment;
import weblogic.management.MBeanHome;
import javax.management.ObjectName;
import weblogic.management.WebLogicMBean;
import weblogic.management.runtime.ClusterRuntimeMBean;
import weblogic.management.WebLogicObjectName;
import weblogic.management.MBeanHome;
public class getRunningServersInCluster {
public static void main(String[] args) {
MBeanHome home = null;
        //ドメイン変数
String url = "t3://localhost:7001"; //url of the Administration Server
/* ドメインに複数のクラスタが存在する場合、クラスタ内の
* すべてのサーバのリストを定義する。 このリストとドメイン内のサーバを比較して
* 対象クラスタに属するサーバを特定する
*/
String server1 = "cs1"; // クラスタ内のサーバの名前
String server2 = "cs2"; // クラスタ内のサーバの名前
String username = "weblogic";
String password = "weblogic";
ClusterRuntimeMBean clusterRuntime = null;
Set mbeanSet = null;
Iterator mbeanIterator = null;
String name = "";
String[] aliveServerArray = null;
        //初期コンテキストを設定
try {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(username);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
            // 管理 MBeanHome を取得 
home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
            // ドメイン内の ClusterRuntime MBean のリストを取得
mbeanSet = home.getMBeansByType("ClusterRuntime");
mbeanIterator = mbeanSet.iterator();
while(mbeanIterator.hasNext()) {
                // リストから 1 つの ClusterRuntime MBean を取得
clusterRuntime = (ClusterRuntimeMBean)mbeanIterator.next();
// ClusterRuntime MBean の名前を取得
name = clusterRuntime.getName();
// 現在の ClusterRuntimeMBean が対象クラスタ内のサーバに
// 属しているかどうかを特定
if(name.equals(server1) || name.equals(server2) ) {
// 現在の ClusterRuntimeMBean を使用してクラスタ内の
// サーバの数を取得
System.out.println("¥nNumber of active servers in the
cluster: " + clusterRuntime.getAliveServerCount());
// クラスタ内のサーバの名前を取得
aliveServerArray = clusterRuntime.getServerNames();
break;
}
}
} catch (Exception e) {
System.out.println("Caught exception:" +e);
}
if(aliveServerArray == null) {
System.out.println("¥nThere are no running servers in the cluster");
System.exit(1);
}
        System.out.println("¥nThe running servers in the cluster are: ");
for (int i=0; i < aliveServerArray.length; i++) {
System.out.println("server " + i + " : " + aliveServerArray[i]);
}
}
}

 


EJB の実行時情報の表示

WebLogic Server では、サーバ インスタンスにデプロイした EJB ごとに、weblogic.management.runtime パッケージから MBean タイプがインスタンス化されます (表 4-1 を参照)。 weblogic.management.runtime パッケージに含まれる MBean の詳細については、WebLogic Server Javadoc を参照してください。

表4-1 EJB の実行時情報を提供する MBean

MBean タイプ

説明

EJBComponentRuntimeMBean

EJB モジュール用に収集されるすべての実行時情報の最上位インタフェース。

StatefulEJBRuntimeMBean

ステートフル セッション Bean の場合にのみインスタンス化される。

ステートフル セッション Bean 用に収集された EJB 実行時情報にアクセスするためのメソッドを含む。

StatelessEJBRuntimeMBean

ステートレス セッション Bean の場合にのみインスタンス化される。

ステートレス セッション Bean 用に収集された EJB 実行時情報にアクセスするためのメソッドを含む。

MessageDrivenEJBRuntimeMBean

メッセージ駆動型 Bean の場合にのみインスタンス化される。

メッセージ駆動型 Bean 用に収集された EJB 実行時情報にアクセスするためのメソッドを含む。

EntityEJBRuntimeMBean

エンティティ Bean 用に収集された EJB 実行時情報にアクセスするためのメソッドを含む。

EJBCacheRuntimeMBean

EJB 用に収集されたキャッシュ実行時情報にアクセスするためのメソッドを含む。

EJBLockingRuntimeMBean

EJB 用に収集されたロック マネージャ実行時情報にアクセスするためのメソッドを含む。

EJBTransactionRuntimeMBean

EJB 用に収集されたトランザクション実行時情報にアクセスするためのメソッドを含む。

EJBPoolRuntimeMBean

ステートレス セッション Bean の場合にのみインスタンス化される。

ステートレス セッション Bean 用に収集されたフリー プール実行時情報にアクセスするためのメソッドを含む。

WebLogic Server では、フリー プールを使用してステートレス セッション EJB のパフォーマンスとスループットを高める。 フリー プールには、非バインド ステートレス セッション EJB が格納される。 非バインド EJB インスタンスはステートレス セッション EJB クラスのインスタンスで、メソッド呼び出しを処理しない。


 

WebLogic Server には、追加の抽象インタフェースとして EJBRuntimeMBean が用意されています。このインタフェースには、その他の EJB 実行時 MBean で使用するメソッドが含まれます。

EJB 実行時 MBean は階層内でインスタンス化されます。次に例を示します。

取得する実行時データのタイプによっては、データのコンテキストを提供するために親 MBean の名前も取得する必要があります。 たとえば、EJBTransactionRuntimeMBean.TransactionsRolledBackTotalCountの値を取得する場合は、その値をどのエンティティ Bean から取得したかを識別するため、その親の名前 EJBEntityRuntimeMBean も取得します。

この階層関係を図 4-1 に示します。

図 4-1 EJB 実行時 MBean の階層関係


 

例 : すべてのステートフル EJB およびステートレス EJB の実行時情報の取得

リスト4-7 の例では、ドメイン内にデプロイされたすべての EJB の実行時情報を取得するために以下の処理を実行します。

  1. 管理サーバに接続し、管理 MBeanHome インタフェースを取得します。

    特定のサーバ インスタンスにデプロイされた EJB のみの実行情報を取得する場合は、特定のサーバ インスタンスに接続してローカル MBeanHome インタフェースを取得します。 詳細については、例 : 内部クライアントからのローカル MBeanHome の取得を参照してください。

  2. フリー プール内でアイドル状態の Bean インスタンスの数を表示するため、以下の処理を実行します。

    1. MBeanHome.getMBeansByType を呼び出してすべての StatelessEJBRuntime MBean を取得します。

    2. ステートレス EJB ごとに displayEJBInfo メソッド (このクラス内で定義) を呼び出します。 このメソッドは以下の処理を実行します。

    1. StatelessEJBRuntime.getPoolRuntime メソッドを呼び出して、ステートレス EJB に関連付けられている EJBPoolRuntimeMBean を取得します。

    2. EJBPoolRuntimeMBean.getIdleBeansCount メソッドを呼び出します。

  3. ドメイン内の各ステートフル EJB がロールバックされたトランザクションの割合を調べるため、以下の処理を実行します。

    1. MBeanHome.getMBeansByType を呼び出してすべての StatefulEJBRuntime MBean を取得します。

    2. displayEJBInfo メソッド (このクラス内で定義) を呼び出します。

    3. EJBRuntime.getTransactionRuntime メソッドを呼び出して、ステートフル EJB に関連付けられている EJBTransactionRuntimeMBean を取得します。

    4. EJBTransactionRuntimeMBean.getTransactionsRolledBackTotalCount メソッドおよび getTransactionsCommittedTotalCount メソッドを呼び出します。

    5. コミットされたトランザクションの数をロールバックされたトランザクションの数で割って、ロールバックされたトランザクションの割合を算出します。

コード リスト 4-7 EJB の実行時情報の表示

import java.util.Iterator;
import java.util.Set;
import javax.management.InstanceNotFoundException;
import javax.naming.Context;
import javax.naming.InitialContext;
import weblogic.management.MBeanHome;
import weblogic.management.WebLogicObjectName;
import weblogic.management.configuration.ApplicationMBean;
import weblogic.management.configuration.EJBComponentMBean;
import weblogic.management.configuration.ServerMBean;
import weblogic.management.runtime.EJBComponentRuntimeMBean;
import weblogic.management.runtime.EJBPoolRuntimeMBean;
import weblogic.management.runtime.EJBRuntimeMBean;
import weblogic.management.runtime.EJBTransactionRuntimeMBean;
import weblogic.management.runtime.StatelessEJBRuntimeMBean;
import weblogic.jndi.Environment;
public final class EJBMonitor {
private String url = "t3://localhost:7001";
private String user = "weblogic";
private String password = "weblogic";
private MBeanHome mBeanHome; // admin
    public EJBMonitor() throws Exception {
Environment env = new Environment();
env.setProviderUrl(url);
env.setSecurityPrincipal(user);
env.setSecurityCredentials(password);
Context ctx = env.getInitialContext();
mBeanHome = (MBeanHome)ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
}
    public void displayStatelessEJBPoolIdleCount()
throws Exception
{
int idleCount = 0;
String type = "StatelessEJBRuntime";
Set beans = mBeanHome.getMBeansByType(type);
System.out.println("Printing Stateless Session pool idle count:");
for(Iterator it=beans.iterator();it.hasNext();) {
StatelessEJBRuntimeMBean rt = (StatelessEJBRuntimeMBean)it.next();
displayEJBInfo(rt);
EJBPoolRuntimeMBean pool = rt.getPoolRuntime();
idleCount = pool.getIdleBeansCount();
}
System.out.println("Pool Idle Bean Count: "+ idleCount +"¥n");
}
    public void displayStatefulEJBTransactionRollbackPercentages()
throws Exception
{
String type = "StatefulEJBRuntime";
Set beans = mBeanHome.getMBeansByType(type);
System.out.println("Printing Stateful transaction rollback
percentages:");
for(Iterator it=beans.iterator();it.hasNext();) {
EJBRuntimeMBean rt = (EJBRuntimeMBean)it.next();
displayEJBInfo(rt);
EJBTransactionRuntimeMBean trans = rt.getTransactionRuntime();
String rollbackPercentage = "0";
long rollbackCount = trans.getTransactionsRolledBackTotalCount();
if(rollbackCount > 0) {
long totalTransactions = rollbackCount +
trans.getTransactionsCommittedTotalCount();
rollbackPercentage =
""+(float)rollbackCount/totalTransactions*100;
}
            System.out.println("Transaction rollback percentage: "+
rollbackPercentage +"¥n");
}
}
    private void displayEJBInfo(EJBRuntimeMBean rt) throws Exception {
System.out.println("EJB Name: "+rt.getEJBName());
EJBComponentRuntimeMBean compRTMBean =
EJBComponentMBean compMBean = compRTMBean.getEJBComponent();
ApplicationMBean appMBean = (ApplicationMBean)compMBean.getParent();
System.out.println("Application Name: "+appMBean.getName());
System.out.println("Component Name: "+compMBean.getName());
WebLogicObjectName objName = rt.getObjectName();
System.out.println("Server Name: "+objName.getLocation());
}
    public static void main(String[] argv) throws Exception {
EJBMonitor m = new EJBMonitor();
m.displayStatelessEJBPoolIdleCount();
m.displayStatefulEJBTransactionRollbackPercentages();
}
}

 

Back to Top Previous Next