In this example we will only load EquilateralTriangle MBeans through the m-let file. We use the same m-let file which is shown in Example 12-2, but without the tags for the Square MBeans.
The code for downloading the MBeans specified in the m-let file is also similar. In the Java 2 version of the m-let loader, only the name of the method to call and the format of its return value is different. In this code we call the getMBeansFromURL method and analyze the result:
// the url_2 string is read from the command line echo("\tURL = " + url_2); Object mletParams_2[] = {url_2}; String mletSignature_2[] = {"java.lang.String"}; Set mbeanSet = (Set) server.invoke(mletName, "getMBeansFromURL", mletParams_2, mletSignature_2); for (Iterator i = mbeanSet.iterator(); i.hasNext(); ) { Object element = i.next(); if (element instanceof ObjectInstance) { // Success, we display the new MBean's name echo("\tOBJECT NAME = " + ((ObjectInstance)element).getObjectName()); } else { // Failure, we display why echo("\tEXCEPTION = " + ((Throwable)element).getMessage()); } } |
The structure of the returned set is much simpler than in the case of the JDK 1.1 loader. In the JDK 1.1 version, the m-let loader handles separate class loader objects, one for each code-base it has accessed. In the Java 2 version, the m-let loader is the class loader, and it handles just a list of code-bases that it has accessed directly. You can view this list by calling the getURLs method of the m-let loader MBean.
This behavior means that the getMBeansFromURL method does not need to return the object names of class loaders it has used. Instead it just returns either the object instance of the downloaded and registered MBean or a Throwable object in case or an error or an exception. These are returned in a Set object containing as many elements as there are MLET tags in the target m-let file.