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:
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 m-let text file may contain any number of MLET tags, each for instantiating
a different MBean in a JMX agent.
Mandatory Fields
Either the CODE or the OBJECT field should be present in an MLET tag.
CODE specifies the full Java class name, including package name of
the MBean to be obtained. OBJECT specifies the .ser file that contains a
serialized representation of the MBean to be obtained. The .class or
.ser file must be contained in one of the JAR files specified in the ARCHIVE
field.
ARCHIVE field specifies one or more JAR files. All the JAR files
should be enclosed within double quotes (") and each JAR file should
be separated using a comma (,)
Optional Fields
CODEBASE specifies the code base URL that contains the JAR files specified
by the ARCHIVE field. If the CODEBASE is not specified, the base URL
of the m-let text file is taken as the code base URL.
NAME specifies the String representation of ObjectName with which the
MBean has to be registered.
VERSION specifies the version of the MBean and associated JAR files
to be obtained. It is represented as a series of non-negative decimal
numbers each separated by a dot (.)
argList specifies a list of one or more arguments to pass to the constructor
of the MBean to be instantiated. Each item in the argList corresponds
to an argument in the constructor. The syntax to be followed is
<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 :
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
MLet is implemented as a StandardMBean and registered
with the MBeanServer of a JMX agent.
MLet extends java.net.URLClassLoader and hence it
is a class loader.
Using the M-Let service, dynamic registration of MBeans
from a remote URL is possible.