JMX HelloWorld

By vijay on October 7, 2005 — 2 mins read

Introduction

JMX or Java Management eXtensions gives you the ability to manage programs remotely. I’ve been working on JMX in one of the SOA application. I would like to share how my first program in JMX has been written and deployed onto JBoss. The MBeans are also know as Platform MBeans (MBeans – Management Beans). You can use JMX to remotely invoke the function on an object. In layman terms, JMX MBeans can be used as "Remote Control" for the "Object that implements the MBean". Using the MBean the object’s operations can be invoked remotely. The JBoss application server has been constructed over a microkernel that uses JMX specification. Every service JBoss provides is an MBean or collection of MBeans. Different kinds of MBeans and notifications are not covered in this article. This article just explains two examples: The plain MBean (HelloWorld), and creating and deploying MBean in the JBoss as an SAR (Service Archive).

The HelloWorld MBean

As already told, MBeans are a way to control the Object remotely. A JMX Agent will expose the MBeans to the platform. Here are the setps to create the first Manageable Object using MBeans.
Step 1: Create the HelloWorldMbean class with sayHello method (Note: MBean interface to be named as ***Mbean):

Step 2: Create the Implementation for the MBean:

Step 3: Create an Agent that exposes the MBean to the platform, so that we can manage it remotely:

Once the three classes are created, compile all of them, and then run the Agent class using the command java -Dcom.sun.management.jmxremote com.vijaykiran.jmx.HelloWorldAgent If you are using Eclipse then, you need to set the VM arguements in the "Run…" dialog. If you want you can download the Zip file Eclipse Project at the end of the article. Now your Agent is running and exposed to the platform. If you want to invoke the function, goto command line and use the jconsole command to strart the JMX console. The command is in your Javabin directory.

Click on Connect, then goto MBeans Tab. You’ll find com.vijaykiran.jmx package on the left, and expand it to get the HelloWorld Mbean. And then select it and on the right pane, click on the Operations tab. You’ll find the sayHelloButton(). Click on it, and your method is ivoked via the exposed MBean.

Posted in: Programming

Leave a comment

Leave a Reply