Search in sources :

Example 1 with OsgiException

use of org.eclipse.gemini.blueprint.OsgiException in project motech by motech.

the class PlatformActivator method registerMdsStartupListener.

private void registerMdsStartupListener() {
    Dictionary<String, String[]> properties = new Hashtable<>();
    properties.put(EventConstants.EVENT_TOPIC, new String[] { PlatformConstants.MDS_STARTUP_TOPIC });
    bundleContext.registerService(EventHandler.class.getName(), new EventHandler() {

        @Override
        public void handleEvent(Event event) {
            try {
                postMdsStartup();
            } catch (ClassNotFoundException e) {
                throw new OsgiException(e);
            }
        }
    }, properties);
}
Also used : Hashtable(java.util.Hashtable) OsgiException(org.eclipse.gemini.blueprint.OsgiException) EventHandler(org.osgi.service.event.EventHandler) ServiceEvent(org.osgi.framework.ServiceEvent) Event(org.osgi.service.event.Event)

Example 2 with OsgiException

use of org.eclipse.gemini.blueprint.OsgiException in project motech by motech.

the class OsgiFrameworkService method start.

/**
 * Initialize, install and start bundles and the OSGi framework
 */
public void start() {
    try {
        LOGGER.info("Starting OSGi framework");
        osgiFramework.start();
        registerJndiLookupService();
        Bundle platformBundle = OsgiBundleUtils.findBundleBySymbolicName(osgiFramework.getBundleContext(), PlatformConstants.PLATFORM_BUNDLE_SYMBOLIC_NAME);
        if (platformBundle == null) {
            throw new OsgiException(PlatformConstants.PLATFORM_BUNDLE_SYMBOLIC_NAME + " not found");
        }
        LOGGER.info("Starting the Platform Bundle");
        platformBundle.start();
        LOGGER.info("OSGi framework started");
    } catch (BundleException e) {
        throw new OsgiException("Failed to start OSGi framework", e);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) OsgiException(org.eclipse.gemini.blueprint.OsgiException) BundleException(org.osgi.framework.BundleException)

Example 3 with OsgiException

use of org.eclipse.gemini.blueprint.OsgiException in project motech by motech.

the class OsgiFrameworkService method init.

public void init(BootstrapConfig bootstrapConfig) {
    try (InputStream is = getClass().getResourceAsStream("/osgi.properties")) {
        Properties properties = readOSGiProperties(bootstrapConfig, is);
        this.setOsgiFramework(new Felix(properties));
    } catch (IOException e) {
        throw new OsgiException("Cannot read OSGi properties", e);
    }
    try {
        LOGGER.info("Initializing OSGi framework");
        ServletContext servletContext = ((WebApplicationContext) applicationContext).getServletContext();
        osgiFramework.init();
        BundleContext bundleContext = osgiFramework.getBundleContext();
        // This is mandatory for Felix http servlet bridge
        servletContext.setAttribute(BundleContext.class.getName(), bundleContext);
        if (bootstrapConfig != null) {
            LOGGER.info("Installing all available bundles");
            installAllBundles(servletContext, bundleContext);
            registerBundleLoaderExecutor();
        }
        platformStatusProxy = new PlatformStatusProxy(bundleContext);
        LOGGER.info("OSGi framework initialization finished");
    } catch (BundleLoadingException e) {
        throw new OsgiException("Failed to start the OSGi framework, unable to load bundles", e);
    } catch (BundleException e) {
        throw new OsgiException("Failed to start the OSGi framework, error processing bundles", e);
    } catch (IOException e) {
        throw new OsgiException("Failed to start the OSGi framework, IO Error", e);
    }
}
Also used : Felix(org.apache.felix.framework.Felix) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) BundleLoadingException(org.motechproject.server.ex.BundleLoadingException) OsgiException(org.eclipse.gemini.blueprint.OsgiException) ServletContext(javax.servlet.ServletContext) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) Properties(java.util.Properties) WebApplicationContext(org.springframework.web.context.WebApplicationContext) BundleContext(org.osgi.framework.BundleContext)

Example 4 with OsgiException

use of org.eclipse.gemini.blueprint.OsgiException in project motech by motech.

the class OsgiFrameworkService method stop.

/**
 * Stop the OSGi framework.
 */
public void stop() {
    try {
        if (osgiFramework != null) {
            osgiFramework.stop();
            LOGGER.info("OSGi framework stopped");
        }
    } catch (BundleException e) {
        throw new OsgiException("Error stopping OSGi framework", e);
    }
}
Also used : OsgiException(org.eclipse.gemini.blueprint.OsgiException) BundleException(org.osgi.framework.BundleException)

Aggregations

OsgiException (org.eclipse.gemini.blueprint.OsgiException)4 BundleException (org.osgi.framework.BundleException)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Hashtable (java.util.Hashtable)1 Properties (java.util.Properties)1 JarInputStream (java.util.jar.JarInputStream)1 ServletContext (javax.servlet.ServletContext)1 Felix (org.apache.felix.framework.Felix)1 BundleLoadingException (org.motechproject.server.ex.BundleLoadingException)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceEvent (org.osgi.framework.ServiceEvent)1 Event (org.osgi.service.event.Event)1 EventHandler (org.osgi.service.event.EventHandler)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1