Java Dynamic Management Kit 3.2 Programming Guide | ||||
---|---|---|---|---|
![]() | ![]() | Chapter 13. Class and Library Loading Service | ![]() | ![]() |
The class and library loader loads classes and libraries into the framework. The com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoader Java class provides an implementation of the class and library loader. It works in conjunction with the RMI network class server provided with the Java Dynamic Management Kit.
The object name you assign to a class loader must contain the configuration information that the class loader requires. To insure this, specify the following attributes in the search key of the object name:
host = hostname
The host name where the class server is running. By default this is the local host.
port = portno
The port number to be used. By default this is 1099.
service = servicename
The service name of the RMI object to be used as the class and library server. By default this is NetClassServer.
The URL rmi://host:port/service should correspond to the URL of the class server.
An example of the object name of a class loader is given in Example 13-2.
The supplied class loader is implemented as an m-bean. This enables it to be managed through the AdaptorMO interface. To add a class loader through a manager, you include it in the manager code that requests the class loader to be added to the agent. The c-bean that the AdaptorMO interface requires for managing a class loader is supplied as the Java class com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoaderMO. Therefore, the manager you develop must contain the code required for instantiating this class.
Example 13-2 shows code for instantiating a class loader through the AdaptorMO interface. The newly instantiated class loader obtains classes and libraries from an RMI server that has the URL rmi://myHost:1099/NetClassServer.
Example 13-2. Instantiating a Network Class Loader Through a Manager
// Define the name of the class to be instantiated // String nc = "com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoader"; // Build object name for registering the instance // String prop = ".host=myHost,port=1099,service=NetClassServer"; ObjectName name = new ObjectName(MOFactory.getDomain()+ ":com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoaderMO"+prop); // Create the m-bean and its corresponding c-bean, and register the m-bean // NetClassLoaderMO ncl = (NetClassLoaderMO) MOFactory.cb_newMO(nc,name,null); |
If your manager needs to obtain c-beans from a remote class server, you have to instantiate a class loader in the manager. For more information, refer to Retrieving C-Beans in Chapter 7.
To add a class loader directly to an agent, include in the agent the code required for instantiating the com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoader class.
Example 13-3 shows code in an agent for instantiating a class loader directly. The newly instantiated class loader obtains classes and libraries from an RMI server that has the URL rmi://myHost:1099/NetClassServer.
Example 13-3. Instantiating a Network Class Loader in Agent Code
// Define the name of the class to be instantiated // String nc = "com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoader"; // Build object name for registering the instance with the repository // String prop = ".host=myHost,port=1099,service=NetClassServer"; ObjectName name = new ObjectName(cmf.getDomain()+ ":com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoaderMO"+prop); // Create the m-bean and register it with the repository // NetClassLoader ncl = (NetClassLoader) cmf.newObject(nc, name, null); |
The methods for instantiating a remote m-bean are the same as those for instantiating any other m-bean, although it is necessary to specify the object name of the class loader to be used.
Example 13-4 shows code for instantiating a remote m-bean using the RMI network class loader through a manager. In this example, the class RemoteClass is stored on a remote class server. The RemoteClassON is the object name given to the m-bean to register it with the repository. The NetClassLoaderON is the object name of the class loader to be used.
Example 13-4. Instantiating a Remote M-Bean Through a Manager
RemoteClassMO rcmo = (RemoteClassMO) MOFactory.cb_newMO( "RemoteClass", RemoteClassON, null, NetClassLoaderON); |
Example 13-5 shows code for instantiating a remote m-bean using the RMI network class loader through an agent. In this example, the class RemoteClass is stored on a remote class server. The RemoteClassON is the object name given to the m-bean to register it with the repository. The NetClassLoaderON is the object name of the class loader to be used.
Example 13-5. Instantiating a Remote M-Bean Through an Agent
RemoteClass rc = (RemoteClass) cmf.newObject( "RemoteClass", RemoteClassON, NetClassLoaderON, null); |
![]() | ![]() | ![]() |
Class and Library Server | ![]() | Using the Library Loading Service |