📄 agletclassloader.java
字号:
package com.ibm.aglets.tahiti;import com.ibm.aglet.MessageManager;import com.ibm.aglet.Ticket;import com.ibm.aglets.AgletRuntime;import com.ibm.aglets.AgletThread;import com.ibm.aglets.ResourceManager;import com.ibm.awb.misc.Archive;import com.ibm.awb.misc.Hexadecimal;import com.ibm.awb.misc.Resource;/* * @(#)AgletClassLoader.java * * IBM Confidential-Restricted * * OCO Source Materials * * 03L7246 (c) Copyright IBM Corp. 1996, 1998 * * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. */// import com.ibm.atci.AtciConstants;import com.ibm.maf.*;import com.ibm.maf.ClassName;import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.net.URLConnection;import java.net.UnknownHostException;import java.security.AccessController;import java.security.AllPermission;import java.security.CodeSource;import java.security.KeyStore;import java.security.PermissionCollection;import java.security.Permissions;import java.security.Policy;import java.security.PrivilegedAction;import java.security.ProtectionDomain;import java.security.cert.Certificate;import java.util.Hashtable;import org.aglets.log.*;/** * Class <tt>AgletClassLoader<tt> 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.<p> * * An aglet loader caches classes and their bytecodes. * * @author Danny B. Lange * @author Gaku Yamamoto * @author Mitsuru Oshima * @version 1.20 $Date: 2002/02/20 22:06:26 $ */class AgletClassLoader extends ClassLoader implements ResourceManager { /** * Cache to store bytecodes of classes. * * @since */ protected static CacheManager _cache = null; static AgentProfile _agent_profile = null; private final static LogCategory log = LogInitializer.getCategory(AgletClassLoader.class.getName()); /** * Digest table for classes managed by this classloader. */ protected DigestTable _digest_table = new DigestTable(); /* * CodeBase */ private URL _codeBase = null; /* * Certificate of the owner */ private Certificate _ownerCert = null; /** * Cache to store resolved classes. */ private Hashtable _resolvedClassCache = new Hashtable(); private java.util.Vector _resources = new java.util.Vector(); static { _cache = CacheManager.getCacheManager(); _agent_profile = new AgentProfile((short) 1, /* * java */ (short) 1, /* * Aglets */ "Aglets", (short) 0, /* * Major */ (short) 2, /* * minor */ (short) 1, /* * serialization */ null); } /** * Constructs a new AgletClassLoader with codebase. * * @param codebase the codebase in which the all classes are originated. * @param owner Certificate of the owner */ protected AgletClassLoader(URL codebase, Certificate owner) { log.debug("Ctor: [" + codebase + "]"); _codeBase = codebase; _ownerCert = owner; } /** * Description of the Method * * @param bytes Description of Parameter * @since */ private static void dumpBytes(byte[] bytes) { if (bytes != null) { for (int i = 0; i < bytes.length; i++) { System.out.print(Hexadecimal.valueOf(bytes[i])); if (i % 16 == 15) { System.out.println(); } else { System.out.print(" "); } } if (bytes.length % 16 != 0) { System.out.println(); } } } /** * Description of the Method * * @param msg Description of Parameter * @since */ private static void verboseOut(String msg) { log.debug(msg); } /** * Sets the resourceManagerContext attribute of the AgletClassLoader object * * @since */ public void setResourceManagerContext() { } /** * Gets the archive attribute of the AgletClassLoader object * * @param t Description of Parameter * @return The archive value * @since */ public Archive getArchive(ClassName[] t) { int size = t.length; if (match(t)) { Archive a = new Archive(); for (int i = 0; i < size; i++) { String name = t[i].name; byte b[] = findByteCodeInCache(name); if (b != null) { long d = _digest_table.getDigest(name); log.debug("putResource(" + name + "," + d + "," + b.length + ") into archive"); a.putResource(name, d, b); } } return a; } else { System.err.println("getArchive: doesn't match"); return null; } } /** * Computes Digest * * @param classes Description of Parameter * @return The classNames value * @since */ public synchronized ClassName[] getClassNames(Class[] classes) { return _digest_table.getClassNames(classes); } /** * Tells where the class was loaded from. * * @return The codeBase value * @since */ public URL getCodeBase() { return _codeBase; } /** * Gets certificate of the owner. (replacement of getIdentity) * * @return Certificate of the owner * @since */ public Certificate getOwnerCertificate() { return _ownerCert; } /** * Gets the resourceAsStream attribute of the AgletClassLoader object * * @param filename Description of Parameter * @return The resourceAsStream value * @since */ public InputStream getResourceAsStream(String filename) { byte b[] = getResourceAsByteArray(filename); if (b != null) { return new java.io.ByteArrayInputStream(b); } return null; } /** * Adds a feature to the Resource attribute of the AgletClassLoader object * * @param o The feature to be added to the Resource attribute * @since */ public void addResource(Object o) { log.debug("Adding resource."); synchronized (_resources) { if (_resources.contains(o) == false) { _resources.addElement(o); } } } /** * Description of the Method * * @param cls Description of Parameter * @since */ public void cacheResolvedClass(Class cls) { _resolvedClassCache.put(cls.getName(), cls); } /** * Checks if the given class is managed by this manager. * * @param cls Description of Parameter * @return Description of the Returned Value * @since */ public boolean contains(Class cls) { return _resolvedClassCache.contains(cls); } /** * Description of the Method * * @since */ public void disposeAllResources() { synchronized (_resources) { java.util.Enumeration e = _resources.elements(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof java.awt.Window) { ((java.awt.Window) o).dispose(); } else { // what's else? } } _resources = null; } } /** * 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 */ public void finalize() { log.debug("Class Loader: Garbage Collected"); disposeAllResources(); releaseCacheEntries(); } /** * Description of method. * @param a Description of Parameter * @since */ public void importArchive(Archive a) { Archive.Entry ae[] = a.entries(); log.debug("importArchive()"); for (int i = 0; i < ae.length; i++) { // do we need check? M.O. log.debug("archive[" + i + "].name()=" + ae[i].name()); log.debug("archive[" + i + "].digest()=" + ae[i].digest()); log.debug("archive[" + i + "].data().length=" + ae[i].data().length); putResource(ae[i].name(), a.getResourceAsByteArray(ae[i].name())); /* * _digest_table.setDigest(ae.name(), ae.digest()); * _cache.putData(ae.name(), ae.digest(), ae.data()); */ } } /* * synchronized public DigestTable getDigestTable(Class[] classes) { * DigestTable r = new DigestTable(classes.length); * for(int i=0; i<classes.length; i++) { * String filename = classes[i].getName().replace('.','/') + ".class"; * // byte[] v = _digest_table.getDigest(filename); * // if ( v != null ) { * long v = _digest_table.getDigest(filename); * if ( v != 0 ) { * r.setDigest(filename, v); * } * } * return r; * } */ /** * Description of the Method * * @param table Description of Parameter * @return Description of the Returned Value * @since */ public synchronized boolean match(ClassName[] table) { return _digest_table.match(table, false); } /** * Description of the Method * * @param table Description of Parameter * @return Description of the Returned Value * @since */ public synchronized boolean matchAndImport(ClassName[] table) { return _digest_table.match(table, true); } /** * Description of the Method * * @param mm Description of Parameter * @return Description of the Returned Value * @since */ public AgletThread newAgletThread(MessageManager mm) { return null; } /** * Description of the Method * * @since */ public void resumeAllThreads() { } /** * Description of the Method * * @since */ public void stopAllThreads() { } /** * Description of the Method * * @since */ public void stopThreadGroup() { } /** * Description of the Method * * @since */ public void suspendAllThreads() { } /** * Description of the Method * * @return Description of the Returned Value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -