com.sun.jaw.impl.agent.services.loader.rmi
Class NetClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--com.sun.jaw.impl.agent.services.loader.rmi.NetClassLoader

public class NetClassLoader
extends java.security.SecureClassLoader
implements java.io.Externalizable, ActivatableIf

This class provides a simple implementation of a class loader which will load a class from a Class Server based on RMI.

The class loader can be instantiated at start time in the agent or dynamically. Several instances of the NetClassLoader can co-exist within the same agent.

When initializing the class loader, an object name must be assigned to the instance. The object name is used by the class loader for retrieving configuration information. So the following key properties need to be specified in the object name:

The library path used by default for locating libraries is specified in the following order:
  1. The value of the libpath property in the object name you give to the service.
  2. The value of the jaw.net.library.path property.
  3. The return value of getTmpDir() in class DefaultPaths.

See Also:
NetClassServerImpl, Serialized Form

Constructor Summary
NetClassLoader()
          Allocates a new net class loader.
NetClassLoader(ObjectName name)
          Allocates a new net class loader object using name as ObjectName.
 
Method Summary
 void deleteCmf()
          Deletes the net class loader.
protected  java.lang.Class findClass(java.lang.String name)
          Returns the Class object associated with the class with the given name from the remote class server.
protected  java.lang.String findLibrary(java.lang.String libname)
          Returns the absolute path name of a native library.
static java.lang.String getClassVersion()
          Returns the version of this class.
 java.util.Vector getLibPaths()
          Returns the current library path used by the network library loader for storing native libraries locally before loading them into memory.
 ObjectName getLoaderName()
          Gets the object name of this instance of NetClassLoader.
 void initCmf(Framework cmf, ObjectName name, boolean db, ModificationList list)
          Initialize the NetClassLoader service.
 boolean isActive()
          Tests if the NetClassLoader is active.
 void performStart()
          Activates the NetClassLoader.
 void performStop()
          Deactivates the NetClassLoader.
 void readExternal(java.io.ObjectInput in)
          This method reads the objects contents during Object Serialization.
 void setLibPaths(java.util.Vector newValue)
          Sets the library path used by the network library loader for storing native libraries locally before loading them into memory.
 void writeExternal(java.io.ObjectOutput out)
          This method saves the objects contents during Object Serialization.
 
Methods inherited from class java.security.SecureClassLoader
defineClass, getPermissions
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLoadedClass, findResource, findResources, 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

NetClassLoader

public NetClassLoader()
Allocates a new net class loader.

NetClassLoader

public NetClassLoader(ObjectName name)
Allocates a new net class loader object using name as ObjectName. name contains the information need for the initialization in its key part.
Parameters:
name - Object name containing configuration information.
Method Detail

initCmf

public void initCmf(Framework cmf,
                    ObjectName name,
                    boolean db,
                    ModificationList list)
             throws InstanceAlreadyExistException
Initialize the NetClassLoader service. The method will declare the object to the Core Management Framework. The name of the class server as well as host/port information are contained in the object name.

For JDMK internal use only.

Parameters:
agent - The core management framework to register the service with.
name - Object name containing configuration information.
db - Indicates if persistent storage is required.
list - The modification list to use for setting up parameters.
Throws:
InstanceAlreadyExistException - The m-bean is already registered in the repository.

deleteCmf

public void deleteCmf()
Deletes the net class loader. Unregisters this net class loader from the framework.

For JDMK internal use only.


findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Returns the Class object associated with the class with the given name from the remote class server.
Parameters:
name - the fully qualified name of the desired class.
Throws:
java.lang.ClassNotFoundException - if the class could not be found.
Overrides:
findClass in class java.lang.ClassLoader

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 class server associated to this class loader 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 under the library path specified by the class server as:

  1. <libpath>/libstat.so
  2. <libpath>/SunOS/sparc/5.7/lib/libstat.so
the library stat on Windows NT 4.0 will be searched in the class server as:
  1. <libpath>/stat.dll
  2. <libpath>/WindowsNT/x86/4.0/lib/stat.dll

If this method returns null, i.e. the library was not found in the class server associated to 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

performStart

public void performStart()
Activates the NetClassLoader.
Specified by:
performStart in interface ActivatableIf

performStop

public void performStop()
Deactivates the NetClassLoader.
Specified by:
performStop in interface ActivatableIf

isActive

public boolean isActive()
Tests if the NetClassLoader is active.
Specified by:
isActive in interface ActivatableIf

getClassVersion

public static java.lang.String getClassVersion()
Returns the version of this class.
Returns:
String representing the version of this class.

getLoaderName

public ObjectName getLoaderName()
Gets the object name of this instance of NetClassLoader.
Returns:
The object name of this instance of NetClassLoader.

getLibPaths

public java.util.Vector getLibPaths()
Returns the current library path used by the network library loader for storing native libraries locally before loading them into memory.

setLibPaths

public void setLibPaths(java.util.Vector newValue)
                 throws java.rmi.RemoteException
Sets the library path used by the network library loader for storing native libraries locally before loading them into memory.
Throws:
java.rmi.RemoteException - This exception will be never thrown. Left here to keep source code backwards compatibility.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
This method saves the objects contents during Object Serialization.
Specified by:
writeExternal in interface java.io.Externalizable
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.
Specified by:
readExternal in interface java.io.Externalizable
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.