Search in sources :

Example 6 with ServiceConfigurationError

use of java.util.ServiceConfigurationError in project Payara by payara.

the class GlassFishRuntime method getRuntimeBuilder.

private static RuntimeBuilder getRuntimeBuilder(BootstrapProperties bootstrapProperties, ClassLoader cl) throws GlassFishException {
    // StringBuilder sb = new StringBuilder("Launcher Class Loader = " + cl);
    // if (cl instanceof URLClassLoader) {
    // sb.append("has following Class Path: ");
    // for (URL url : URLClassLoader.class.cast(cl).getURLs()) {
    // sb.append(url).append(", ");
    // }
    // }
    // System.out.println(sb);
    Iterator<RuntimeBuilder> runtimeBuilders = ServiceLoader.load(RuntimeBuilder.class, cl).iterator();
    while (runtimeBuilders.hasNext()) {
        try {
            RuntimeBuilder builder = runtimeBuilders.next();
            logger.logp(Level.FINE, "GlassFishRuntime", "getRuntimeBuilder", "builder = {0}", new Object[] { builder });
            if (builder.handles(bootstrapProperties)) {
                return builder;
            }
        } catch (ServiceConfigurationError sce) {
            // Ignore the exception and move ahead to the next builder.
            logger.logp(Level.FINE, "GlassFishRuntime", "getRuntimeBuilder", "Ignoring", sce);
        } catch (NoClassDefFoundError ncdfe) {
            // On IBM JDK, we seem to be getting NoClassDefFoundError instead of ServiceConfigurationError
            // when OSgiRuntimeBuilder is not able to be loaded in non-OSGi mode because of absence of
            // OSGi classes in classpath. So, we need to catch it and ignore.
            logger.logp(Level.FINE, "GlassFishRuntime", "getRuntimeBuilder", "Ignoring", ncdfe);
        }
    }
    throw new GlassFishException("No runtime builder available for this configuration: " + bootstrapProperties.getProperties(), null);
}
Also used : ServiceConfigurationError(java.util.ServiceConfigurationError) RuntimeBuilder(org.glassfish.embeddable.spi.RuntimeBuilder)

Example 7 with ServiceConfigurationError

use of java.util.ServiceConfigurationError in project hadoop by apache.

the class Cluster method initProviderList.

private void initProviderList() {
    if (providerList == null) {
        synchronized (frameworkLoader) {
            if (providerList == null) {
                List<ClientProtocolProvider> localProviderList = new ArrayList<ClientProtocolProvider>();
                try {
                    for (ClientProtocolProvider provider : frameworkLoader) {
                        localProviderList.add(provider);
                    }
                } catch (ServiceConfigurationError e) {
                    LOG.info("Failed to instantiate ClientProtocolProvider, please " + "check the /META-INF/services/org.apache." + "hadoop.mapreduce.protocol.ClientProtocolProvider " + "files on the classpath", e);
                }
                providerList = localProviderList;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ServiceConfigurationError(java.util.ServiceConfigurationError) ClientProtocolProvider(org.apache.hadoop.mapreduce.protocol.ClientProtocolProvider)

Example 8 with ServiceConfigurationError

use of java.util.ServiceConfigurationError in project hadoop by apache.

the class TestFileSystemInitialization method testMissingLibraries.

@Test
public void testMissingLibraries() {
    try {
        Configuration conf = new Configuration();
        Class<? extends FileSystem> fs = FileSystem.getFileSystemClass("s3a", conf);
        fail("Expected an exception, got a filesystem: " + fs);
    } catch (Exception | ServiceConfigurationError expected) {
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ServiceConfigurationError(java.util.ServiceConfigurationError) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with ServiceConfigurationError

use of java.util.ServiceConfigurationError in project aries by apache.

the class AriesRepositoryGenerator method startFramework.

/**
   * Start OSGi framework and install the necessary bundles
   * @return
   * @throws BundleException
   */
public BundleContext startFramework() throws BundleException {
    ServiceLoader<FrameworkFactory> factoryLoader = ServiceLoader.load(FrameworkFactory.class, getClass().getClassLoader());
    Iterator<FrameworkFactory> factoryIterator = factoryLoader.iterator();
    //Map<String, String> osgiPropertyMap = new HashMap<String, String>();
    if (!!!factoryIterator.hasNext()) {
        System.out.println("Unable to locate the osgi jar");
    }
    try {
        FrameworkFactory frameworkFactory = factoryIterator.next();
        framework = frameworkFactory.newFramework(Collections.EMPTY_MAP);
    } catch (ServiceConfigurationError sce) {
        sce.printStackTrace();
    }
    framework.init();
    framework.start();
    // install the bundles in the current directory
    Collection<Bundle> installedBundles = new ArrayList<Bundle>();
    File bundleDir = new File(".");
    File[] jars = bundleDir.listFiles();
    try {
        for (File jar : jars) {
            if (jar.isFile() && (jar.getName().endsWith(".jar"))) {
                String location = URLDecoder.decode(jar.toURI().toURL().toExternalForm(), "UTF-8");
                if (shouldInstall(location, getIgnoreList())) {
                    installedBundles.add(framework.getBundleContext().installBundle("reference:" + location));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    ServiceReference paRef = framework.getBundleContext().getServiceReference(PackageAdmin.class.getCanonicalName());
    if (paRef != null) {
        try {
            PackageAdmin admin = (PackageAdmin) framework.getBundleContext().getService(paRef);
            admin.resolveBundles(installedBundles.toArray(new Bundle[installedBundles.size()]));
        } finally {
            framework.getBundleContext().ungetService(paRef);
        }
    } else {
        System.out.println("Unable to find the service reference for package admin");
    }
    //loop through the list of installed bundles to start them
    for (Bundle bundle : installedBundles) {
        try {
            if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
                //start the bundle using its activiation policy
                bundle.start(Bundle.START_ACTIVATION_POLICY);
            } else {
            //nothing to start, we have got a fragment
            }
        } catch (BundleException e) {
            e.printStackTrace();
            continue;
        }
    }
    return framework.getBundleContext();
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ServiceConfigurationError(java.util.ServiceConfigurationError) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) FrameworkFactory(org.osgi.framework.launch.FrameworkFactory) ServiceReference(org.osgi.framework.ServiceReference) PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) BundleException(org.osgi.framework.BundleException) File(java.io.File)

Example 10 with ServiceConfigurationError

use of java.util.ServiceConfigurationError in project lucene-solr by apache.

the class SPIClassIterator method loadNextProfile.

private boolean loadNextProfile() {
    ArrayList<String> lines = null;
    while (profilesEnum.hasMoreElements()) {
        if (lines != null) {
            lines.clear();
        } else {
            lines = new ArrayList<>();
        }
        final URL url = profilesEnum.nextElement();
        try {
            final InputStream in = url.openStream();
            boolean success = false;
            try {
                final BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
                String line;
                while ((line = reader.readLine()) != null) {
                    final int pos = line.indexOf('#');
                    if (pos >= 0) {
                        line = line.substring(0, pos);
                    }
                    line = line.trim();
                    if (line.length() > 0) {
                        lines.add(line);
                    }
                }
                success = true;
            } finally {
                if (success) {
                    IOUtils.close(in);
                } else {
                    IOUtils.closeWhileHandlingException(in);
                }
            }
        } catch (IOException ioe) {
            throw new ServiceConfigurationError("Error loading SPI class list from URL: " + url, ioe);
        }
        if (!lines.isEmpty()) {
            this.linesIterator = lines.iterator();
            return true;
        }
    }
    return false;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ServiceConfigurationError(java.util.ServiceConfigurationError) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

ServiceConfigurationError (java.util.ServiceConfigurationError)14 IOException (java.io.IOException)3 Iterator (java.util.Iterator)3 ArrayList (java.util.ArrayList)2 Configuration (org.apache.hadoop.conf.Configuration)2 Test (org.junit.Test)2 Component (com.datatorrent.api.Component)1 NetletThrowable (com.datatorrent.netlet.NetletThrowable)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 CharsetProvider (java.nio.charset.spi.CharsetProvider)1 SQLException (java.sql.SQLException)1 LinkedHashMap (java.util.LinkedHashMap)1 NoSuchElementException (java.util.NoSuchElementException)1 ServiceLoader (java.util.ServiceLoader)1 Context (org.apache.flume.Context)1 ClientProtocolProvider (org.apache.hadoop.mapreduce.protocol.ClientProtocolProvider)1