Thursday May 11, 2006

JMX NetBeans lab at JavaOne 2006

This year at javaone I will lead the lab 5120 "Application Monitoring and Management with NetBeans™ 5.0".

During this lab you will learn how to instrument your own Java application using the JMX NetBeans tooling. Once the application instrumented, you will use JConsole to monitor the application.

You will also learn how to write a JMX client application and remotely connect to the JMX agent to access MBean information.

The lab is a 60 minutes one. All has been setup for you to focus on the exercices. The lab team, led by Sang Shin, has done a wonderful job to make your lab a delightful experience.

Hope to meet you there on Friday (05/19/2006 10:45 AM - 11:45 AM) at the Moscone Center Hall E 130/131


Friday Mar 10, 2006

JMX NetBeans module demo at Java Expo 06

Tuesday, March 21,

Luis-Miguel Alventosa, a member of JMX team, will be presenting Monitoring and Management in Java SE 5.0 at Java Expo '06 in Madrid.

During his talk he will use the JMX NetBeans module to demonstrate the Java SE 5.0 Monitoring and Management features.

You will see JConsole launched from NetBeans, connecting to a Java Swing application to manage its AWT event queue.

If you want more info on this AWT to JMX bridge, you can read the blog entry I wrote in december 2005.

You still have time to register for the event. Don't forget the NetBeans Software Day on Thursday 23rd.


Monday Feb 13, 2006

GlassFish : Managing JAX-WS 2.0 services with JMX

In Netbeans 5.0 obviously...

My previous blog entry,"JMX to manage JAX-WS 2.0 service using NetBeans" created an interest in the aquarium community. I have been contacted from underneath the water in order to address the same use case in GlassFish.

I want to say first that it has been a real pleasure to make JMX and JConsole work in the context of GlassFish. Configuring Tomcat to allow JMX remote access by updating the catalina script to enable remote management is quick but a little dirty too.

Let's see what are the necessary steps to achieve the scenario in my previous blog entry.

GlassFish NetBeans integration (if needed)

Simply follow this GlassFish NetBeans IDE integration. Then make the JAX-WS20Project to use the GlassFish installed server.

Grant the required permissions to the JAX-WS20Project application to deal with JMX

When dealing with J2EE containers, something that makes a big difference is the security aspect. GlassFish enables Java security by default. All GlassFish deployed applications run with a very limited set of permissions. When management is in the picture, this is really a must.

Management can't be understood outside of a secured context. Management actions are generally so critical that they make sense only in a fully secured context.

This being said, let's grant the application code base the required permissions. In order to find out your application's codebase, start the Glassfish Management console, select the JAX-WS20Project application. The code base is the value of the Location property.

The following picture shows you the administration view of the JAX-WS20Project application.

Granting permission in GlassFish, is explained very well in the Securing GlassFish applications article.
A single step is needed :

  • Edit <your domain>/config/server.policy and add the following grant block

    grant codeBase "file:/-" {
    // Allow access to ManagementFactory.getPlatformMBeanServer()
    permission "createMBeanServer";
    //Permission to register our MBean
    permission "my.sample.server.HelloPrefixProvider#-[]", "registerMBean";
    //Permission to get HelloPrefix attribute
    permission "my.sample.server.HelloPrefixProvider#HelloPrefix[]", "getAttribute";
    In this grant block we listed the set of required permissions in order to access the platform MBeanServer, register an MBean instance of class my.sample.server.HelloPrefixProvider, named We also granted the permission to get the MBean attribute HelloPrefix. (If you want to learn more about JMX permissions, see MBeanPermission and MBeanServerPermission javadoc)

Need to restart GlassFih?

No, you don't need to. The server.policy file will be loaded when your app will be deployed. That is really really cool!

Deploy JAX-WS20Project

Simply run the project and send a first request to the HelloService (thanks to the NetBeans Web Service Registry) in order to register the HelloPrefixProvider MBean.

Connecting JConsole

This is my favorite part. It is very simple and very well integrated with the GlassFish management framework. A few years ago I had a really bad time trying to remotely access some JMX MBeans running in AppServer 7...I can tell you that this is now history!
  • Launch GlassFish Admin Console.
  • Select Configuration/Admin Service/System nodes
  • The JMX Connector configuration is displayed. Among other things, you can see the address, port and protocol that are used in order to establish a connection.

  • Note the port number. 28732 in this example.
  • Launch JConsole from NetBeans. Click on the toolbar icon.
  • In the JConsole Connection Dialog, select the Remote tab.
  • Type in the port number, the admin user and password (admin, adminadmin are default glassfish values)

  • Select the MBeans Tab. Tree node contains HelloPrefixProvider MBean. You can start playing with HelloPrefix attribute.

    You noticed the existence of new JMX management domains (amx, amx-support, ias, com.sun.appserver). These nodes contain the set of MBeans that form the GlassFish JMX based management and monitoring framework.

Here we are, we acheived exactly what we did in Tomcat. My feeling is that we did it in a better/cleaner way. We didn't start any new components or hack any scripts. We just reused what was there, ready to serve our needs. Our management solution is also more secure.

Stacking the "Java 2 Somethings"

I hope that you also noticed that not a line of JMX code was changed from the ServiceImpl JAX-WS 2.0 service. When GlassFish is running on top of JDK 5.0 it uses the platform MBeanServer. Deploying your own MBeans in this MBeanServer helps you reuse upper layers (such as J2EE servers) management infrastructure for free. In my first blog entry I tried to explain the power that is brought to your application when relying on a Standard JMX framework. I think that this case helps you understand all the benefits.

Jean-Francois Denise

Just in case you want some more, I added a little chapter in order to optimize your JConsole connection task from NetBeans

Adding a default URL to JConsole

When starting/stopping a GlassFish server, you will need to reconnect JConsole. The NetBeans integration of JConsole comes with a set of Options. One of them allows you to provide a URL to which JConsole will connect when starting.
NetBeans Options are located under menu Tools > Options . The following window is displayed.

To access the JConsole options, click on the Advanced Options button in the bottom left corner, then select IDE Configuration > Server and External Tools Setting > JConsole. In the Default URL property, provide the full JMXServiceURL. In our case it is :


You will notice that credentials are not stored in properties. It is not recommanded that you store such critical information. Each time you will relaunch JConsole, JConsole will connect to the Glassfish server and you will be prompted for user name and password.

Thursday Feb 02, 2006

JMX to manage JAX-WS 2.0 service using NetBeans 5.0

NetBeans 5.0 is out!

Among a full set of exciting features, check the NetBeans Home Page, it brings a very very cool support for Web Services. If you have not already played with web services, you should start doing so. It is becoming much simpler with JAX-WS 2.0.

As you already know, I blogged few weeks ago about that, JMX is now part of the set of stable modules.

Management Of Web Services (MOWS is sometimes found in literature) is a hot topic. More and more people are writing web services that need to be managed. I think that it is an appropriate time to start speaking about a possible bridging of JAX-WS and JMX technologies.

I am not going to detail how to write a webservice using Netbeans. Bobby Bissett and Milan Kuchtiak wrote an excellent tutorial on how to setup netbeans to work with JAX-WS 2.0. I am going to extend their tutorial by adding the necessary steps to add manageability to this webservice.

The ServiceImpl webservice has got a single method named hello. This method prefixes the received string with "hello" string and returns it. In Bobby and Milan's tutorial, the added prefix is hard coded in the hello method implementation. We are going to use this very simple case to see how we could use JMX to make the prefix updated dynamically. I assume that JAX-WS20Project is open and working well in your netbeans IDE.

Generating the HelloPrefixProvider MBean

I wrote a tutorial that explains how to write an MBean. To access the MBean wizard : File > New File > Management > JMX MBean. You can follow the steps defined in the tutorial to generate a HelloPrefixProvider Standard MBean. It contains a single read/write attribute of type String named HelloPrefix. No operation, no notification.

Generating the JMX Agent

I wrote a tutorial that explains how to write a JMX Agent. Follow it to generate a JMXAgent class that will be added to your webservice.

Adding the HelloPrefixProvider MBean to the Agent

I wrote a tutorial that explains how to register an MBean in a JMX Agent. Follow it to create and register the HelloPrefixProvider MBean in the JMXAgent.

Make the JAXWS service ServiceImpl access the Prefix attribute

In this step we are going to update the JMXAgent with an accessor that returns the HelloPrefixProviderMBean interface. This method will be used by the service to access the prefix.

In order to increase our JMX knowledge, we are going to make use of a very useful class MBeanServerInvocationHandler. This class is generally used on the JMX manager side to create MBean proxies. We are going to use it on the agent side to make MBean handling simpler. If you have an MBean server mbs containing an MBean with ObjectName name ("" in our case), and if the MBean's management interface is described by the Java interface Intf (HelloPrefixProviderMBean in our case), you can construct a proxy for the MBean like this:

 HelloPrefixProviderMBean proxy = (HelloPrefixProviderMBean)
                                                   new ObjectName(""),

So we add a getPrefixProvider() method that returns a proxy to the MBean prefix provider.

Your JMXAgent code should look like this:

Now we add the code to access the prefix attribute from the JAX WS 2.0 ServiceImpl service.
The current method implementation is:

    public String hello(@WebParam(name="name") String s) {
        System.out.println("Service received: " + s);
        return "Hello "+s;
It becomes:
    public String hello(@WebParam(name="name") String s) throws Exception {
        System.out.println("Service received: " + s);
        return JMXAgent.getDefault().getPrefixProvider().getHelloPrefix() + " " + s;

We simply replaced the "hello " string by a call to access the prefix attribute. Lazily, when the service is first called, we deploy the management and access to the default prefix value.

We are done! The service has been very lightly impacted. A single line of code has been needed to make the service much more dynamic.

Compile your project.

Configuring Tomcat to connect with JConsole

In order to enable JConsole access to the Tomcat JVM management data, the Tomcat launch script must be updated.

  • Edit <your netbeans install path>/enterprise2/jakarta-tomcat-5.5.9/bin/catalina.bat (.sh for Unix users)
  • Add a system property to the Tomcat JVM run command line. For each exec command, add the required property. The following is a catalina script extract :
          -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \\ 
"$CATALINA_BASE"/conf/catalina.policy \\ 
          -Dcatalina.base="$CATALINA_BASE" \\      
          -Dcatalina.home="$CATALINA_HOME" \\       
          org.apache.catalina.startup.Bootstrap "$@" start
You are DONE with configuration. You are now able to view your MBeans (and all other JVM MBeans) from JConsole.

Running and testing JAX-WS20Project

Click on Run project. The project is compiled, a war is generated, tomcat is started and your web service is deployed ready to serve client requests. Go to the WebService registry, as explained in Bobby and Milan tutorial, and activate the hello operation. The first call to hello request will deploy JMX management.

Now, launch JConsole by clicking on Toolbar button .

Connect to tomcat JVM by selecting org.apache.catalina.startup.Bootstrap JVM as shown in the following image:

Go to the MBeans tab and select HelloPrefixProvider MBean located under node. Type in a value for the HelloPrefix Attribute:

Check the new prefix value from the Web Service registry...

... it has been updated with what you typed in JConsole. The bridge is created! Ok the river was not very wide, but consider it a start to building your own suspension bridge.

I hope that this blog entry helped you better understand how JMX and JAX-WS can be used together. And again, great Welcome to NetBeans 5.0!


Friday Jan 20, 2006

NetBeans JMX module goes stable

Today, is the JMX module day!

JMX module is mature enough to be granted a release number of 1.0! Starting from 0.1, it made is way to 1.0 in few months.

It has been considered stable enough by the community to be moved to the product level quality modules area.
It means that, if you do not already do so, you should rely more strongly on this module for your Java monitoring and JMX development.

The main change you will encounter is related to downloading the module. It is getting simpler.
Previously, you had to select NetBeans Update Center beta check box from Update Center Panel.
This step is no more needed.

I provide you with pointers to Getting Started, Tutorial and Management project page.
Don't forget that there is also a detailed Java Help.


Thursday Dec 22, 2005

A JMX MBean to visualize AWT events

Some MBean seem generic enough to be deployed in any Java application. Why not share them?

I recently developed an MBean that can be dropped in any Java application. It will export AWT events in the JMX world. Using JMX monitoring tools, you can visualize what is happening when the mouse is moved, a button is pressed and much more. The today MBean code is verbose and could be optimized but I think that it makes a start.

Your application doesn't need any particular modifications. Just download the MBean sources (Standard MBean class and interface), compile them and deploy the MBean in your application.

1 Deploying the MBean

This MBean follows the singleton pattern. A single MBean instance is deployed per application. Call AWTEvents.getDefault in order to access the singleton mbean. Then register it in an MBeanServer. Using JDK 5, you can use the platform MBeanServer.

     AWTEvents mbean = AWTEvents.getDefault();
     ManagementFactory.getPlatformMBeanServer().registerMBean(mbean,new ObjectName(":type=AWTEvents");

Recompile and relaunch your application.

2 Monitoring thanks to JConsole

Connect JConsole to the running process. NetBeans users, have a look to JMX module documentation to see how to automatically connect JConsole to your running project.

Once JConsole is connected to your application, select MBeans Tab then AWTEvents mbean.
You should see something like:

JConsole 1

For each AWT event (Invocation, Action, Mouse, ...) an MBean attribute is exposed. It displays the number of time an event has occurred.

An interesting thing to visualize is the attribute value plotting. Double clicking on numerical values will make a plotter to be displayed.
If you double click on NumMouseMotionEvents attribute value and move mouse pointer on top of your application, you should visualize something like :
JConsole 2

You can do the same for any numerical attributes.

What about receiving a JMX notification when an AWT event occurs?
CurrentNotificationFilter, writable attribute, allows you to express for which AWT event a JMX notification is to be sent. To see the list of possible filters, double click on PossibleNotificationFilterValues attribute.

JConsole 3

You can provide multiple filters by using '|' as separator. Setting to all filter will make all AWT events to be translated into JMX Notifications.

JConsole 4

Select Notifications Tab to visualize received notifications. First subscribe then play with your app. You should received a lot of JMX Notifications.
JConsole 5

Want to stop the translation ? Select Operations Tab. From here you can start the translation, stop it or reset attribute counters.

JConsole 6
Have fun and be prepared to share your MBeans!


Thursday Nov 17, 2005

Mac OS X, netbeans and JMX: a turning point

The story started badly...

Few months ago, Apple released a JDK 5 release 1 for mac OS X. I don't know if you had the chance to play with it, but JVM Management and Monitoring was not really working. (Have a look to Apple radar #4084603). Although netbeans was perfectly running on this JDK, the JMX module was not operational. Wizards were working, but JConsole support was simply broken.

And the story reached a turning point...

Today Apple announced the new release 3 of its JDK 5 integrating a fix for 4084603. You can check :

BTW, you need to update to Mac OS X 10.4.2.

At the same time announced the new beta 2 release of IDE... You can check :

And a new era of synergie has begun... ;-)

More directly, what I wanted to tell you, is that it WORKS!


PS: I am impatiently waiting for Mac OS X community developpers feedbacks.

Wednesday Nov 02, 2005

Relying on a standard JMX framework

The goal of this weblog entry is to detail how the Java JMX management framework can be leveraged when developing applications using Netbeans.

It is difficult to write about Java development outside of the context of an IDE. The way a Java library is used or understood is greatly influenced by the IDE used.
Using the IDE for writing, executing and debugging code is fine, but today we expect more than that. We want an IDE to help us realize the main use cases implied by the technologies we are using.

Among other tools, the Netbeans 5.0 beta release provides tools centered around Swing, XML, Web Services, and JMX API (you can download the JMX module from the beta update center). If you are not yet familiar with these features (including very cool Swing, CVS and J2EE support, among others), you should have a quick look at Roman Strobl's presentation.

Before we start, if you feel that a refresher is needed, have a look at the following excellent JMX API, JConsole and JDK 5 Management and Monitoring articles.

Something that can appear a little confusing when you are trying to find out where the borders of JMX technology are, is the coexistence of the JMX library and the JMX instrumentation of the JVM. You will in fact discover that ignoring this distinction and taking a global approach will make the use of JMX technology much more simple and powerful.

A brief history of JMX technology
In the old days of JMX, everyone who wanted to register MBeans had to create their own MBeanServer, then create and start some kind of non-standard remote access.  A step toward better interoperability was achieved by the introduction of standard RMI access. But still people were not able to rely on a standard "management framework". People had to create multiple paths to access their management. This situation lead to a kind of "management divide".
Java 2 Platform, Standard Edition (J2SE) 5 introduced a new and standard management platform.  The JMX developer can now rely on this management platform to deploy their management. An MBeanServer linked to a fully configurable RMI ConnectorServer are present on any JVM. If you want management you can get going with straight away, just use them!

As an example, management consoles (such as JConsole) rely increasingly on the existence of this standard framework. Deploying your MBeans in this framework will make them accessible from a wide range of JMX managers.

By relying on the Java management platform, you will greatly simplify the way you use JMX. In turn, if your IDE uses it, developing a JMX application should become a child's play... This is what we are going to see.

The Netbeans JMX module relies on the standard management framework. It makes use of the platform MBeanServer when:
  • Generating a JMX Agent. The JMX Agent is a Platform MBeanServer wrapper that allows you to instantiate, name and register your MBeans
  • Generating a JUnit JMX Test. Such tests allow you to activate MBean attributes and operations without dealing with the framework. The MBean under test is automatically registered in this MBeanServer.  At the end of a test session, the MBeanServer is cleaned from the MBean references.
==> During your JMX instrumentation coding and testing phase, you can rely on the presence of the platform MBeanServer.

The Netbeans JMX module makes use of the platform remote RMI access:
  • At execution time: The application under development is automatically launched with the RMI access enabled.
  • At debugging time: The application under debug is automatically launched with the RMI access enabled.
==> During the execution and debugging phases, again, you can rely on the presence of the remote RMI access.

Having your application ready to receive remote management requests is fine, but what about the manager layer? How do JMX managers / consoles enter the scene?
  • If you are not developing a full JMX Manager, you can rely on the JConsole generic management console. It will automatically connect to the running application, allowing visualization of the JVM state and interaction with MBeans.
  • If you are developing a JMX Manager, a JMX URL Editor helps you construct a reference to the remote RMI access.
==> Again, JMX clients will benefit from the existence of this framework.

I said that it's child's play... To help you, I have written a tutorial on how to start a JMX enabled Java application and how to connect to it.
The tutorial shows how the complexity of client / server application development can be reduced when handled directly from inside the IDE.
I recommend that you work through the tutorial. If you think that parts are still too complex, please let me know and we'll find an answer together to improve it.

If you want more details about how to add JMX to your application, you can work through another tutorial that shows you how to develop an MBean, test it, register it and interact with it at runtime.

To conclude, choosing to rely on this standard framework orientates the way you use JMX. One advantage of choosing it is that it will help you build your overall application management system. Making consistent choices will result in a coherent manageability application management solution.



« June 2016