Skip navigation.
Downloads | Product Documentation | Support

Using WebLogic JRockit 8.1 SDK

# Adding Custom Notification Actions and Constraints

After starting the WebLogic JRockit JVM Management Console for the first time, a file named `consolesettings.xml` will be 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:

- Locating consolesettings.xml
- Creating a Custom Action
- Creating and Implementing an Action: Example
- Creating a Custom Constraint

# Locating consolesettings.xml

The `consolesettings.xml` file is located in your home directory, under the `\ManagementConsole` folder. If you are using Windows, the path should be:

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

(where `<user_name>` is the user name under which you are running the Management Console)

If you are using Linux, the path will normally be:

>     /home/<user_name>/ManagementConsole

(where `<user_name>` is the user name under which you are running Management Console)

# Creating a Custom Action

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.

1. Add the `ManagementConsole.jar` to your build path.

You can find this `.jar` in the `<jrockit_home>/console` directory.

2. Create a subclass of `AbstractNotificationAction`. This class will receive the `NotificationEvents`.
3. Implement `handleNotificationEvent`:

>     public void handleNotificationEvent(NotificationEvent event)

You can also override the `exportToXml` and `initializeFromXml` methods to store your action settings to XML.

4. Create a subclass of `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`.
5. Implement the abstract methods:

>     protected void storeToObject(Describable object);

>     protected void initializeEditor(Describable object);

6. Edit the `consolesettings.xml` file to include your new action under the `<registry_entry>` element.
7. Add your new classes in the classpath.
8. Run the console.

The new action will be available in the new rule dialog box in the notification section of the Management Console (see Notification Tab).

# Creating and Implementing an Action: Example

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).

## Create the Action (Step 2)

First, we create a subclass of `AbstractNotificationAction`, as shown in Listing B-1. This class will receive the `NotificationEvents`.

Listing B-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;
>        }
>     }

## Implementing handleNotificationEvent() (Step 3)

While creating the subclass of `AbstractNotificationAction` created, we implemented handleNotificationEvent(), as shown in Listing B-2. This method acts on the incoming event.

Listing B-2 Implementing 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)

## Creating the Action Editor (Step 4)

Next, we create a subclass of `AbstractNotificationActionEditor` to create the graphical editor used to edit the settings. Listing B-3 shows how this is done.

Listing B-3 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());
>        }
>     }

## Implementing the Abstract Methods (Step 5)

When we created the action editor above, we implemented the abstract methods `initializeEditor()` and `storeToObject()`, as shown in Table B-4.

Listing B-4 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());
>        }

## Adding the New Action to the Deployment Entries (Step 6)

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 `<registry_entry>` element, as shown in Listing B-5.

Listing B-5 Adding the New Action to the Deployment Entries

>     <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>

## Displaying the New Action Editor (Steps 7 and 8)

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.

# Creating a Custom Constraint

Create custom constraints by using the same procedure described in Creating a Custom Action, except that you must implement:

>     boolean validate(NotificationEvent event)

instead of:

>     void handleNotificationEvent(NotificationEvent event)

as shown in Listing B-6:

Listing B-6 Code Change for Creating a Customer Constraint

>     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)