User Guide
After starting the Management Console for the first time, a file named consolesettings.xml
is created in the \ManagementConsole
directory in your home directory. Among other entries, this file contains the deployment entries for the default actions and constraints. You can create custom notification actions and constraints for the Management Console, which are also stored in this file. Once added, these actions and constraints will appear on the Notifications tab of the Management Console.
This appendix includes information on the following subjects:
The following procedure walks you through the steps necessary to create and implement a custom action. In this procedure, you will be creating a print action.
public void handleNotificationEvent(NotificationEvent event)
You can also override the exportToXml
and initializeFromXml
methods to store your action settings to XML.
AbstractNotificationActionEditor
to create the graphical editor used to edit the settings. If you have no editable settings for your action, you can just use the com.jrockit.console.notification.ui.NotificationActionEditorEmpty
.protected void storeToObject(Describable object);
protected void initializeEditor(Describable object);
The new action will be available in the new rule dialog box in the notification section of the Management Console (see Creating a New Rule).
This section shows a real-life example of how an action is created and implemented. Once implemented, a text field where you can enter a parameter will appear on the Notification tab. The step numbers that appear in headings below refer to the steps in the procedures under Creating a Custom Action.
Note: This example assumes that ManagementConsole.jar
has been added to the build path (Step 1).
First, create a subclass of AbstractNotificationAction
, as shown in Listing A-1. This class will receive the NotificationEvents
.
Listing A-1 Building the Parameterized Action
package com.example.actions;
import org.w3c.dom.Element;
import com.jrockit.console.notification.*;
import com.jrockit.console.util.XmlToolkit;
/**
* Test class showing how to build a parameterized action.
*
* @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);
}
/**
* Returns the parameter.
*
* @return some parameter.
*/
public String getParameter()
{
return m_parameter;
}
/**
* Sets the parameter.
*
* @param parameter the value to set the parameter to.
*/
public void setParameter(String parameter)
{
m_parameter = parameter;
}
}
While creating the subclass of AbstractNotificationAction
, you implemented the abstract method handleNotificationEvent()
. This method acts on the incoming event and this is where you put the code representing the action you wish to take. From the event, you can access the RJMXConnectorModule
via getSource()
from which you can access the functionality available from the JVM.
Next, we create a subclass of AbstractNotificationActionEditor
to create the graphical editor used to edit the settings. Listing A-2 shows how this is done.
Listing A-2 Creating the Action Editor
package com.example.actions;
import java.awt.*;
import javax.swing.*;
import com.jrockit.console.notification.Describable;
import com.jrockit.console.notification.ui.AbstractNotification
ActionEditor;
/**
* Simple test editor. Displays a text field where you can enter a
* parameter.
* (Note that you'd get better layout results using a GridbagLayout.)
*
* @author Marcus Hirt
*/
public class MyTestActionEditor extends AbstractNotificationActionEditor
{
private JTextField m_parameterField = new
JTextField(MyTestAction.DEFAULT_VALUE);
/**
* Constructor for 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());
}
}
When we created the action editor above, we implemented the abstract methods initializeEditor()
and storeToObject()
, as shown in Table A-3.
Listing A-3 Implementing the Abstract Methods
*/
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());
}
Before the action and editor can appear on the Management Console, you need to add it to the deployment entries in consolesettings.xml
, under the <notification_actions>
element, as shown in Listing A-4.
Listing A-4 Adding the New Action to the Deployment Entries
<registry_entry>
<entry_class>
com.example.actions.MyTestAction
</entry_class>
<entry_name>
Test action
</entry_name>
<entry_description>
Test action, dynamically added.
</entry_description>
<entry_editor_class>
com.example.actions.MyTestActionEditor
</entry_editor_class>
</registry_entry>
Finally, add the new classes to your classpath and start the console. When you navigate to the Notifications tab, you'll see the new editor on the tab.
Create custom constraints by using the same procedure described in Creating a Custom Action, except that you must implement:
boolean validate(NotificationEvent event)
void handleNotificationEvent(NotificationEvent event)