m-bean を記述する場合、以下の作業を行う必要があります。
m-let テキストファイルを作成する。
各 m-bean の情報は、MLET タグと呼ばれる単一のタグインスタンス内で指定します。m-let テキストファイルが読み込まれる時点で、このファイル内に指定された各 m-bean のインスタンスが作成されます。たとえば、QDatabaseAccounting m-bean の m-let テキストファイルを次のように作成し、QDatabaseAccounting.html に入れることができます。
<MLET
CODE=com.sun.ba.beans.QDatabaseAccounting
ARCHIVE="qdatabaseaccounting.jar, dbaccess.jar
>
<PARAM NAME=jdbcDriverName VALUE=com.sun.jdbc.SimpleText.SimpleTextDriver>
<PARAM NAME=jdbcURLName VALUE=jdbc:SimpleText:/var/opt/SUNWconn/ba>
</MLET>
|
initCmf() メソッドを実装する。initCmf() メソッドのプロトタイプは、次のような形式をとる必要があります。
. . . public void initCmf(Framework cmf, ObjectName name, boolean db, ModificationList list) . . . |
また、m-bean の bean 名とクラス名を指定して初期化も行えます。
.
.
.
ObjectName statsName = new ObjectName(cmf.getDomain(), beanName);
stats = (className) cmf.retrieveObject(statsName);
.
.
.
|
次に、QDatabaseAccounting.java ファイル内の initCmf() メソッドの例を示します。
.
.
.
public void initCmf(Framework cmf, ObjectName name, boolean db, ModificationList list)
throws InstanceNotFoundException, InstanceAlreadyExistException, ServiceNotFoundException
{
this.cmf = cmf;
if (name == null) {
name = new ObjectName(cmf.getDomain(), getClass().getName());
}
if (db) {
cmf.addDBObject(this, name);
} else {
cmf.addObject(this, name);
}
this.name = name;
ObjectName statsName = new ObjectName(cmf.getDomain(), statsMOName);
stats = (QStatsInterface) cmf.retrieveObject(statsName);
String jdbcDriverName = null;
Enumeration enum = list.elements();
while (enum.hasMoreElements()) {
Modification modif = (Modification) enum.nextElement();
String property = modif.getProperty();
String value = (String) modif.getValue();
if (property.equalsIgnoreCase("jdbcDriverName")) {
jdbcDriverName = value;
} else if (property.equalsIgnoreCase("jdbcUrlName")) {
jdbcUrlName = value;
} else if (property.equalsIgnoreCase("jdbcUserName")) {
jdbcUserName = value;
} else if (property.equalsIgnoreCase("jdbcPassword")) {
jdbcPassword = value;
} else if (property.equalsIgnoreCase("jdbcTableName")) {
jdbcTableName = value;
}
}
try {
Class.forName(jdbcDriverName);
} catch (ClassNotFoundException e) {
throw new ServiceNotFoundException("cannot load JDBC driver " + jdbcDriverName);
}
}
.
.
.
|
m-bean の宣言が ActivatableIf インタフェースを実装していることを確認する。
.
.
.
public class QDatabaseAccounting implements QConstants, QFlowAccountingListener,
ActivatableIf
{
.
.
.
|
performStart() メソッドを実装する。QDatabaseAccounting m-bean の場合、performStart() メソッドはフローアカウンティングのイベントリスナーを起動するメソッドを呼び出しています。
.
.
.
public void performStart()
{
if (!isActive()) {
try {
jdbcConnection = DriverManager.getConnection(jdbcUrlName, jdbcUserName, jdbcPassword);
flowTable = new QFlowTable(jdbcConnection, jdbcTableName);
stats.addQFlowAccountingListener(this);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
.
.
.
|
performStop() メソッドを実装する。次に、QDatabaseAccounting m-bean の場合の performStop() メソッドの例を示します。
.
.
.
public void performStop()
{
if (isActive()) {
stats.removeQFlowAccountingListener(this);
try {
jdbcConnection.commit();
jdbcConnection.close();
jdbcConnection = null;
flowTable = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
.
.
.
|
.
.
.
public boolean isActive()
{
return (jdbcConnection != null && flowTable != null);
}
.
.
.
|