@Test public void testMultipleServiceClassLoading() throws ClassLoaderException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { ClassManager testee = new ClassManager(new FileSystemRepository("export/jars/"), ClassLoader.getSystemClassLoader(), new DefaultPolicy()); Class<?> cl1 = testee.getServiceClass(new ServiceNameVersion("i5.las2peer.classLoaders.testPackage2.UsingCounter", "1.0")); Class<?> cl2 = testee.getServiceClass(new ServiceNameVersion("i5.las2peer.classLoaders.testPackage2.UsingCounter", "1.0")); assertFalse(cl1.getClassLoader().equals(ClassLoader.getSystemClassLoader())); assertFalse(cl2.getClassLoader().equals(ClassLoader.getSystemClassLoader())); assertSame(cl1, cl2); }
public Class<?> getServiceClass(ServiceNameVersion service) throws ClassLoaderException { ServiceClassLoader cl = registeredLoaders.get(service); if (cl == null) { try { registerService(service); cl = registeredLoaders.get(service); } catch (LibraryNotFoundException e) { System.err.println("No library found for " + service + "! Trying default classpath. This should not happen in a productive environment!"); try { return this.platformLoader.loadClass(service.getName()); } catch (ClassNotFoundException e2) { throw e; } } } try { return cl.loadClass(service.getName()); } catch (ClassNotFoundException e) { throw new LibraryNotFoundException( "The library for " + service + " could be loaded, but the class is not available!", e); } }
ClassManager { public Class<?> getServiceClass(ServiceNameVersion service) throws ClassLoaderException { ServiceClassLoader cl = registeredLoaders.get(service); if (cl == null) { try { registerService(service); cl = registeredLoaders.get(service); } catch (LibraryNotFoundException e) { System.err.println("No library found for " + service + "! Trying default classpath. This should not happen in a productive environment!"); try { return this.platformLoader.loadClass(service.getName()); } catch (ClassNotFoundException e2) { throw e; } } } try { return cl.loadClass(service.getName()); } catch (ClassNotFoundException e) { throw new LibraryNotFoundException( "The library for " + service + " could be loaded, but the class is not available!", e); } } }
ClassManager { public Class<?> getServiceClass(ServiceNameVersion service) throws ClassLoaderException { ServiceClassLoader cl = registeredLoaders.get(service); if (cl == null) { try { registerService(service); cl = registeredLoaders.get(service); } catch (LibraryNotFoundException e) { System.err.println("No library found for " + service + "! Trying default classpath. This should not happen in a productive environment!"); try { return this.platformLoader.loadClass(service.getName()); } catch (ClassNotFoundException e2) { throw e; } } } try { return cl.loadClass(service.getName()); } catch (ClassNotFoundException e) { throw new LibraryNotFoundException( "The library for " + service + " could be loaded, but the class is not available!", e); } } ClassManager(Repository repository, ClassLoader platformLoader, ClassLoaderPolicy policy);  ClassManager(Repository[] repositories, ClassLoader platformLoader, ClassLoaderPolicy policy);  ClassManager(List<Repository> repositories, ClassLoader platformLoader, ClassLoaderPolicy policy); }
ClassManager { public Class<?> getServiceClass(ServiceNameVersion service) throws ClassLoaderException { ServiceClassLoader cl = registeredLoaders.get(service); if (cl == null) { try { registerService(service); cl = registeredLoaders.get(service); } catch (LibraryNotFoundException e) { System.err.println("No library found for " + service + "! Trying default classpath. This should not happen in a productive environment!"); try { return this.platformLoader.loadClass(service.getName()); } catch (ClassNotFoundException e2) { throw e; } } } try { return cl.loadClass(service.getName()); } catch (ClassNotFoundException e) { throw new LibraryNotFoundException( "The library for " + service + " could be loaded, but the class is not available!", e); } } ClassManager(Repository repository, ClassLoader platformLoader, ClassLoaderPolicy policy);  ClassManager(Repository[] repositories, ClassLoader platformLoader, ClassLoaderPolicy policy);  ClassManager(List<Repository> repositories, ClassLoader platformLoader, ClassLoaderPolicy policy); void registerService(ServiceNameVersion serviceIdentifier); void unregisterService(ServiceNameVersion service); Class<?> getServiceClass(ServiceNameVersion service); static final String getPackageName(String className); void addRepository(Repository repository); }
ClassManager { public Class<?> getServiceClass(ServiceNameVersion service) throws ClassLoaderException { ServiceClassLoader cl = registeredLoaders.get(service); if (cl == null) { try { registerService(service); cl = registeredLoaders.get(service); } catch (LibraryNotFoundException e) { System.err.println("No library found for " + service + "! Trying default classpath. This should not happen in a productive environment!"); try { return this.platformLoader.loadClass(service.getName()); } catch (ClassNotFoundException e2) { throw e; } } } try { return cl.loadClass(service.getName()); } catch (ClassNotFoundException e) { throw new LibraryNotFoundException( "The library for " + service + " could be loaded, but the class is not available!", e); } } ClassManager(Repository repository, ClassLoader platformLoader, ClassLoaderPolicy policy);  ClassManager(Repository[] repositories, ClassLoader platformLoader, ClassLoaderPolicy policy);  ClassManager(List<Repository> repositories, ClassLoader platformLoader, ClassLoaderPolicy policy); void registerService(ServiceNameVersion serviceIdentifier); void unregisterService(ServiceNameVersion service); Class<?> getServiceClass(ServiceNameVersion service); static final String getPackageName(String className); void addRepository(Repository repository);  }