JRockit SDK ユーザーズ ガイド
![]() |
![]() |
![]() |
![]() |
初めて BEA JRockit Management Console を起動すると、consolesettings.xml
というファイルがホーム ディレクトリの ¥ManagementConsole
ディレクトリに作成されます。 このファイルにはいろいろなエントリがありますが、その中にデフォルトのアクションと制約のデプロイメント エントリも含まれています。 Management Console ではカスタムの通知アクションと制約を作成することができますが、それらもこのファイルに格納されます。 追加されたアクションと制約は Management Console の [Notification] タブに表示されます。
consolesettings.xml
ファイルは、ホーム ディレクトリの ¥ManagementConsole
フォルダに格納されています。 Windows を使用している場合、パスは次のようになります。
C:¥Documents and Settings¥<user_name>
¥ManagementConsole
(<user_name>
は Management Console を実行しているユーザ名)
Linux を使用している場合、パスは通常次のようになります。
/home/<user_name>
/ManagementConsole
(<user_name>
は Management Console を実行しているユーザ名)
カスタム アクションを作成および実装するために必要な手順について以下に説明します。 この手順では、出力アクションを作成します。
public void handleNotificationEvent(NotificationEvent event)
AbstractNotificationActionEditor
のサブクラスを作成して、設定の編集に使用するグラフィカルなエディタを作成します。 アクションに編集可能な設定がない場合は、com.jrockit.console.notification.ui.NotificationActionEditorEmpty
を使用します。
protected void storeToObject(Describable object);
protected void initializeEditor(Describable object);
新しいアクションが、Management Console の通知セクションにある新しいルールのダイアログ ボックスで使用できるようになります (「[Notification] タブ」を参照)。
この節では、アクションの作成方法と実装方法の実際の例を示します。 実装すると、パラメータを入力できるテキスト フィールドが [Notification] タブに表示されます。 以下の見出しにある手順番号は、「カスタム アクションの作成」の手順を示しています。
注意 : この例では、ManagementConsole.jar
がビルド パスに追加されていることを前提としています (手順 1)。
最初に、AbstractNotificationAction
のサブクラスを作成します。コード リスト A-1 を参照してください。 このクラスは NotificationEvent
を受け取ります。
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;
}
}
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)
次に、AbstractNotificationActionEditor
のサブクラスを作成して、設定の編集に使用するグラフィカルなエディタを作成します。コード リスト 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());
}
}
アクション エディタを作成したら、抽象メソッド initializeEditor()
および storeToObject()
を実装します。コード リスト 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());
}
アクションとエディタを 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>
最後に、新しいクラスをクラスパスに追加し、コンソールを起動します。 [Notification] タブに移動すると、タブ上に新しいエディタが表示されます。
カスタムの制約を作成するには、「カスタム アクションの作成」で説明したものと同じ手順を使用します。ただし、以下のように実装する必要があります。
boolean validate(NotificationEvent event)
void handleNotificationEvent(NotificationEvent event)
コード リスト 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)
![]() ![]() |
![]() |
![]() |