@Test public void testDuplicateServiceFinder() { ClassLoader mainClassLoader = this.getClass().getClassLoader(); ClassLoader otherClassLoader = new ClonedClassLoader(mainClassLoader); Collection<SampleSPI> spis = ServiceFinder.load(SampleSPI.class, mainClassLoader, otherClassLoader); assertEquals(1, spis.size()); }
public static <T> Collection<T> load(Class<T> contract, ClassLoader... loaders) { Map<String, T> services = new LinkedHashMap<>(); if (loaders.length == 0) { try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract); addServices(loadedServices, services); } catch (Exception e) { } } else { for (ClassLoader loader : loaders) { if (loader == null) throw new NullPointerException(); try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract, loader); addServices(loadedServices, services); } catch (Exception e) { } } } if (services.isEmpty()) { LOG.debugf("No service impls found: %s", contract.getSimpleName()); } return services.values(); }
ServiceFinder { public static <T> Collection<T> load(Class<T> contract, ClassLoader... loaders) { Map<String, T> services = new LinkedHashMap<>(); if (loaders.length == 0) { try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract); addServices(loadedServices, services); } catch (Exception e) { } } else { for (ClassLoader loader : loaders) { if (loader == null) throw new NullPointerException(); try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract, loader); addServices(loadedServices, services); } catch (Exception e) { } } } if (services.isEmpty()) { LOG.debugf("No service impls found: %s", contract.getSimpleName()); } return services.values(); } }
ServiceFinder { public static <T> Collection<T> load(Class<T> contract, ClassLoader... loaders) { Map<String, T> services = new LinkedHashMap<>(); if (loaders.length == 0) { try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract); addServices(loadedServices, services); } catch (Exception e) { } } else { for (ClassLoader loader : loaders) { if (loader == null) throw new NullPointerException(); try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract, loader); addServices(loadedServices, services); } catch (Exception e) { } } } if (services.isEmpty()) { LOG.debugf("No service impls found: %s", contract.getSimpleName()); } return services.values(); }  }
ServiceFinder { public static <T> Collection<T> load(Class<T> contract, ClassLoader... loaders) { Map<String, T> services = new LinkedHashMap<>(); if (loaders.length == 0) { try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract); addServices(loadedServices, services); } catch (Exception e) { } } else { for (ClassLoader loader : loaders) { if (loader == null) throw new NullPointerException(); try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract, loader); addServices(loadedServices, services); } catch (Exception e) { } } } if (services.isEmpty()) { LOG.debugf("No service impls found: %s", contract.getSimpleName()); } return services.values(); }  static Collection<T> load(Class<T> contract, ClassLoader... loaders); }
ServiceFinder { public static <T> Collection<T> load(Class<T> contract, ClassLoader... loaders) { Map<String, T> services = new LinkedHashMap<>(); if (loaders.length == 0) { try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract); addServices(loadedServices, services); } catch (Exception e) { } } else { for (ClassLoader loader : loaders) { if (loader == null) throw new NullPointerException(); try { ServiceLoader<T> loadedServices = ServiceLoader.load(contract, loader); addServices(loadedServices, services); } catch (Exception e) { } } } if (services.isEmpty()) { LOG.debugf("No service impls found: %s", contract.getSimpleName()); } return services.values(); }  static Collection<T> load(Class<T> contract, ClassLoader... loaders);  }