October 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Integrating your Java Application with Existing Network Management Solutions with JMX

  • July 1, 2004
  • By Olexiy & Alexander Prokhorenko
  • Send Email »
  • More Articles »

The next step, after creating this applet, according to the parts considered above JMX framework, is to start with the instrumentation layer. Here it is just necessary to allocate methods that carry out a functional part of the application. In our case, it is the getCounterValue(), setCounterValue(), incCounterValue(), and decCounterValue() methods. In other words, for management will be the exposed counterValue field.

Further, we implement an MBean of the standard type, such at which all attributes, operations, and events are determined during compilation by the fixed management interface. So, we will define the interface with the CounterFrameMBean name:

public interface CounterFrameMBean {
   public void setCounterValue(Integer value);
   public Integer getCounterValue();
   public void incCounterValue();
   public void decCounterValue();
}

This interface contains prototypes of methods that are implemented in the CounterFrame class. JMX Agent should independently define which attributes and operations are subject to manipulation and agree with MBean of such a kind. Now, we shall start creating such an JMX Agent.

JMX agent loads MBean into a special MBean server. It also gives a number of necessary services, connectors, and adapters to JMX managers or directly to EMS/NMS.

In the code of agent, it is necessary to put in an executed part of the application, in a main() method of the MainApp class. The code will look like this:

BaseAgent myAgent = new BaseAgent();
myAgent.startAgent( (Object) cms);

The BaseAgent class should carry out at least three functions:

  • Start a MBean server
  • Register a MBean in this MBean server
  • Start a protocol adapter or connector

So, for the first part:

MBeanServer server = MBeanServerFactory.createMBeanServer();

And for the second:

try {
   ObjectName mbName = new ObjectName("MBean:name=CounterFrame");
   server.registerMBean(mbObject, mbName); 
   // mbObject - object, passed to method startAgent() of class CounterFrame
} catch (Exception e) {
   System.out.println("Impossible to register CounterFrameMBean!");
   e.printStackTrace();
   return;
}

And, last, but not least, it is necessary to start a protocol adapter and/or connector to give access to our application to managing applications. There are a number of different ways and variants how to do that. Different manufacturers present their own protocol adapters and connectors. We will take advantage of a class com.sun.jdmk.comm.HtmlAdaptorServer (from the implementation of the JMX specification from Sun Microsystems: http://java.sun.com/products/JavaManagement/). By default, this class will listen to port 8082 for HTTP connections.

Here is the code:

HtmlAdaptorServer hadaptor = new HtmlAdaptorServer();
ObjectName adaptorName = null;
try {
    adaptorName = new ObjectName("Adaptor:name=hadaptor,port=8082");
    server.registerMBean(hadaptor, adaptorName);
} catch(Exception e) {
    System.out.println("?????????? ??????? HTML adaptor!");
    e.printStackTrace();
    return;
}
hadaptor.start();

It's the final part of our simple JMX agent.

Having compiled all these classes, we will get the complete applicaton that can be operated with a help of a Web browser. It is enough just to go to the http://localhost:8082 address. But, it also is necessary to take into account that, except for the HtmlAdaptorServer class, there is a set of other different control facilities; some of them are built in and others are provided as separate applications.

Additional Abilities of JMX

JMX allows you to carry out many more functions than just a framework of remote management. It gives additional services that you can make the basic part of your development process. We shall see the small list of these opportunities below:

  • Notices on events: Interfaces are supplied with an opportunity of broadcasting notices among events listeners. An Event can be, for example, a simple change of an attribute. It allows MBeans to cooperate with others MBeans or a remote manager and to notify each other on changes of a condition/status.
  • Monitoring: Monitor MBeans can send notices on events to registered listeners. Listener can be another MBean or application. Target objects of supervision over attributes can be counter, gauge, and string. You can read more in detail about them in the specification.
  • The timer: A Timer MBean will send notices to registered listeners on the approach of a certain time or the expiration of the set interval.

Afterword

JMX is a significant and extremely useful framework that you now can integrate with minimal efforts into your application. JMX can easily be integrated with already existing management technologies, for example, SNMP, and also "future" technologies such as CIM/WBEM.





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel