public ConnectorClassFinder(ClassLoader parent, String raName, DelegatingClassLoader.ClassFinder finder){ super(parent); this.raName = raName; // There should be better approach to skip libraries Classloader when none specified. // casting to DelegatingClassLoader is not a clean approach DelegatingClassLoader.ClassFinder libcf = null; if(finder!= null && (finder instanceof DelegatingClassLoader)){ if(((DelegatingClassLoader)finder).getDelegates().size() > 0){ libcf = finder; } } this.librariesClassFinder = libcf; }
@Override public DelegatingClassLoader run() { return new DelegatingClassLoader(earLibCl); } });
/** * @throws IllegalArgumentException when the delegate does not have same parent * as this classloader. */ private void checkDelegate(ClassFinder d) throws IllegalArgumentException { final ClassLoader dp = d.getParent(); final ClassLoader p = getParent(); if (dp != p) { // check for equals if ((dp != null && !dp.equals(p)) || !p.equals(dp)) { throw new IllegalArgumentException("Delegation hierarchy mismatch"); } } }
/** * @see org.glassfish.internal.api.ClassLoaderHierarchy#getAppLibClassLoader(String, List<URI>) */ public ClassLoader getAppLibClassLoader(String application, List<URI> libURIs) throws MalformedURLException { ClassLoaderHierarchy clh = habitat.getService(ClassLoaderHierarchy.class); DelegatingClassLoader connectorCL = clh.getConnectorClassLoader(application); if (libURIs == null || libURIs.isEmpty()) { // Optimization: when there are no libraries, why create an empty // class loader in the hierarchy? Instead return the parent. return connectorCL; } final ClassLoader commonCL = commonCLS.getCommonClassLoader(); DelegatingClassLoader applibCL = AccessController.doPrivileged(new PrivilegedAction<DelegatingClassLoader>() { public DelegatingClassLoader run() { return new DelegatingClassLoader(commonCL); } }); // order of classfinders is important here : // connector's classfinders should be added before libraries' classfinders // as the delegation hierarchy is appCL->app-libsCL->connectorCL->commonCL->API-CL // since we are merging connector and applib classfinders to be at same level, // connector classfinders need to be be before applib classfinders in the horizontal // search path for (DelegatingClassLoader.ClassFinder cf : connectorCL.getDelegates()) { applibCL.addDelegate(cf); } addDelegates(libURIs, applibCL); return applibCL; }
private DelegatingClassLoader createConnectorClassLoaderForApplication(String appName){ DelegatingClassLoader appSpecificConnectorClassLoader = new DelegatingClassLoader(getCommonClassLoader()); //add system ra classloaders for(DelegatingClassLoader.ClassFinder cf : appsSpecificCCLUtil.getSystemRARClassLoaders()){ appSpecificConnectorClassLoader.addDelegate(cf); } for(String raName : appsSpecificCCLUtil.getRARsReferredByApplication(appName)){ addRarClassLoader(appName, appSpecificConnectorClassLoader, raName); } for(String raName : appsSpecificCCLUtil.getRequiredResourceAdapters(appName)){ addRarClassLoader(appName, appSpecificConnectorClassLoader, raName); } return appSpecificConnectorClassLoader; }
private void addRarClassLoader(String appName, DelegatingClassLoader appSpecificConnectorClassLoader, String raName) { if(logger.isLoggable(Level.FINEST)){ logger.finest("raName for app [ "+appName+" ] : " + raName); } DelegatingClassLoader.ClassFinder cf = getClassFinder(raName); if(cf != null){ appSpecificConnectorClassLoader.addDelegate(cf); }else{ //not possible /* TODO V3 if(!ConnectorsUtil.isEmbedded(appName, raName)){ throw new IllegalStateException("RAR Classloader of RAR [ "+raName+" ] not found for " + "application [ "+appName+" ]"); } */ } }
for(DelegatingClassLoader.ClassFinder cf : dcl.getDelegates()){ ConnectorClassFinder ccf = (ConnectorClassFinder)cf; if(ccf.getResourceAdapterName().equals(moduleName)){ dcl.removeDelegate(ccf); break;
clh.getConnectorClassLoader(null).addDelegate(ccf); clh.getConnectorClassLoader(null).removeDelegate(ccf);
/** * @throws IllegalArgumentException when the delegate does not have same parent * as this classloader. */ public DelegatingClassLoader(ClassLoader parent, List<ClassFinder> delegates) throws IllegalArgumentException{ super(parent); for (ClassFinder d : delegates) { checkDelegate(d); } this.delegates.addAll(delegates); }
public URL findResource(String name) { return super.findResource(name); }
if(globalConnectorCL == null){ ClassLoader parent = getCommonClassLoader(); globalConnectorCL = new DelegatingClassLoader(parent); for(DelegatingClassLoader.ClassFinder cf : appsSpecificCCLUtil.getSystemRARClassLoaders()){ globalConnectorCL.addDelegate(cf);
private void addDelegates(Collection<URI> libURIs, DelegatingClassLoader holder) throws MalformedURLException { ClassLoader commonCL = commonCLS.getCommonClassLoader(); for (URI libURI : libURIs) { synchronized (this) { DelegatingClassLoader.ClassFinder libCF = classFinderRegistry.get(libURI); if (libCF == null) { libCF = new URLClassFinder(new URL[]{libURI.toURL()}, commonCL); classFinderRegistry.put(libURI, libCF); } holder.addDelegate(libCF); } } }
/** * @throws IllegalArgumentException when the delegate does not have same parent * as this classloader. */ public DelegatingClassLoader(ClassLoader parent, List<ClassFinder> delegates) throws IllegalArgumentException{ super(parent); for (ClassFinder d : delegates) { checkDelegate(d); } this.delegates.addAll(delegates); }
private boolean isRARCL(ClassLoader loader) { DelegatingClassLoader connectorCL = (DelegatingClassLoader) this.getParent(); if (!(loader instanceof DelegatingClassLoader.ClassFinder)) { return false; } return connectorCL.getDelegates().contains((DelegatingClassLoader.ClassFinder)loader); }
PreDestroy.class.cast(subCl).preDestroy(); } else if (md.getModuleType().equals(DOLUtils.rarType())) { embeddedConnCl.addDelegate( (DelegatingClassLoader.ClassFinder)subCl); cl.addModuleClassLoader(moduleUri, subCl);
public DelegatingClassLoader run() { return new DelegatingClassLoader(commonCL); } });
/** * @throws IllegalArgumentException when the delegate does not have same parent * as this classloader. */ private void checkDelegate(ClassFinder d) throws IllegalArgumentException { final ClassLoader dp = d.getParent(); final ClassLoader p = getParent(); if (dp != p) { // check for equals if ((dp != null && !dp.equals(p)) || !p.equals(dp)) { throw new IllegalArgumentException("Delegation hierarchy mismatch"); } } }
/** * Adds a ClassFinder to list of delegates. To have a consistent * class space (by consistent class space, I mean a classpace where there * does not exist two class with same name), this method does not allow * a delegate to be added that has a different parent. * @param d ClassFinder to add to the list of delegates * @return true if the delegate is added, false otherwise. * @throws IllegalStateException when this method is called after the * classloader has been used to load any class. * @throws IllegalArgumentException when the delegate does not have same parent * as this classloader. */ public synchronized boolean addDelegate(ClassFinder d) throws IllegalStateException, IllegalArgumentException { checkDelegate(d); if (delegates.contains(d)) { return false; } return delegates.add(d); }
private DelegatingClassLoader.ClassFinder getClassFinder(String raName) { List<DelegatingClassLoader.ClassFinder> delegates = globalConnectorCL.getDelegates(); DelegatingClassLoader.ClassFinder classFinder = null; for(DelegatingClassLoader.ClassFinder cf : delegates){ if(raName.equals(((ConnectorClassFinder)cf).getResourceAdapterName())){ classFinder = cf; break; } } return classFinder; }
public DelegatingClassLoader run() { return new DelegatingClassLoader(commonCLS.getCommonClassLoader()); } });