Search in sources :

Example 1 with ServiceConfigurationError

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();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Iterator(java.util.Iterator) ServiceConfigurationError(java.util.ServiceConfigurationError) Test(org.junit.Test)

Example 2 with ServiceConfigurationError

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);
}
Also used : ServiceConfigurationError(java.util.ServiceConfigurationError) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ServiceConfigurationError

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);
    }
}
Also used : ServiceConfigurationError(java.util.ServiceConfigurationError)

Example 4 with ServiceConfigurationError

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;
}
Also used : SQLException(java.sql.SQLException) ServiceConfigurationError(java.util.ServiceConfigurationError)

Example 5 with ServiceConfigurationError

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);
        }
    }
}
Also used : Context(org.apache.flume.Context) NetletThrowable(com.datatorrent.netlet.NetletThrowable) ServiceConfigurationError(java.util.ServiceConfigurationError) Component(com.datatorrent.api.Component)

Aggregations

ServiceConfigurationError (java.util.ServiceConfigurationError)34 IOException (java.io.IOException)9 Iterator (java.util.Iterator)6 File (java.io.File)5 FileInputStream (java.io.FileInputStream)3 ArrayList (java.util.ArrayList)3 NoSuchElementException (java.util.NoSuchElementException)3 Properties (java.util.Properties)3 ServiceLoader (java.util.ServiceLoader)3 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)2 Exporter (edu.harvard.iq.dataverse.export.spi.Exporter)2 JsonPrinter (edu.harvard.iq.dataverse.util.json.JsonPrinter)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 CharsetProvider (java.nio.charset.spi.CharsetProvider)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 Configuration (org.apache.hadoop.conf.Configuration)2 Test (org.junit.Test)2 NoProviderFoundException (com.att.cdp.exceptions.NoProviderFoundException)1