The XMOJO Project
<< Prev Chapter 3.2.3 M-Let Service Next >>

M-Let Service


The M-Let service allows you to instantiate and register in the MBeanServer, one or several MBeans coming from a remote URL. The M-Let service itself is implemented as a StandardMBean and registered as one of the MBeans in the MBeanServer. So, it can be used by other MBeans, agent applications, or remote management applications.

The classes of the M-Let service are members of the javax.management.loading package. javax.management.loading.MLet class implements the MLetMBean and also extends the java.net.URLClassLoader. Thus, M-Let is a StandardMBean and also a class loader.

 Instantiating and Registering MBeans from a Remote URL 

The M-Let service loads an m-let text file which contains information about the MBeans that have to be registered. The information on each MBean is specified in an XML-like tag, called the MLET tag. The location of the m-let text file is specified by a URL. When an m-let text file is loaded, all classes specified in MLET tags are downloaded, and an instance of each MBean specified in the file is created and registered with the MBeanServer.

The M-Let service is depicted pictorially below to give you a better understanding about how this service works:

How MLet Service works

The MLet class has a method called getMBeansfromURL. The two overloaded versions of this method take the URL argument as a String or as a java.net.URL object. In this URL argument, the location of the m-let text file is specified so that the MBeans specified in the MLET tags are instantiated and registered, if all the resources are available and the m-let text file has proper MLET tags.

 The MLET Tag 

The general syntax of a MLET tag is shown below:
<MLET  
            CODE = class | OBJECT = serfile
            ARCHIVE = "archiveList"  
            [CODEBASE = codebaseURL]
            [NAME = MBeanName]
            [VERSION = version]
>
[argList]
</MLET>

The m-let text file may contain any number of MLET tags, each for instantiating a different MBean in a JMX agent.

 Mandatory Fields 

 Optional Fields 

  <ARG TYPE=argumentType VALUE=argumentValue>  
where :
argumentType is the class of the argument
argumentValue is the string representation of the value of the argument

 A Sample M-Let File 

A Sample m-let text file with only one MLET tag is shown below :

  <MLET  CODE=ServerInfo ARCHIVE="mbeans.jar" CODEBASE=http://localhost:8080/test_mlet NAME=MyMBean:type=Dynamic >
  <ARG TYPE=java.lang.String VALUE=localhost>
  <ARG TYPE=java.lang.Integer VALUE=8080>
  </MLET>

If the getMBeansfromURL method is invoked by passing the location URL of the above m-let text file, the MLet tries to load the class named ServerInfo from the mbeans.jar present in the URL http://localhost:8080/test_mlet. On successful loading of the ServerInfo class, the MLet tries to instantiate the class by invoking the constructor which takes two arguments in the order String, Integer, i.e, it tries to create an instance of ServerInfo using the constructor ServerInfo("localhost" , new Integer(8080) ). On successful instantiation, the MLet class tries to register this instance specifying the object name as MyMBean:type=Dynamic. It uses the registerMBean(Object object, ObjectName name) method of the MBeanServer.

Points to Remember
  1. MLet is implemented as a StandardMBean and registered with the MBeanServer of a JMX agent.
  2. MLet extends java.net.URLClassLoader and hence it is a class loader.
  3. Using the M-Let service, dynamic registration of MBeans from a remote URL is possible.

<< Prev Home Next >>
String Monitor Service
Adaptors Level