ナビゲーションをスキップ

JRockit SDK ユーザーズ ガイド

  前 次 前/次ボタンと目次ボタンとの区切り線 目次  

カスタム通知アクションおよび制約の追加

初めて BEA JRockit Management Console を起動すると、consolesettings.xml というファイルがホーム ディレクトリの ¥ManagementConsole ディレクトリに作成されます。 このファイルにはいろいろなエントリがありますが、その中にデフォルトのアクションと制約のデプロイメント エントリも含まれています。 Management Console ではカスタムの通知アクションと制約を作成することができますが、それらもこのファイルに格納されます。 追加されたアクションと制約は Management Console の [Notification] タブに表示されます。

この付録の内容は以下のとおりです。

 


consolesettings.xml の配置

consolesettings.xml ファイルは、ホーム ディレクトリの ¥ManagementConsole フォルダに格納されています。 Windows を使用している場合、パスは次のようになります。

C:¥Documents and Settings¥<user_name>¥ManagementConsole

(<user_name> は Management Console を実行しているユーザ名)

Linux を使用している場合、パスは通常次のようになります。

/home/<user_name>/ManagementConsole

(<user_name> は Management Console を実行しているユーザ名)

 


カスタム アクションの作成

カスタム アクションを作成および実装するために必要な手順について以下に説明します。 この手順では、出力アクションを作成します。

  1. ManagementConsole.jar をビルド パスに追加します。
  2. この .jar<jrockit_home>/console ディレクトリにあります。

  3. AbstractNotificationAction のサブクラスを作成します。 このクラスは NotificationEvent を受け取ります。
  4. handleNotificationEvent を実装します。
  5. public void handleNotificationEvent(NotificationEvent event)

    exportToXml および initializeFromXml メソッドをオーバーライドして、アクション設定を XML に格納することもできます。

  6. AbstractNotificationActionEditor のサブクラスを作成して、設定の編集に使用するグラフィカルなエディタを作成します。 アクションに編集可能な設定がない場合は、com.jrockit.console.notification.ui.NotificationActionEditorEmpty を使用します。
  7. 抽象メソッドを実装します。
  8. protected void storeToObject(Describable object);
    protected void initializeEditor(Describable object);
  9. consolesettings.xml ファイルを編集して、<registry_entry> 要素の下に新しいアクションを指定します。
  10. クラスパスに新しいクラスを追加します。
  11. コンソールを実行します。

新しいアクションが、Management Console の通知セクションにある新しいルールのダイアログ ボックスで使用できるようになります (「[Notification] タブ」を参照)。

 


アクションの作成および実装 : 例

この節では、アクションの作成方法と実装方法の実際の例を示します。 実装すると、パラメータを入力できるテキスト フィールドが [Notification] タブに表示されます。 以下の見出しにある手順番号は、「カスタム アクションの作成」の手順を示しています。

注意 : この例では、ManagementConsole.jar がビルド パスに追加されていることを前提としています (手順 1)。

アクションの作成 (手順 2)

最初に、AbstractNotificationAction のサブクラスを作成します。コード リスト A-1 を参照してください。 このクラスは NotificationEvent を受け取ります。

コード リスト A-1 パラメータ化したアクションの作成

package com.example.actions;
import org.w3c.dom.Element;
import com.jrockit.console.notification.*;
import com.jrockit.console.util.XmlToolkit;
/**
* パラメータ化したアクションの作成方法を示すテスト クラス
*
* @author Marcus Hirt
*/
public class MyTestAction extends AbstractNotificationAction
{
private final static String TEST_SETTING = "test_param";
public final static String DEFAULT_VALUE = "default value";
private String m_parameter = DEFAULT_VALUE;
      /**
* @see com.jrockit.console.notification.NotificationAction#
* handleNotificationEvent(NotificationEvent)
*/
public void handleNotificationEvent(NotificationEvent event)
   {
System.out.println("===MyTestAction with param: " +
getParameter() + "======");
System.out.println(NotificationToolkit.prettyPrint(event));
}
   /**
* @see com.jrockit.console.util.XmlEnabled#exportToXml
* (Element)
*/
   public void exportToXml(Element node)
{
XmlToolkit.setSetting(node, TEST_SETTING, m_parameter);
}

/**
* @see com.jrockit.console.util.XmlEnabled#initializeFromXml
* (Element)
*/
public void initializeFromXml(Element node)
{
      m_parameter = XmlToolkit.getSetting(node, TEST_SETTING,
DEFAULT_VALUE);
}
      /**
* パラメータを返す
*
* @return なんらかのパラメータ
*/
   public String getParameter()
{
return m_parameter;
}
   /**
* パラメータを設定
*
* @param パラメータ名 パラメータに設定する値
*/
public void setParameter(String parameter)
{
m_parameter = parameter;
}
}

handleNotificationEvent() の実装 (手順 3)

AbstractNotificationAction のサブクラスを作成したら、handleNotificationEvent() を実装します。コード リスト A-2 を参照してください。 このメソッドは受信するイベントに対して機能します。

コード リスト A-2 handleNotificationEvent の実装

public class MyTestAction extends AbstractNotificationAction
{
private final static String TEST_SETTING = "test_param";
public final static String DEFAULT_VALUE = "default value";
private String m_parameter = DEFAULT_VALUE;
      /**
* @see com.jrockit.console.notification.NotificationAction#
* handleNotificationEvent(NotificationEvent)
*/
public void handleNotificationEvent(NotificationEvent event)

アクション エディタの作成 (手順 4)

次に、AbstractNotificationActionEditor のサブクラスを作成して、設定の編集に使用するグラフィカルなエディタを作成します。コード リスト A-3 にその方法を示します。

コード リスト A-3 アクション エディタの作成

package com.example.actions;
import java.awt.*;
import javax.swing.*;
import com.jrockit.console.notification.Describable;
import com.jrockit.console.notification.ui.AbstractNotification
ActionEditor;
/**
* 簡単なテスト エディタ。 パラメータを入力できるテキスト フィールドを表示する
* (GridbagLayout を使用すると、よりよいレイアウト結果が得られる)
*
* @author Marcus Hirt
*/
public class MyTestActionEditor extends AbstractNotificationActionEditor
{
private JTextField m_parameterField = new
JTextField(MyTestAction.DEFAULT_VALUE);
   /**
* MyTestActionEditor のコンストラクタ
*/
public MyTestActionEditor()
{
super();
setName("MyTestAction settings");
add(new JLabel("Param:"), BorderLayout.WEST);
add(m_parameterField, BorderLayout.CENTER);
setMinimumSize(new Dimension(140,0));
}
/**
* @see com.jrockit.console.notification.ui.Abstract
* Editor#initializeEditor(com.jrockit.console.notification.
* Describable)
*/
protected void initializeEditor(Describable action)
{
m_parameterField.setText(((MyTestAction) action).
getParameter());
}
/**
* @see com.jrockit.console.notification.ui.AbstractEditor#
* storeToObject(com.jrockit.console.notification.Describable)
*/
protected void storeToObject(Describable action)
{
      ((MyTestAction)action).setParameter(m_parameterField.
getText());
}
}

抽象メソッドの実装 (手順 5)

アクション エディタを作成したら、抽象メソッド initializeEditor() および storeToObject() を実装します。コード リスト A-4 を参照してください。

コード リスト A-4 抽象メソッドの実装

  */
protected void initializeEditor(Describable action)
{
m_parameterField.setText(((MyTestAction) action).
getParameter());
}
/**
* @see com.jrockit.console.notification.ui.AbstractEditor#
* storeToObject(com.jrockit.console.notification.Describable)
*/
protected void storeToObject(Describable action)
{
      ((MyTestAction)action).setParameter(m_parameterField.
getText());
}

デプロイメント エントリへの新しいアクションの追加 (手順 6)

アクションとエディタを Management Console に表示するには、consolesettings.xml で、<registry_entry> 要素の下のデプロイメント エントリに追加する必要があります。コード リスト A-5 を参照してください。

コード リスト A-5 デプロイメント エントリへの新しいアクションの追加

<registry_entry>
<entry_class>
com.company.actions.MyTestAction
</entry_class>
<entry_name>
Test action
</entry_name>
<entry_description>
Test action, dynamically added.
</entry_description>
<entry_editor_class>
com.company.actions.MyTestActionEditor
</entry_editor_class>
</registry_entry>

新しいアクション エディタの表示 (手順 7 および 8)

最後に、新しいクラスをクラスパスに追加し、コンソールを起動します。 [Notification] タブに移動すると、タブ上に新しいエディタが表示されます。

 


カスタム制約の作成

カスタムの制約を作成するには、「カスタム アクションの作成」で説明したものと同じ手順を使用します。ただし、以下のように実装する必要があります。

boolean validate(NotificationEvent event)

このコードの代わりに、次のコードを実装します。

void handleNotificationEvent(NotificationEvent event)

コード リスト A-6 を参照してください。

コード リスト A-6 カスタム制約作成用のコードの変更

public class MyTestAction extends AbstractNotificationAction
{
private final static String TEST_SETTING = "test_param";
public final static String DEFAULT_VALUE = "default value";
private String m_parameter = DEFAULT_VALUE;
      /**
* @see com.jrockit.console.notification.NotificationAction#
* handleNotificationEvent(NotificationEvent)
*/
      boolean validate(NotificationEvent event)

 

ナビゲーション バーのスキップ  ページの先頭 前 次