Thursday May 11, 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
Jean-Francois
Posted by jeanfrancoisdenise
( May 11 2006, 09:27:49 PM GMT+02:00 )
Permalink
Friday March 10, 2006 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.
Jean-Francois
Posted by jeanfrancoisdenise
( Mar 10 2006, 04:17:27 PM GMT+02:00 )
Permalink
Monday February 13, 2006 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 :
grant codeBase "file:In this grant block we listed the set of required permissions in order to access the platform MBeanServer, register an MBean instance of class/-" { // Allow access to ManagementFactory.getPlatformMBeanServer() permission javax.management.MBeanServerPermission "createMBeanServer"; //Permission to register our MBean permission javax.management.MBeanPermission "my.sample.server.HelloPrefixProvider#-[server.sample.my:type=HelloPrefixProvider]", "registerMBean"; //Permission to get HelloPrefix attribute permission javax.management.MBeanPermission "my.sample.server.HelloPrefixProvider#HelloPrefix[server.sample.my:type=HelloPrefixProvider]", "getAttribute"; };
my.sample.server.HelloPrefixProvider, named server.sample.my:type=HelloPrefixProvider. 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 theHelloService (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!
toolbar icon.
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 theServiceImpl 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.service:jmx:rmi://localhost:28732/jndi/rmi://localhost:28732/jmxrmi
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. Posted by jeanfrancoisdenise ( Feb 13 2006, 01:04:07 PM GMT+02:00 ) Permalink
Thursday February 02, 2006 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 ("server.sample.my:type=HelloPrefixProvider" 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)
MBeanServerInvocationHandler.newProxyInstance(mbs,
new ObjectName("server.sample.my:type=HelloPrefixProvider"),
HelloPrefixProviderMBean.class,
false);
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:
@WebMethod
public String hello(@WebParam(name="name") String s) {
System.out.println("Service received: " + s);
return "Hello "+s;
}
It becomes:
@WebMethod
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.
<your netbeans install path>/enterprise2/jakarta-tomcat-5.5.9/bin/catalina.bat (.sh for Unix users) -Dcom.sun.management.jmxremote system property to the Tomcat JVM run command line. For each exec command, add the required property. The following is a catalina script extract :
...
exec "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
-Djava.security.manager \
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
-Dcom.sun.management.jmxremote\
org.apache.catalina.startup.Bootstrap "$@" start
...
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 server.sample.my 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!
Jean-Francois
Posted by jeanfrancoisdenise ( Feb 02 2006, 04:46:40 PM GMT+02:00 ) Permalink
Friday January 20, 2006
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.
http://www.netbeans.org/kb/articles/jmx-getstart.html
http://management.netbeans.org/jmx
JF.
Posted by jeanfrancoisdenise
( Jan 20 2006, 11:22:36 AM GMT+02:00 )
Permalink
Thursday December 22, 2005
AWTEvents mbean = AWTEvents.getDefault();
ManagementFactory.getPlatformMBeanServer().registerMBean(mbean,new ObjectName(":type=AWTEvents");
Recompile and relaunch your application.





Thursday November 17, 2005 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 netbeans.org 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!
Jeff.
PS: I am impatiently waiting for Mac OS X community developpers feedbacks.
Posted by jeanfrancoisdenise
( Nov 17 2005, 07:50:15 PM GMT+02:00 )
Permalink
Comments [1]
Wednesday November 02, 2005
A. Sundararajan
Alan Bateman
Daniel Fuchs
Éamonn McManus
Joël Féraud
Mandy Chung
Luis-Miguel Alventosa