javax.management.loading
Class MLet

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--java.net.URLClassLoader
                    |
                    +--javax.management.loading.MLet

public class MLet
extends java.net.URLClassLoader
implements MLetMBean, MBeanRegistration

The m-let Service allows you to instantiate and register in the MBeanServer one or several MBeans coming from a remote URL. M-let is a shortcut for management applet. The m-let service does this by loading an m-let text file, which specifies information on the MBeans to be obtained. The information on each MBean is specified in a single instance of a 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, an instance of each MBean specified in the file is created and registered.

The m-let Service extends the java.net.URLClassLoader and can be used to load remote classes and jar files in the VM of the agent.


Constructor Summary
MLet()
          Constructs a new MLet using the default delegation parent ClassLoader.
MLet(java.net.URL[] urls)
          Constructs a new MLet for the specified URLs using the default delegation parent ClassLoader.
MLet(java.net.URL[] urls, java.lang.ClassLoader parent)
          Constructs a new MLet for the given URLs.
MLet(java.net.URL[] urls, java.lang.ClassLoader parent, java.net.URLStreamHandlerFactory factory)
          Constructs a new MLet for the specified URLs, parent class loader, and URLStreamHandlerFactory.
 
Method Summary
 void addURL(java.lang.String url)
          Appends the specified URL to the list of URLs to search for classes and resources.
 void addURL(java.net.URL url)
          Appends the specified URL to the list of URLs to search for classes and resources.
protected  java.lang.Class findClass(java.lang.String name)
          This is the main method for class loaders that is being redefined.
protected  java.lang.String findLibrary(java.lang.String libname)
          Returns the absolute path name of a native library.
 java.lang.String getLibraryDirectory()
          Gets the current directory used by the library loader for storing native libraries before they are loaded into memory.
 java.util.Set getMBeansFromURL(java.lang.String url)
          Loads a text file containing MLET tags that define the MBeans to be added to the agent.
 java.util.Set getMBeansFromURL(java.net.URL url)
          Loads a text file containing MLET tags that define the MBeans to be added to the agent.
 java.net.URL[] getURLs()
          Returns the search path of URLs for loading classes and resources.
 void postDeregister()
          Allows the m-let to perform any operations needed after having been de-registered in the MBeanServer.
 void postRegister(java.lang.Boolean registrationDone)
          Allows the m-let to perform any operations needed after having been registered in the MBeanServer or after the registration has failed.
 void preDeregister()
          Allows the m-let to perform any operations it needs before being de-registered by the MBeanServer.
 ObjectName preRegister(MBeanServer server, ObjectName name)
          Allows the m-let to perform any operations it needs before being registered in the MBeanServer.
 void readExternal(java.io.ObjectInput in)
          This method reads the objects contents during Object Serialization.
 void setLibraryDirectory(java.lang.String libdir)
          Sets the directory used by the library loader for storing native libraries before they are loaded into memory.
 void writeExternal(java.io.ObjectOutput out)
          This method saves the objects contents during Object Serialization.
 
Methods inherited from class java.net.URLClassLoader
definePackage, findResource, findResources, getPermissions, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MLet

public MLet()
Constructs a new MLet using the default delegation parent ClassLoader.

MLet

public MLet(java.net.URL[] urls)
Constructs a new MLet for the specified URLs using the default delegation parent ClassLoader. The URLs will be searched in the order specified for classes and resources after first searching in the parent class loader.
Parameters:
urls - the URLs from which to load classes and resources

MLet

public MLet(java.net.URL[] urls,
            java.lang.ClassLoader parent)
Constructs a new MLet for the given URLs. The URLs will be searched in the order specified for classes and resources after first searching in the specified parent class loader. URLStreamHandlerFactory. The parent argument will be used as the parent class loader for delegation. The factory argument will be used as the stream handler factory to obtain protocol handlers when creating new URLs.
Parameters:
urls - the URLs from which to load classes and resources
parent - the parent class loader for delegation

MLet

public MLet(java.net.URL[] urls,
            java.lang.ClassLoader parent,
            java.net.URLStreamHandlerFactory factory)
Constructs a new MLet for the specified URLs, parent class loader, and URLStreamHandlerFactory. The parent argument will be used as the parent class loader for delegation. The factory argument will be used as the stream handler factory to obtain protocol handlers when creating new URLs.
Parameters:
urls - the URLs from which to load classes and resources
parent - the parent class loader for delegation
factory - the URLStreamHandlerFactory to use when creating URLs
Method Detail

addURL

public void addURL(java.net.URL url)
Appends the specified URL to the list of URLs to search for classes and resources.
Specified by:
addURL in interface MLetMBean
Overrides:
addURL in class java.net.URLClassLoader

addURL

public void addURL(java.lang.String url)
            throws ServiceNotFoundException
Appends the specified URL to the list of URLs to search for classes and resources.
Specified by:
addURL in interface MLetMBean
Throws:
ServiceNotFoundException - The specified URL is malformed.

getURLs

public java.net.URL[] getURLs()
Returns the search path of URLs for loading classes and resources. This includes the original list of URLs specified to the constructor, along with any URLs subsequently appended by the addURL() method.
Specified by:
getURLs in interface MLetMBean
Overrides:
getURLs in class java.net.URLClassLoader

getMBeansFromURL

public java.util.Set getMBeansFromURL(java.net.URL url)
                               throws ServiceNotFoundException
Loads a text file containing MLET tags that define the MBeans to be added to the agent. The location of the text file is specified by a URL. The MBeans specified in the MLET file will be instantiated and registered by the MBeanServer.
Specified by:
getMBeansFromURL in interface MLetMBean
Parameters:
url - The URL of the text file to be loaded as URL object.
Returns:
A set containing one entry per MLET tag in the m-let text file loaded. Each entry specifies either the ObjectInstance for the created MBean, or a throwable object (that is, an error or an exception) if the MBean could not be created.
Throws:
ServiceNotFoundException - One of the following errors has occurred: The m-let text file does not contain an MLET tag, the m-let text file is not found, a mandatory attribute of the MLET tag is not specified, the value of url is null.

getMBeansFromURL

public java.util.Set getMBeansFromURL(java.lang.String url)
                               throws ServiceNotFoundException
Loads a text file containing MLET tags that define the MBeans to be added to the agent. The location of the text file is specified by a URL. The MBeans specified in the MLET file will be instantiated and registered by the MBeanServer.
Specified by:
getMBeansFromURL in interface MLetMBean
Parameters:
url - The URL of the text file to be loaded as String object.
Returns:
A set containing one entry per MLET tag in the m-let text file loaded. Each entry specifies either the ObjectInstance for the created MBean, or a throwable object (that is, an error or an exception) if the MBean could not be created.
Throws:
ServiceNotFoundException - One of the following errors has occurred: The m-let text file does not contain an MLET tag, the m-let text file is not found, a mandatory attribute of the MLET tag is not specified, the url is malformed.

getLibraryDirectory

public java.lang.String getLibraryDirectory()
Gets the current directory used by the library loader for storing native libraries before they are loaded into memory.
Specified by:
getLibraryDirectory in interface MLetMBean
Returns:
The current directory used by the library loader.

setLibraryDirectory

public void setLibraryDirectory(java.lang.String libdir)
Sets the directory used by the library loader for storing native libraries before they are loaded into memory.
Specified by:
setLibraryDirectory in interface MLetMBean
Parameters:
libdir - The directory used by the library loader.

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws java.lang.Exception
Allows the m-let to perform any operations it needs before being registered in the MBeanServer. If the ObjectName is null, the m-let provides a default name for its registration :service=MLet
Specified by:
preRegister in interface MBeanRegistration
Parameters:
server - The MBeanServer in which the m-let will be registered.
name - The object name of the m-let.
Returns:
The name of the m-let registered.
Throws:
java.langException - This exception should be caught by the MBeanServer and re-thrown as an MBeanRegistrationException.

postRegister

public void postRegister(java.lang.Boolean registrationDone)
Allows the m-let to perform any operations needed after having been registered in the MBeanServer or after the registration has failed.
Specified by:
postRegister in interface MBeanRegistration
Parameters:
registrationDone - Indicates whether or not the m-let has been successfully registered in the MBeanServer. The value false means that either the registration phase has failed.

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Allows the m-let to perform any operations it needs before being de-registered by the MBeanServer.
Specified by:
preDeregister in interface MBeanRegistration
Throws:
java.langException - This exception should be caught by the MBeanServer and re-thrown as an MBeanRegistrationException.

postDeregister

public void postDeregister()
Allows the m-let to perform any operations needed after having been de-registered in the MBeanServer.
Specified by:
postDeregister in interface MBeanRegistration

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
This method saves the objects contents during Object Serialization.
Parameters:
out - The serialization output stream.
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
This method reads the objects contents during Object Serialization.
Parameters:
in - The serialization input stream.
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.
java.lang.ClassNotFoundException - The class for an object being restored cannot be found.

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
This is the main method for class loaders that is being redefined.
Parameters:
name - The name of the class.
Returns:
The resulting Class object.
Throws:
java.lang.ClassNotFoundException - The specified class could not be found.
Overrides:
findClass in class java.net.URLClassLoader

findLibrary

protected java.lang.String findLibrary(java.lang.String libname)
Returns the absolute path name of a native library. The VM invokes this method to locate the native libraries that belong to classes loaded with this class loader. Libraries are searched in the JAR files using first just the native library name and if not found the native library name together with the architecture-specific path name (OSName/OSArch/OSVersion/lib/nativelibname), i.e.

the library stat on Solaris SPARC 5.7 will be searched in the JAR file as:

  1. libstat.so
  2. SunOS/sparc/5.7/lib/libstat.so
the library stat on Windows NT 4.0 will be searched in the JAR file as:
  1. stat.dll
  2. WindowsNT/x86/4.0/lib/stat.dll

If this method returns null, i.e. the libraries were not found in any of the JAR files loaded with this class loader, the VM searches the library along the path specified as the java.library.path property.

Parameters:
libname - The library name.
Returns:
The absolute path of the native library.
Overrides:
findLibrary in class java.lang.ClassLoader