com.ibm.aglets.tahiti
Class AgletClassLoader

java.lang.Object
  extended byjava.lang.ClassLoader
      extended bycom.ibm.aglets.tahiti.AgletClassLoader
All Implemented Interfaces:
ResourceManager
Direct Known Subclasses:
JarAgletClassLoader

class AgletClassLoader
extends java.lang.ClassLoader
implements ResourceManager

Class AgletClassLoader is responsible for loading classes for the aglets. This class has a class loader cache as a static member and store all class loader objects with keys which is the URL of the origin of classes managed by the loader. In aglets bytecodes of classes are transfered with objects. Therefore, there may be many version of classes whose names are same in an aglet server. In aglets classes are managed based on their origin. Classes which sources of their bytecodes are same are managed by a same aglet loader in an aglet server. Therefore, an object can access objects if sources of their class bytecodes are same, otherwise ClassCastException will occur.

An aglet loader caches classes and their bytecodes.

Version:
1.20 $Date: 2002/02/20 22:06:26 $
Author:
Danny B. Lange, Gaku Yamamoto, Mitsuru Oshima

Nested Class Summary
 
Nested classes inherited from class java.lang.ClassLoader
 
Field Summary
(package private) static AgentProfile _agent_profile
           
protected static CacheManager _cache
          Cache to store bytecodes of classes.
private  java.net.URL _codeBase
           
protected  DigestTable _digest_table
          Digest table for classes managed by this classloader.
private  java.security.cert.Certificate _ownerCert
           
private  java.util.Hashtable _resolvedClassCache
          Cache to store resolved classes.
private  java.util.Vector _resources
           
private static LogCategory log
           
 
Fields inherited from class java.lang.ClassLoader
 
Constructor Summary
protected AgletClassLoader(java.net.URL codebase, java.security.cert.Certificate owner)
          Constructs a new AgletClassLoader with codebase.
 
Method Summary
 void addResource(java.lang.Object o)
          Adds a feature to the Resource attribute of the AgletClassLoader object
 void cacheResolvedClass(java.lang.Class cls)
          Description of the Method
 boolean contains(java.lang.Class cls)
          Checks if the given class is managed by this manager.
 void disposeAllResources()
          Description of the Method
private static void dumpBytes(byte[] bytes)
          Description of the Method
 void finalize()
          Shout when an AgletClassLoader object is caught by GC.
private  byte[] findByteCode(java.lang.String classname)
          Description of the Method
protected  byte[] findByteCodeInCache(java.lang.String filename)
          Description of the Method
private  java.lang.Class findClassInternal(java.lang.String name)
          Loads a class
private  java.lang.Class findResolvedClass(java.lang.String classname)
          Gets the class specified by the name from resolved cache.
 Archive getArchive(ClassName[] t)
          Gets the archive attribute of the AgletClassLoader object
 ClassName[] getClassNames(java.lang.Class[] classes)
          Computes Digest
 java.net.URL getCodeBase()
          Tells where the class was loaded from.
 java.security.cert.Certificate getOwnerCertificate()
          Gets certificate of the owner.
protected  byte[] getResourceAsByteArray(java.lang.String filename)
          Gets the resourceAsByteArray attribute of the AgletClassLoader object
 java.io.InputStream getResourceAsStream(java.lang.String filename)
          Gets the resourceAsStream attribute of the AgletClassLoader object
 void importArchive(Archive a)
          Description of method.
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          Loads a class specified by the param name.
private  java.lang.Class loadClassFromCodeBase(java.lang.String classname)
          Description of the Method
private  byte[] loadResourceFromCodeBase(java.lang.String name)
          The method for loading class data.
 boolean match(ClassName[] table)
          Description of the Method
 boolean matchAndImport(ClassName[] table)
          Description of the Method
 AgletThread newAgletThread(MessageManager mm)
          Description of the Method
private  void putResource(java.lang.String name, byte[] data)
          Description of the Method
private  void releaseCacheEntries()
          Description of the Method
 void resumeAllThreads()
          Description of the Method
 void setResourceManagerContext()
          Sets the resourceManagerContext attribute of the AgletClassLoader object
 void stopAllThreads()
          Description of the Method
 void stopThreadGroup()
          Description of the Method
 void suspendAllThreads()
          Description of the Method
 java.lang.String toString()
          Description of the Method
 void unsetResourceManagerContext()
          Description of the Method
private static void verboseOut(java.lang.String msg)
          Description of the Method
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.ibm.aglets.ResourceManager
loadClass
 

Field Detail

_cache

protected static CacheManager _cache
Cache to store bytecodes of classes.

Since:

_agent_profile

static AgentProfile _agent_profile

log

private static final LogCategory log

_digest_table

protected DigestTable _digest_table
Digest table for classes managed by this classloader.


_codeBase

private java.net.URL _codeBase

_ownerCert

private java.security.cert.Certificate _ownerCert

_resolvedClassCache

private java.util.Hashtable _resolvedClassCache
Cache to store resolved classes.


_resources

private java.util.Vector _resources
Constructor Detail

AgletClassLoader

protected AgletClassLoader(java.net.URL codebase,
                           java.security.cert.Certificate owner)
Constructs a new AgletClassLoader with codebase.

Parameters:
codebase - the codebase in which the all classes are originated.
owner - Certificate of the owner
Method Detail

dumpBytes

private static void dumpBytes(byte[] bytes)
Description of the Method

Parameters:
bytes - Description of Parameter
Since:

verboseOut

private static void verboseOut(java.lang.String msg)
Description of the Method

Parameters:
msg - Description of Parameter
Since:

setResourceManagerContext

public void setResourceManagerContext()
Sets the resourceManagerContext attribute of the AgletClassLoader object

Specified by:
setResourceManagerContext in interface ResourceManager
Since:

getArchive

public Archive getArchive(ClassName[] t)
Gets the archive attribute of the AgletClassLoader object

Specified by:
getArchive in interface ResourceManager
Parameters:
t - Description of Parameter
Returns:
The archive value
Since:

getClassNames

public ClassName[] getClassNames(java.lang.Class[] classes)
Computes Digest

Specified by:
getClassNames in interface ResourceManager
Parameters:
classes - Description of Parameter
Returns:
The classNames value
Since:

getCodeBase

public java.net.URL getCodeBase()
Tells where the class was loaded from.

Returns:
The codeBase value
Since:

getOwnerCertificate

public java.security.cert.Certificate getOwnerCertificate()
Gets certificate of the owner. (replacement of getIdentity)

Returns:
Certificate of the owner
Since:

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String filename)
Gets the resourceAsStream attribute of the AgletClassLoader object

Parameters:
filename - Description of Parameter
Returns:
The resourceAsStream value
Since:

addResource

public void addResource(java.lang.Object o)
Adds a feature to the Resource attribute of the AgletClassLoader object

Specified by:
addResource in interface ResourceManager
Parameters:
o - The feature to be added to the Resource attribute
Since:

cacheResolvedClass

public void cacheResolvedClass(java.lang.Class cls)
Description of the Method

Parameters:
cls - Description of Parameter
Since:

contains

public boolean contains(java.lang.Class cls)
Checks if the given class is managed by this manager.

Specified by:
contains in interface ResourceManager
Parameters:
cls - Description of Parameter
Returns:
Description of the Returned Value
Since:

disposeAllResources

public void disposeAllResources()
Description of the Method

Specified by:
disposeAllResources in interface ResourceManager
Since:

finalize

public void finalize()
Shout when an AgletClassLoader object is caught by GC. This method is for verifing whether a class loader becomes a target of GC or not.

Since:

importArchive

public void importArchive(Archive a)
Description of method.

Specified by:
importArchive in interface ResourceManager
Parameters:
a - Description of Parameter
Since:

match

public boolean match(ClassName[] table)
Description of the Method

Parameters:
table - Description of Parameter
Returns:
Description of the Returned Value
Since:

matchAndImport

public boolean matchAndImport(ClassName[] table)
Description of the Method

Parameters:
table - Description of Parameter
Returns:
Description of the Returned Value
Since:

newAgletThread

public AgletThread newAgletThread(MessageManager mm)
Description of the Method

Specified by:
newAgletThread in interface ResourceManager
Parameters:
mm - Description of Parameter
Returns:
Description of the Returned Value
Since:

resumeAllThreads

public void resumeAllThreads()
Description of the Method

Specified by:
resumeAllThreads in interface ResourceManager
Since:

stopAllThreads

public void stopAllThreads()
Description of the Method

Specified by:
stopAllThreads in interface ResourceManager
Since:

stopThreadGroup

public void stopThreadGroup()
Description of the Method

Specified by:
stopThreadGroup in interface ResourceManager
Since:

suspendAllThreads

public void suspendAllThreads()
Description of the Method

Specified by:
suspendAllThreads in interface ResourceManager
Since:

toString

public java.lang.String toString()
Description of the Method

Returns:
Description of the Returned Value
Since:

unsetResourceManagerContext

public void unsetResourceManagerContext()
Description of the Method

Specified by:
unsetResourceManagerContext in interface ResourceManager
Since:

getResourceAsByteArray

protected byte[] getResourceAsByteArray(java.lang.String filename)
Gets the resourceAsByteArray attribute of the AgletClassLoader object

Parameters:
filename - Description of Parameter
Returns:
The resourceAsByteArray value
Since:

findByteCodeInCache

protected byte[] findByteCodeInCache(java.lang.String filename)
Description of the Method

Parameters:
filename - Description of Parameter
Returns:
Description of the Returned Value
Since:

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Loads a class specified by the param name. If a bytecode of the class has not been loaded, an AgletClassLoader object will load the bytecode form the codebase and define the class. The loaded bytecode and class will be stored into the class data cache and the class cache respectively.

Parameters:
name - the name of the desired class.
resolve - true if the class must be resolved.
Returns:
a loaded class
Throws:
java.lang.ClassNotFoundException - if the class is not found.
Since:

findByteCode

private byte[] findByteCode(java.lang.String classname)
Description of the Method

Parameters:
classname - Description of Parameter
Returns:
Description of the Returned Value
Since:

findClassInternal

private java.lang.Class findClassInternal(java.lang.String name)
                                   throws java.lang.ClassNotFoundException
Loads a class

Parameters:
name - Description of Parameter
Returns:
Description of the Returned Value
Throws:
java.lang.ClassNotFoundException - Description of Exception
Since:
See Also:
loadClass(java.lang.String, boolean), AgletClassLoader#instantiageAglet

findResolvedClass

private java.lang.Class findResolvedClass(java.lang.String classname)
Gets the class specified by the name from resolved cache.

Parameters:
classname - Description of Parameter
Returns:
the class of the name, null if the class is not in the cache.
Since:

loadClassFromCodeBase

private java.lang.Class loadClassFromCodeBase(java.lang.String classname)
                                       throws java.lang.ClassNotFoundException
Description of the Method

Parameters:
classname - Description of Parameter
Returns:
Description of the Returned Value
Throws:
java.lang.ClassNotFoundException - Description of Exception
Since:

loadResourceFromCodeBase

private byte[] loadResourceFromCodeBase(java.lang.String name)
The method for loading class data. This loads the bytecode from codebase of this loader.

Parameters:
name - the class name.
Returns:
the bytecode for the class.
Since:

putResource

private void putResource(java.lang.String name,
                         byte[] data)
Description of the Method

Parameters:
name - Description of Parameter
data - Description of Parameter
Since:

releaseCacheEntries

private void releaseCacheEntries()
Description of the Method

Since: