Java Reference
In-Depth Information
methods of the M-let MBean. Fortunately, it supports all the methods you need
for this example. Follow these steps to load the example M-let file:
If you haven't already, select the MLet MBean.
1
Put the cursor in the blank for the getMBeansFromURL() method.
2
Ty p e i n t h e URL to your M-let file. In our case, the URL is file://c:/jmx-
book/ch10/ch10.mlet.
3
Click the button to execute the method. You should get a success message.
4
Go back to the Agent View, and you should see a new HelloWorld MBean
registered in the MBean server.
5
Stop the agent. You will use it for again in the next example, which creates an
MBean without using an M-let file.
Reusing loaded classes
After you have loaded classes specified in an M-let file, they are available for
use again. However, you would need to specify the MLet MBean as the class
loader when creating an MBean from a previously loaded JAR file (from using an
M-let file).
In chapter 8, we discussed the MBean server's overloaded version of the cre-
ateMBean() method, which adds an ObjectName parameter that specifies a class
loader. The overloaded method uses this class loader to search for the MBean
class needed to instantiate the requested MBean. The value of this parameter
should be the ObjectName value of the M-let service. The method invocation to
load another HelloWorld MBean would look like the following:
ObjectName helloName = new ObjectName( "MLetAgent:name=hello2" );
ObjectName mletName = new ObjectName( "MLetAgent:name=mlet" );
mbeanServer.createMBean( "jmxbook.ch2.HelloWorld",
helloName, mletName );
This code results in a new HelloWorld MBean with the specified ObjectName
value. The MBean server relies on the M-let service to act as the class loader for
the jmxbook.ch2.HelloWorld class.
10.3.3
Example: expanding the agent's codebase
At this point, you might be telling yourself that you want to load classes from a
remote location without creating MBeans at the same time. Any time you want to
add classes or add to your codebase, you don't want to have to create an MBean
(for instance, to use an M-let file to load a JAR file).
Search WWH ::




Custom Search