Search in sources :

Example 1 with BundleFrameworkConfiguration

use of org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration in project aries by apache.

the class SharedBundleFramework method createSharedBundleFramework.

/**
 * create using any bundle context in EBA App framework as we want to create
 * a child framework under EBA App framework
 *
 * @param bc
 * @throws BundleException
 * @throws InvalidSyntaxException
 */
private static void createSharedBundleFramework(BundleContext bc, BundleFrameworkConfigurationFactory bundleFrameworkConfigFactory, BundleFrameworkFactory bundleFrameworkFactory) throws ContextException {
    LOGGER.debug(LOG_ENTRY, "createSharedBundleFramework", new Object[] { bc, bundleFrameworkFactory });
    try {
        BundleFrameworkConfiguration config = new SharedBundleFrameworkConfiguration(bundleFrameworkConfigFactory.createBundleFrameworkConfig(BundleFramework.SHARED_BUNDLE_FRAMEWORK, bc));
        sharedFramework = bundleFrameworkFactory.createBundleFramework(bc, config);
        sharedFramework.start();
    } catch (BundleException e) {
        LOGGER.debug(LOG_EXIT, "createSharedBundleFramework", e);
        throw new ContextException("Unable to create or start the shared framework composite bundle " + sharedFramework, e);
    }
    LOGGER.debug(LOG_EXIT, "createSharedBundleFramework");
}
Also used : BundleException(org.osgi.framework.BundleException) ContextException(org.apache.aries.application.management.spi.repository.ContextException) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)

Example 2 with BundleFrameworkConfiguration

use of org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration in project aries by apache.

the class BundleFrameworkConfigurationFactoryImpl method createBundleFrameworkConfig.

public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId, BundleContext parentCtx) {
    BundleFrameworkConfiguration config = null;
    // Set up framework config properties
    Properties frameworkConfig = new Properties();
    // Problems occur if the parent framework has osgi.console set because the child framework
    // will also attempt to listen on the same port which will cause port clashs. Setting this
    // to null essentially turns the console off.
    frameworkConfig.put("osgi.console", "none");
    if (parentCtx.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA) != null)
        frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, parentCtx.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA));
    /**
     * Set up BundleManifest for the framework bundle
     */
    Properties frameworkBundleManifest = new Properties();
    /**
     * Set up CompositeServiceFilter-Import header for framework manifest
     */
    StringBuffer serviceImportFilter = new StringBuffer("(" + Constants.OBJECTCLASS + "=" + EquinoxFrameworkConstants.TRANSACTION_REGISTRY_BUNDLE + ")");
    frameworkBundleManifest.put(EquinoxFrameworkConstants.COMPOSITE_SERVICE_FILTER_IMPORT, serviceImportFilter.toString());
    config = new BundleFrameworkConfigurationImpl(frameworkId, frameworkConfig, frameworkBundleManifest);
    return config;
}
Also used : Properties(java.util.Properties) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)

Example 3 with BundleFrameworkConfiguration

use of org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration in project aries by apache.

the class BundleFrameworkManagerImpl method isolatedInstall.

private BundleFramework isolatedInstall(Collection<BundleSuggestion> bundlesToBeInstalled, BundleContext parentCtx, AriesApplication app) throws BundleException {
    LOGGER.debug(LOG_ENTRY, "isolatedInstall", new Object[] { bundlesToBeInstalled, app });
    /**
     * Build the configuration information for this application framework
     */
    BundleFrameworkConfiguration config = _bundleFrameworkConfigurationFactory.createBundleFrameworkConfig(app.getApplicationMetadata().getApplicationScope(), parentCtx, app);
    /**
     * Install and start the new isolated bundle framework
     */
    BundleFramework bundleFramework = _bundleFrameworkFactory.createBundleFramework(parentCtx, config);
    // We should now have a bundleFramework
    if (bundleFramework != null) {
        try {
            bundleFramework.init();
            /**
             * Install the bundles into the new framework
             */
            BundleContext frameworkBundleContext = bundleFramework.getIsolatedBundleContext();
            if (frameworkBundleContext != null) {
                for (BundleSuggestion suggestion : bundlesToBeInstalled) bundleFramework.install(suggestion, app);
            }
        } catch (BundleException be) {
            bundleFramework.close();
            throw be;
        } catch (RuntimeException re) {
            bundleFramework.close();
            throw re;
        }
    }
    LOGGER.debug(LOG_EXIT, "isolatedInstall", bundleFramework);
    return bundleFramework;
}
Also used : BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) BundleException(org.osgi.framework.BundleException) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration) BundleContext(org.osgi.framework.BundleContext)

Example 4 with BundleFrameworkConfiguration

use of org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration in project aries by apache.

the class BundleFrameworkConfigurationFactoryImpl method createBundleFrameworkConfig.

public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId, BundleContext parentCtx, AriesApplication app) {
    BundleFrameworkConfiguration config = null;
    DeploymentMetadata metadata = app.getDeploymentMetadata();
    /**
     * Set up framework config properties
     */
    Properties frameworkConfig = new Properties();
    // Problems occur if the parent framework has osgi.console set because the child framework
    // will also attempt to listen on the same port which will cause port clashs. Setting this
    // to null essentially turns the console off.
    frameworkConfig.put("osgi.console", "none");
    String flowedSystemPackages = EquinoxFrameworkUtils.calculateSystemPackagesToFlow(EquinoxFrameworkUtils.getSystemExtraPkgs(parentCtx), metadata.getImportPackage());
    frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, flowedSystemPackages);
    /**
     * Set up BundleManifest for the framework bundle
     */
    Properties frameworkBundleManifest = new Properties();
    frameworkBundleManifest.put(Constants.BUNDLE_SYMBOLICNAME, metadata.getApplicationSymbolicName());
    frameworkBundleManifest.put(Constants.BUNDLE_VERSION, metadata.getApplicationVersion().toString());
    /**
     * Set up Import-Package header for framework manifest
     */
    // Extract the import packages and remove anything we already have available in the current framework
    Collection<Content> imports = EquinoxFrameworkUtils.calculateImports(metadata.getImportPackage(), EquinoxFrameworkUtils.getExportPackages(parentCtx));
    if (imports != null && !imports.isEmpty()) {
        StringBuffer buffer = new StringBuffer();
        for (Content i : imports) buffer.append(EquinoxFrameworkUtils.contentToString(i) + ",");
        frameworkBundleManifest.put(Constants.IMPORT_PACKAGE, buffer.substring(0, buffer.length() - 1));
    }
    /**
     * Set up CompositeServiceFilter-Import header for framework manifest
     */
    StringBuilder serviceImportFilter = new StringBuilder();
    String txRegsitryImport = "(" + Constants.OBJECTCLASS + "=" + EquinoxFrameworkConstants.TRANSACTION_REGISTRY_BUNDLE + ")";
    Collection<Filter> deployedServiceImports = metadata.getDeployedServiceImport();
    // if there are more services than the txRegistry import a OR group is required for the Filter
    if (deployedServiceImports.size() > 0) {
        serviceImportFilter.append("(|");
    }
    for (Filter importFilter : metadata.getDeployedServiceImport()) {
        serviceImportFilter.append(importFilter.toString());
    }
    serviceImportFilter.append(txRegsitryImport);
    // close the OR group if needed
    if (deployedServiceImports.size() > 0) {
        serviceImportFilter.append(")");
    }
    frameworkBundleManifest.put(EquinoxFrameworkConstants.COMPOSITE_SERVICE_FILTER_IMPORT, serviceImportFilter.toString());
    config = new BundleFrameworkConfigurationImpl(frameworkId, frameworkConfig, frameworkBundleManifest);
    return config;
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) Filter(org.osgi.framework.Filter) Content(org.apache.aries.application.Content) Properties(java.util.Properties) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)

Aggregations

BundleFrameworkConfiguration (org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)4 Properties (java.util.Properties)2 BundleException (org.osgi.framework.BundleException)2 Content (org.apache.aries.application.Content)1 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)1 BundleFramework (org.apache.aries.application.management.spi.framework.BundleFramework)1 BundleSuggestion (org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion)1 ContextException (org.apache.aries.application.management.spi.repository.ContextException)1 BundleContext (org.osgi.framework.BundleContext)1 Filter (org.osgi.framework.Filter)1