private static void fail(Class<?> service, String msg) throws ServiceConfigurationError { throw new ServiceConfigurationError(service.getName() + ": " + msg); }
private static void fail(Class<?> service, String msg, Throwable cause) throws ServiceConfigurationError { throw new ServiceConfigurationError(service.getName() + ": " + msg, cause); }
private static ServiceConfigurationError fail(Class<?> service, String msg) { return new ServiceConfigurationError(service.getName() + ": " + msg); }
private static ServiceConfigurationError fail(Class<?> service, String msg, Throwable cause) { return new ServiceConfigurationError(service.getName() + ": " + msg, cause); }
private static ServiceConfigurationError fail(Class<?> service, String msg, Throwable cause) { return new ServiceConfigurationError(service.getName() + ": " + msg, cause); }
private static ServiceConfigurationError fail(Class<?> service, String msg) { return new ServiceConfigurationError(service.getName() + ": " + msg); }
@Override public S load() { return loadedClass.map(aClass -> { try { return InstantiationUtils.instantiate(aClass); } catch (Throwable e) { throw new ServiceConfigurationError("Error loading service [" + aClass.getName() + "]: " + e.getMessage(), e); } }).orElseThrow(() -> new ServiceConfigurationError("Call to load() when class '" + name + "' is not present")); } }
private SPIClassIterator(Class<S> clazz, ClassLoader loader) { this.clazz = Objects.requireNonNull(clazz, "clazz"); this.loader = Objects.requireNonNull(loader, "loader"); try { final String fullName = META_INF_SERVICES + clazz.getName(); this.profilesEnum = loader.getResources(fullName); } catch (IOException ioe) { throw new ServiceConfigurationError("Error loading SPI profiles for type " + clazz.getName() + " from classpath", ioe); } this.linesIterator = Collections.<String>emptySet().iterator(); }
private static BeanManagerFactoryServiceConfiguratorFactoryProvider load() { Iterator<BeanManagerFactoryServiceConfiguratorFactoryProvider> providers = load(BeanManagerFactoryServiceConfiguratorFactoryProvider.class).iterator(); if (!providers.hasNext()) { throw new ServiceConfigurationError(BeanManagerFactoryServiceConfiguratorFactoryProvider.class.getName()); } return providers.next(); }
@Override public Class<? extends S> next() { // hasNext() implicitely loads the next profile, so it is essential to call this here! if (!hasNext()) { throw new NoSuchElementException(); } assert linesIterator.hasNext(); final String c = linesIterator.next(); try { // don't initialize the class (pass false as 2nd parameter): return Class.forName(c, false, loader).asSubclass(clazz); } catch (ClassNotFoundException cnfe) { throw new ServiceConfigurationError(String.format(Locale.ROOT, "An SPI class of type %s with classname %s does not exist, "+ "please fix the file '%s%1$s' in your classpath.", clazz.getName(), c, META_INF_SERVICES)); } }
serviceConfigs = classLoader.getResources(SoftServiceLoader.META_INF_SERVICES + '/' + name); } catch (IOException e) { throw new ServiceConfigurationError("Failed to load resources for service: " + name, e); throw new ServiceConfigurationError("Failed to load resources for URL: " + url, e);
throw new ServiceConfigurationError("Error loading SPI class list from URL: " + url, ioe);
throw new ServiceConfigurationError("Cannot instantiate SPI class: " + c.getName(), e);
throw new ServiceConfigurationError("The class name " + service.getName() + " has wrong suffix, allowed are: " + Arrays.toString(suffixes));
@Test @SuppressWarnings("unchecked") public void testProtocolProviderCreation() throws Exception { Iterator iterator = mock(Iterator.class); when(iterator.hasNext()).thenReturn(true, true, true, true); when(iterator.next()).thenReturn(getClientProtocolProvider()) .thenThrow(new ServiceConfigurationError("Test error")) .thenReturn(getClientProtocolProvider()); Iterable frameworkLoader = mock(Iterable.class); when(frameworkLoader.iterator()).thenReturn(iterator); Cluster.frameworkLoader = frameworkLoader; Cluster testCluster = new Cluster(new Configuration()); // Check that we get the acceptable client, even after // failure in instantiation. assertNotNull("ClientProtocol is expected", testCluster.getClient()); // Check if we do not try to load the providers after a failure. verify(iterator, times(2)).next(); }
private <S> S createInstance(Class<? extends S> serviceClass) { Constructor<? extends S> constructor = null; try { constructor = serviceClass.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError(ERROR_INSTANTIATING + ":" + serviceClass.getName(), t); } } }
private <S> S createInstance(Class<? extends S> serviceClass) { Constructor<? extends S> constructor = null; try { constructor = serviceClass.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError(ERROR_INSTANTIATING + ":" + serviceClass.getName(), t); } } }
private <S> S createInstance(Class<? extends S> serviceClass) { Constructor<? extends S> constructor = null; try { constructor = serviceClass.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError(ERROR_INSTANTIATING + ":" + serviceClass.getName(), t); } } }
private <S> S createInstance(Class<? extends S> serviceClass) { Constructor<? extends S> constructor = null; try { constructor = serviceClass.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (Throwable t) { throw new ServiceConfigurationError(ERROR_INSTANTIATING + ":" + serviceClass.getName(), t); } } }
@Override @SuppressWarnings("unchecked") public final <K> KeyManager<K> get(final Class<K> type) { final KeyManager<?> manager = get().get(type); if (null == manager) throw new ServiceConfigurationError("No key manager available for " + type); return (KeyManager<K>) manager; }