use of java.util.ServiceConfigurationError in project hadoop by apache.
the class TestCluster method testProtocolProviderCreation.
@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();
}
use of java.util.ServiceConfigurationError in project lucene-solr by apache.
the class NamedSPILoader method reload.
/**
* Reloads the internal SPI list from the given {@link ClassLoader}.
* Changes to the service list are visible after the method ends, all
* iterators ({@link #iterator()},...) stay consistent.
*
* <p><b>NOTE:</b> Only new service providers are added, existing ones are
* never removed or replaced.
*
* <p><em>This method is expensive and should only be called for discovery
* of new service providers on the given classpath/classloader!</em>
*/
public void reload(ClassLoader classloader) {
Objects.requireNonNull(classloader, "classloader");
final LinkedHashMap<String, S> services = new LinkedHashMap<>(this.services);
final SPIClassIterator<S> loader = SPIClassIterator.get(clazz, classloader);
while (loader.hasNext()) {
final Class<? extends S> c = loader.next();
try {
final S service = c.newInstance();
final String name = service.getName();
// them used instead of others
if (!services.containsKey(name)) {
checkServiceName(name);
services.put(name, service);
}
} catch (Exception e) {
throw new ServiceConfigurationError("Cannot instantiate SPI class: " + c.getName(), e);
}
}
this.services = Collections.unmodifiableMap(services);
}
use of java.util.ServiceConfigurationError in project jdk8u_jdk by JetBrains.
the class SelectorProvider method loadProviderFromProperty.
private static boolean loadProviderFromProperty() {
String cn = System.getProperty("java.nio.channels.spi.SelectorProvider");
if (cn == null)
return false;
try {
Class<?> c = Class.forName(cn, true, ClassLoader.getSystemClassLoader());
provider = (SelectorProvider) c.newInstance();
return true;
} catch (ClassNotFoundException x) {
throw new ServiceConfigurationError(null, x);
} catch (IllegalAccessException x) {
throw new ServiceConfigurationError(null, x);
} catch (InstantiationException x) {
throw new ServiceConfigurationError(null, x);
} catch (SecurityException x) {
throw new ServiceConfigurationError(null, x);
}
}
use of java.util.ServiceConfigurationError in project jdk8u_jdk by JetBrains.
the class RowSetProvider method loadViaServiceLoader.
/**
* Use the ServiceLoader mechanism to load the default RowSetFactory
* @return default RowSetFactory Implementation
*/
private static RowSetFactory loadViaServiceLoader() throws SQLException {
RowSetFactory theFactory = null;
try {
trace("***in loadViaServiceLoader():");
for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
theFactory = factory;
break;
}
} catch (ServiceConfigurationError e) {
throw new SQLException("RowSetFactory: Error locating RowSetFactory using Service " + "Loader API: " + e, e);
}
return theFactory;
}
use of java.util.ServiceConfigurationError in project apex-malhar by apache.
the class FlumeSink method stop.
@Override
public void stop() {
try {
super.stop();
} finally {
try {
if (client != null) {
eventloop.disconnect(client);
client = null;
}
eventloop.stop(server);
eventloop.stop();
if (codec instanceof Component) {
@SuppressWarnings("unchecked") Component<com.datatorrent.api.Context> component = (Component<com.datatorrent.api.Context>) codec;
component.teardown();
}
if (discovery instanceof Component) {
@SuppressWarnings("unchecked") Component<com.datatorrent.api.Context> component = (Component<com.datatorrent.api.Context>) discovery;
component.teardown();
}
if (storage instanceof Component) {
@SuppressWarnings("unchecked") Component<com.datatorrent.api.Context> component = (Component<com.datatorrent.api.Context>) storage;
component.teardown();
}
} catch (Throwable cause) {
throw new ServiceConfigurationError("Failed Stop", cause);
}
}
}
Aggregations