org.objectweb.mobilitools.smi.lib
Class SMIClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--org.objectweb.mobilitools.smi.lib.SMIClassLoader

public class SMIClassLoader
extends java.lang.ClassLoader

MobiliTools $Name: $, $Id: SMIClassLoader.java,v 1.1.1.1 2003/03/28 14:48:06 dillense Exp $

MAF-based class loader for SMI. Makes it possible to define classes by loading their byte code from a local filesystem, a URL, or an implementation of MAF's MAFAgentSystem interface. It also handles access to resources in the same manner. A dedicated classloader is created for each new mobile object (created or incoming). However, byte-code, classes and resources are kept in a cache and reused for each given codebase. This way, mobile objects may invoke each other through and only through a class, interface or object with the same codebase, or loaded by a common parent class loader.

The class/resource loading policy is the following:

  1. try to get the missing class/resource from the parent classloader
  2. try to retrieve the missing class/resource from the local cache
  3. ask the class provider (SMI agency), which, in turn, looks for the class byte-code or resource in its cache
  4. locally interpret the codebase
A cache is flushed at garbage collection time if and only if no more agent with the corresponding codebase is present in the agency.

Notes:

See Also:
RMIClassLoaderAdapter, URLClassLoaderAdapter, getClassLoader(ClassLoader, String, AgentProfile, MAFAgentSystem), Constants

Method Summary
 void finalize()
           
protected  java.lang.Class findClass(java.lang.String name)
          Gets the byte code for, and defines the requested class, either through local or remote bytecode load.
 java.net.URL findResource(java.lang.String name)
          Gets the content of the named resource and keeps it in the cache associated to current SMI class loader's codebase.
 java.util.Enumeration findResources(java.lang.String name)
          Since a codebase for SMI class loaders hold a single value, this method is similar to findResource().
 byte[] getBytes(java.lang.String name)
          Reads or retrieves from a cache the byte code for a given class name, or a resource content (accordingly to current class loader's code base).
static java.lang.ClassLoader getClassLoader(java.lang.ClassLoader parent, java.lang.String codebase, org.omg.CfMAF.AgentProfile profile, org.omg.CfMAF.MAFAgentSystem provider)
          Creates a new SMI class loader.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLibrary, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getClassLoader

public static java.lang.ClassLoader getClassLoader(java.lang.ClassLoader parent,
                                                   java.lang.String codebase,
                                                   org.omg.CfMAF.AgentProfile profile,
                                                   org.omg.CfMAF.MAFAgentSystem provider)
Creates a new SMI class loader.
Parameters:
the - parent class loader (from which SMI class loader tries to get classes before fetching them by itself)
codebase - the codebase for the classes; may be a single pathname or URL designating a ZIP/JAR file or directory holding the classes
profile - the agent profile (based on SMI's profile, see MAF spec.)
provider - the MAFAgentSystem implementation (SMI agency) providing the classes.
Returns:
each call returns a new classloader

getBytes

public byte[] getBytes(java.lang.String name)
Reads or retrieves from a cache the byte code for a given class name, or a resource content (accordingly to current class loader's code base). There is one cache per represented codebase. Caches are filled by the findClass() instance method, when a class is downloaded from another agency by the fetch_class() operation.
Parameters:
name - the class full name (i.e. including the package name if any) or resource name
Returns:
the byte code or the resource content designated by the name, or null if the byte code or resource could not be found.

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Gets the byte code for, and defines the requested class, either through local or remote bytecode load. Byte-code remotely loaded through the fetch_class() operation of a MAFAgentSystem implementation is cached. This cache is necessary for the next migration of the incoming agent, in order to provide the next hosting agency with the class bytecode. Classes in the cache are identified by their name and codebase.
Overrides:
findClass in class java.lang.ClassLoader
Parameters:
name - the name of the class to define (see Java2 API).
Returns:
the corresponding Class object.
Throws:
java.lang.ClassNotFoundException - if the class could not be loaded and defined.

findResource

public java.net.URL findResource(java.lang.String name)
Gets the content of the named resource and keeps it in the cache associated to current SMI class loader's codebase.
Overrides:
findResource in class java.lang.ClassLoader
Parameters:
name - the resource's name
Returns:
a URL with a specific scheme to access the resource content, or null if the resource could not be found/loaded.

findResources

public java.util.Enumeration findResources(java.lang.String name)
Since a codebase for SMI class loaders hold a single value, this method is similar to findResource().
Overrides:
findResources in class java.lang.ClassLoader
Parameters:
name - the resource's name
Returns:
an empty or single-value enumeration of URLs for the named resource
See Also:
findResource(String)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object