Search in sources :

Example 1 with ContextException

use of org.apache.aries.application.management.spi.repository.ContextException 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 ContextException

use of org.apache.aries.application.management.spi.repository.ContextException in project aries by apache.

the class BundleRepositoryManagerImpl method getBundleSuggestions.

public Map<DeploymentContent, BundleSuggestion> getBundleSuggestions(Collection<BundleRepository> providers, Collection<DeploymentContent> content) throws ContextException {
    LOGGER.debug(LOG_ENTRY, "getBundleSuggestions", new Object[] { content, providers });
    Map<DeploymentContent, BundleSuggestion> urlToBeInstalled = new HashMap<DeploymentContent, BundleSuggestion>();
    Iterator<DeploymentContent> it = content.iterator();
    while (it.hasNext()) {
        DeploymentContent bundleToFind = it.next();
        Map<Version, List<BundleSuggestion>> bundlesuggestions = new HashMap<Version, List<BundleSuggestion>>();
        for (BundleRepository obj : providers) {
            BundleSuggestion suggestion = obj.suggestBundleToUse(bundleToFind);
            if (suggestion != null) {
                List<BundleSuggestion> suggestions = bundlesuggestions.get(suggestion.getVersion());
                if (suggestions == null) {
                    suggestions = new ArrayList<BundleSuggestion>();
                    bundlesuggestions.put(suggestion.getVersion(), suggestions);
                }
                suggestions.add(suggestion);
            }
        }
        BundleSuggestion suggestion = null;
        if (!!!bundlesuggestions.isEmpty()) {
            List<BundleSuggestion> thoughts = bundlesuggestions.get(bundleToFind.getExactVersion());
            if (thoughts != null) {
                Collections.sort(thoughts, new Comparator<BundleSuggestion>() {

                    public int compare(BundleSuggestion o1, BundleSuggestion o2) {
                        return o1.getCost() - o2.getCost();
                    }
                });
                suggestion = thoughts.get(0);
            }
        }
        // add the suggestion to the list
        if (suggestion != null) {
            urlToBeInstalled.put(bundleToFind, suggestion);
        } else {
            throw new ContextException("Unable to find bundle " + bundleToFind.getContentName() + "/" + bundleToFind.getExactVersion());
        }
    }
    LOGGER.debug(LOG_EXIT, "getBundleSuggestions", new Object[] { urlToBeInstalled });
    return urlToBeInstalled;
}
Also used : HashMap(java.util.HashMap) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) ContextException(org.apache.aries.application.management.spi.repository.ContextException) DeploymentContent(org.apache.aries.application.DeploymentContent) Version(org.osgi.framework.Version) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) ArrayList(java.util.ArrayList) List(java.util.List) ArrayServiceList(org.apache.aries.application.utils.service.ArrayServiceList)

Aggregations

ContextException (org.apache.aries.application.management.spi.repository.ContextException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 DeploymentContent (org.apache.aries.application.DeploymentContent)1 BundleFrameworkConfiguration (org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)1 BundleRepository (org.apache.aries.application.management.spi.repository.BundleRepository)1 BundleSuggestion (org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion)1 ArrayServiceList (org.apache.aries.application.utils.service.ArrayServiceList)1 BundleException (org.osgi.framework.BundleException)1 Version (org.osgi.framework.Version)1