This section describes how you can create your own user actions that you want to be shown in the Plugin menu of the Management Console. There are two default user actions supplied with the Management Console: the jrarecording
user action, which initiates a JRA recording on the connected JRockits, and the ctrlbreak
, which sends ctrl-breaks to the connected JRockits.
The parameters specific to a certain user action can be configured either by using the GUI, or by editing the Management Console settings file (see Console Settings File for more information about that file).
Writing your own user action is quite easy. First you create a subclass of AbstractUserAction
(see Listing 7-1), then you enter a deployment descriptor to the consolesettings.xml
file (see Listing 7-2).
Listing 7-1 demonstrates how to make a User Action that retrieves a thread stack dump from all connected JRockits.
package com.example.useractions;
import java.io.IOException;
import java.util.*;
import com.jrockit.console.rjmx.CommonRJMXNames;
import com.jrockit.console.rjmx.RJMXConnectorModel;
import com.jrockit.console.useractions.AbstractUserAction;
/**
* Test action to request a stackdump from JRockit.
* (Just an example; no errorhandling or recovery.)
*
* @author Marcus Hirt
*/
public class StackDumpAction extends AbstractUserAction {
/**
* @see com.jrockit.console.useractions.UserAction#executeAction(List)
*/
public void executeAction(List connections) {
if (connections.size() > 0) {
Iterator iter = connections.iterator();
while (iter.hasNext()) {
RJMXConnectorModel cm = (RJMXConnectorModel) iter.next();
if (cm.isConnected()) {
try
{
System.out.println(CommonRJMXNames.getThreadMXBean(cm).getThreadStackDump());
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
Once the user action is created, you need to enter a deployment descriptor in the consolesettings.xml
, under the user_actions
element. This procedure ensures that your user action visible in the Plugin menu.
<user_action>
<user_action_class>com.example.useractions.StackDumpAction</user_action_class>
<user_action_name>mystackdump</user_action_name>
<user_action_menu_name>My Stack Dump Action</user_action_menu_name>
<user_action_description>Example. Gets a stackdump from every connected JRockit and prints it to stdout.</user_action_description>
</user_action>