Please or
Try NowBuy Now

Locations of visitors to this page

SourceForge.net

SourceForge.JP

JMX Control
JMX Control

Controlling the Java Service Wrapper using JMX

The Java Service Wrapper provides a pair of Java Management Extensions (JMX) MBean interfaces (J2SE 5.0 JMX, JavaSE6 JMX) which make it possible to control the Wrapper using a JMX interface. This section will describe how to configure your JMX enabled application so that the MBeans provided with the Java Service Wrapper are available.

JConsole

Sun's JDK 5.0 includes the Java Monitoring and Management Console tool "JConsole" (J2SE 5.0 JConsole) (JavaSE6 JConsole). See the above link for details, but JConsole makes it easy to connect to properly configured JVMs and monitor and manage their various functions.

For security reasons, the ability to remotely monitor a JVM is not enabled by default. To enable this functionality, it is necessary to define the com.sun.management.jmxremote (J2SE 5.0) (JavaSE6) system property when launching the JVM. This can be done using the Wrapper by specifying a JVM parameter with the wrapper.java.additional.<n> property as follows.

Example: (a JVM parameter)
wrapper.java.additional.1=-Dcom.sun.management.jmxremote

The Java Service Wrapper currently provides 2 MBean interfaces.

The primary MBean interface, org.tanukisoftware.wrapper.jmx.WrapperManagerMBean, provides basic information about the Wrapper and JVM as well as the ability to stop and restart the JVM as well as trigger a full thread dump. The registration of this MBean is controlled by setting the org.tanukisoftware.wrapper.WrapperManager.mbean system property. It is enabled by default.

The second MBean interface, org.tanukisoftware.wrapper.jmx.WrapperManagerTestingMBean, makes it possible to trigger various failure states for testing and should not be made enabled outside of a testing environment. The registration of this MBean is controlled by setting the org.tanukisoftware.wrapper.WrapperManager.mbean.testing system property. It is disabled by default.

Example: (a JVM parameter)
wrapper.java.additional.1=-Dcom.sun.management.jmxremote
wrapper.java.additional.2=-Dorg.tanukisoftware.wrapper.WrapperManager.mbean=TRUE
wrapper.java.additional.3=-Dorg.tanukisoftware.wrapper.WrapperManager.mbean.testing=false

The registered Wrapper MBeans will show up on the MBean tab of the JConsole interface under the org.tanukisoftware.wrapper package.

JBoss

Registering the Java Service Wrapper's MBean interfaces with JBoss is surprising simple. This assumes that you have already gotten JBoss integrated with the Java Service Wrapper. See the Integration Method 1 section, in particular the example using JBoss. This explanation assumes that you have installed all of the Wrapper files in the locations described in the JBoss integration example. Particularly the wrapper.jar file is assumed to be located in the ${jboss.home}/lib directory.

JBoss allows you to register as an MBean, any Object which implements an interface whose name is the same as the class, appended by "MBean". The Java Service Wrapper provides two such classes WrapperManager and WrapperManagerTesting in the org.tanukisoftware.wrapper.jmx package.

The first class, WrapperManager, provides several functions to restart and stop the JVM as well as providing other information about the Java Service Wrapper. The second class, WrapperManagerTesting, exposes a few methods which can be useful in the testing cycle. They are broken out in case you wish to not include them in a final product release. See the JavaDocs for more details.

To register both of the above MBeans, create an XML file named "java-service-wrapper-service.xml" in the ${jboss.home}/server/default/deploy directory. The file should contain the following:

Example: (java-service-wrapper-service.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<server>
    <classpath archives="wrapper.jar" codebase="../../lib"/>
    
    <mbean code="org.tanukisoftware.wrapper.jmx.WrapperManager"
           name="JavaServiceWrapper:service=WrapperManager"/>
    
    <mbean code="org.tanukisoftware.wrapper.jmx.WrapperManagerTesting"
           name="JavaServiceWrapper:service=WrapperManagerTesting"/>
</server>

Notice that the location of the wrapper.jar file is relative to the location of the XML file.

Upon saving the file, JBoss should detect it and register your new MBeans almost immediately. No need to restart JBoss. Pretty Cool.

Now, to actually use the new MBeans, simply point your browser to JBoss's JMX interface at: http://localhost:8080/jmx-console/ You should notice a JavaServiceWrapper Agent with two MBeans, WrapperManager and WrapperManagerTesting. Selecting either MBeans will present you with a set of attributes and actions provided by the MBean.

MX4J

To do. (This section is incomplete and just a jumble of my notes at this point. Feel free to send in any suggestions for this section)

MX4J

Sun JMX Reference Implementation

To do. (This section is incomplete and just a jumble of my notes at this point. Feel free to send in any suggestions for this section)

Sun's reference implementation is just that, a reference implementation. There are not a fixed set of steps that you can follow to register the the Wrapper's MBeans. Each application tends to have created their own custom way of registering such beans.

Although many applications have defined their own syntax, Sun has defined MLET tags, short for Management Applet, as a means for defining MBeans. Their syntax is described in the JavaDocs for the javax.management.loading.MLet (J2SE 1.4) (J2SE 5.0) (JavaSE6) class. The following MLET tags can be used to register the MBeans provided with the Wrapper. Notice that they are not really XML.

MLET tags:
<MLET
    CODE = org.tanukisoftware.wrapper.jmx.WrapperManager
    ARCHIVE = "../lib/wrapper.jar"
    NAME = JavaServiceWrapper:service=WrapperManager>
<MLET
    CODE = org.tanukisoftware.wrapper.jmx.WrapperManagerTesting
    ARCHIVE = "../lib/wrapper.jar"
    NAME = JavaServiceWrapper:service=WrapperManagerTesting>

More information is available on Sun's "Java Managagement Extensions (JMX) Home Page".

(Java Management Extensions(JMX) Documentation: J2SE 5.0 / JavaSE6)





User Comments

If you notice something that is incorrect, missing, or simply feel that some part of this page could be explained better, feel free to log in and add a comment. You will need to register before you can log on.

Email:
Password:
by alpiv (2007/12/11 01:42:31 JST from 168.215.73.114)
Gravatar

Note about Jboss integration with Jconsole.
There seems to be a problem when your ear contains web-services.
If you receive a null pointer exception with regards to Loading a WSDL file location.
Please refer to the following:
http://jbws.dyndns.org/mediawiki/index.php?title=FAQ#How_to_use_JDK_JMX_JConsole_with_JBossWS.3F

by Graeme Harker (2007/05/19 15:39:49 JST from 77.68.16.117)
Gravatar

1) This page should be updated as setting -Dcom.sun.management.jmxremote is no longer required in the v6 JVM.

2) By default on Windows the direct attach won't work as Windows Services run in the "Local System" security context and jconsole can only make direct connections to processes in the same security context. As a consequence Wrapper services are invisible to jconsole by default and the approach described in this documentaiton won't work on Windows. John Halliman's example should be included in this page.

by John Hallman (2007/01/25 11:32:51 JST from 151.151.73.164)
Gravatar

I was not seeing the Java process in the Jconsole window, so I did this

wrapper.java.additional.1=-Dcom.sun.management.jmxremote.port=9999
wrapper.java.additional.2=-Dcom.sun.management.jmxremote.authenticate=false
wrapper.java.additional.3=-Dcom.sun.management.jmxremote.ssl=false
wrapper.java.additional.4=-Dorg.tanukisoftware.wrapper.WrapperManager.mbean=true

restartedm the service, started jconsole connected to localhost:9999 and it works like a charm

by Andreas Brenk (2006/01/03 20:51:30 JST from 80.171.34.198)
Gravatar

Registering the WrapperManager MBean using Spring JMX is as simple as:

<bean id="wrapperManager" class="org.tanukisoftware.wrapper.jmx.WrapperManager"/>
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="JavaServiceWrapper:service=WrapperManager" value-ref="wrapperManager"/>
</map>
</property>
</bean>

This can be used in the applicationContext.xml of a web application deployed to Tomcat 5.5 for example.

Further documentation can be found at http://www.springframework.org/docs/reference/jmx.html

by Zhu Wenbin (2005/11/14 02:59:38 JST from 210.6.198.235)
Gravatar

I have written a simple example using Sun JMX Reference Implementation. You can download it from http://iwen.net:8080/wrapper-jmx.tar.bz2

The example is written for linux. But you can easiy modify the batch scripts to make it work on windows.

The net.iwen.vrp.mdvrp.ServiceWrapperHelper class implements WrapperListener and register the MBean. The net.iwen.vrp.mdvrp.TestServiceJMXClient class demostrates how to use JMX to monitor and control status of the wrapper service.

Java Service Wrapper Version: 3.5.4