private void addURLClassLoader(URLClassLoader loader) { URL[] urls = loader.getURLs(); int count = urls != null && urls.length > 0 ? urls.length : 0; URL origURL = count > 0 ? urls[0] : null; UnifiedClassLoader3 ucl3 = new UnifiedClassLoader3(origURL, origURL, this); addRepositoryClassLoader(ucl3); synchronized (classLoaders) { nonUCLClassLoader.put(loader, ucl3); } for (int i = 1; i < count; i++) { this.addClassLoaderURL(ucl3, urls[i]); } }
/** Add a class loader to the repository. */ public void addClassLoader(ClassLoader loader) { // if you come to us as UCL we send you straight to the orbit if (loader instanceof RepositoryClassLoader) addRepositoryClassLoader((RepositoryClassLoader) loader); else if (loader instanceof MLet) { addMLetClassLoader((MLet) loader); } else if (loader instanceof URLClassLoader) { addURLClassLoader((URLClassLoader) loader); } else { log.warn("Tried to add non-URLClassLoader. Ignored"); } // end of else }
private URL getResourceFromClassLoader(String name, ClassLoader cl) { URL resource = null; if (cl instanceof RepositoryClassLoader) { RepositoryClassLoader ucl = (RepositoryClassLoader) cl; resource = ucl.getResourceLocally(name); cacheLoadedResource(name, resource, cl); } return resource; }
protected URL getResourceFromRepository(String name, ClassLoader cl) String pkgName = getResourcePackageName(name); Iterator<ClassLoader> i = null; Set<ClassLoader> pkgSet = this.packagesMap.get(pkgName); if (url != null) cacheLoadedResource(name, url, classloader); cacheGlobalResource(name, url, classloader); break;
/** * This method provides an mbean-accessible way to add a * UnifiedClassloader, and sends a notification when it is added. * * @param ucl an <code>UnifiedClassLoader</code> value * @return a <code>LoaderRepository</code> value * * @jmx.managed-operation */ public LoaderRepository registerClassLoader(RepositoryClassLoader ucl) { addClassLoader(ucl); if (NOTIFICATION_MODE == LEGACY_MODE || NOTIFICATION_MODE == WEAK_REFERENCE_MODE) { Notification msg = new Notification(CLASSLOADER_ADDED, this, getNextSequenceNumber()); if (NOTIFICATION_MODE == WEAK_REFERENCE_MODE) msg.setUserData(new WeakReference<ClassLoader>(ucl)); else msg.setUserData(ucl); broadcaster.sendNotification(msg); } return this; }
return loadClass(className, false, ucl); Class clazz = getNativeClassForName(className); if (clazz != null) return clazz;
ClassLoader wrapper = repository.getWrappingClassLoader(loader); if (wrapper != null) loader=wrapper; repository.cacheLoadedClass(threadTask.getClassname(), loadedClass, loader);
private void addMLetClassLoader(MLet loader) { MLetRepositoryClassLoader rcl = new MLetRepositoryClassLoader(loader); synchronized (classLoaders) { nonUCLClassLoader.put(loader, rcl); } addRepositoryClassLoader(rcl); }
Class loadClassFromClassLoader(String name, boolean resolve, RepositoryClassLoader cl) { try { Class cls = cl.loadClassLocally(name, resolve); cacheLoadedClass(name, cls, cl); return cls; } catch (ClassNotFoundException x) { // The class is not visible by the calling classloader if(log.isTraceEnabled()) log.trace("Failed to load class: "+name, x); } return null; }
/** Override getCachedClass to return the parent repository cached class * if java2ParentDelegation=true, followed by this repository's cached * value. Else, if java2ParentDelegation=false, only check this repository's * cache to attempt to load the class from the child repository before * going to the parent cache. * * @param classname * @return the cached class if found, null otherwise */ public Class getCachedClass(String classname) { Class clazz = null; if( java2ParentDelegation == true ) { // Try the parent repository clazz = parentRepository.getCachedClass(classname); // Next try our parent repository if( clazz == null ) clazz = super.getCachedClass(classname); } else { // Try this repository clazz = super.getCachedClass(classname); } return clazz; }
protected URL getResourceFromRepository(String name, ClassLoader cl) String pkgName = getResourcePackageName(name); Iterator i = null; Set pkgSet = (Set) this.packagesMap.get(pkgName); if (url != null) cacheLoadedResource(name, url, classloader); cacheGlobalResource(name, url, classloader); break;
/** * This method provides an mbean-accessible way to add a * UnifiedClassloader, and sends a notification when it is added. * * @param ucl an <code>UnifiedClassLoader</code> value * @return a <code>LoaderRepository</code> value * * @jmx.managed-operation */ public LoaderRepository registerClassLoader(RepositoryClassLoader ucl) { addClassLoader(ucl); if (NOTIFICATION_MODE == LEGACY_MODE || NOTIFICATION_MODE == WEAK_REFERENCE_MODE) { Notification msg = new Notification(CLASSLOADER_ADDED, this, getNextSequenceNumber()); if (NOTIFICATION_MODE == WEAK_REFERENCE_MODE) msg.setUserData(new WeakReference(ucl)); else msg.setUserData(ucl); broadcaster.sendNotification(msg); } return this; }
return loadClass(className, false, ucl); Class<?> clazz = getNativeClassForName(className); if (clazz != null) return clazz;
ClassLoader wrapper = repository.getWrappingClassLoader(loader); if (wrapper != null) loader=wrapper; repository.cacheLoadedClass(threadTask.getClassname(), loadedClass, loader);
private void addMLetClassLoader(MLet loader) { MLetRepositoryClassLoader rcl = new MLetRepositoryClassLoader(loader); synchronized (classLoaders) { nonUCLClassLoader.put(loader, rcl); } addRepositoryClassLoader(rcl); }
Class<?> loadClassFromClassLoader(String name, boolean resolve, RepositoryClassLoader cl) { try { Class<?> cls = cl.loadClassLocally(name, resolve); cacheLoadedClass(name, cls, cl); return cls; } catch (ClassNotFoundException x) { // The class is not visible by the calling classloader if(log.isTraceEnabled()) log.trace("Failed to load class: "+name, x); } return null; }
/** Override getCachedClass to return the parent repository cached class * if java2ParentDelegation=true, followed by this repository's cached * value. Else, if java2ParentDelegation=false, only check this repository's * cache to attempt to load the class from the child repository before * going to the parent cache. * * @param classname * @return the cached class if found, null otherwise */ public Class<?> getCachedClass(String classname) { Class<?> clazz = null; if( java2ParentDelegation == true ) { // Try the parent repository clazz = parentRepository.getCachedClass(classname); // Next try our parent repository if( clazz == null ) clazz = super.getCachedClass(classname); } else { // Try this repository clazz = super.getCachedClass(classname); } return clazz; }
/** Add a class loader to the repository. */ public void addClassLoader(ClassLoader loader) { // if you come to us as UCL we send you straight to the orbit if (loader instanceof RepositoryClassLoader) addRepositoryClassLoader((RepositoryClassLoader) loader); else if (loader instanceof MLet) { addMLetClassLoader((MLet) loader); } else if (loader instanceof URLClassLoader) { addURLClassLoader((URLClassLoader) loader); } else { log.warn("Tried to add non-URLClassLoader. Ignored"); } // end of else }
private void addURLClassLoader(URLClassLoader loader) { URL[] urls = loader.getURLs(); int count = urls != null && urls.length > 0 ? urls.length : 0; URL origURL = count > 0 ? urls[0] : null; UnifiedClassLoader3 ucl3 = new UnifiedClassLoader3(origURL, origURL, this); addRepositoryClassLoader(ucl3); synchronized (classLoaders) { nonUCLClassLoader.put(loader, ucl3); } for (int i = 1; i < count; i++) { this.addClassLoaderURL(ucl3, urls[i]); } }
private URL getResourceFromClassLoader(String name, ClassLoader cl) { URL resource = null; if (cl instanceof RepositoryClassLoader) { RepositoryClassLoader ucl = (RepositoryClassLoader) cl; resource = ucl.getResourceLocally(name); cacheLoadedResource(name, resource, cl); } return resource; }