Search in sources :

Example 1 with BlueprintContainer

use of org.osgi.service.blueprint.container.BlueprintContainer in project pentaho-metaverse by pentaho.

the class MetaverseBeanUtil method get.

public Object get(String id) {
    BlueprintContainer service = null;
    if (bundleContext == null) {
        return null;
    } else {
        try {
            Bundle bundle = bundleContext.getBundle();
            if (bundle == null) {
                return null;
            }
            Collection<ServiceReference<BlueprintContainer>> serviceReferences = bundleContext.getServiceReferences(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + bundle.getSymbolicName() + ")");
            if (serviceReferences.size() != 0) {
                ServiceReference<BlueprintContainer> reference = serviceReferences.iterator().next();
                service = bundleContext.getService(reference);
            }
        } catch (InvalidSyntaxException e) {
        // No-op, service will be null
        }
        if (service == null) {
            return null;
        }
        return service.getComponentInstance(id);
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) Bundle(org.osgi.framework.Bundle) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with BlueprintContainer

use of org.osgi.service.blueprint.container.BlueprintContainer in project fabric8 by jboss-fuse.

the class WatcherBlueprintContainer method removePath.

protected void removePath(Path path) {
    URL url = toUrl(path);
    if (url != null) {
        BlueprintContainer container = containerMap.remove(url);
        closeContainer(url, container);
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) URL(java.net.URL)

Example 3 with BlueprintContainer

use of org.osgi.service.blueprint.container.BlueprintContainer in project fabric8 by jboss-fuse.

the class WatcherBlueprintContainer method destroy.

public void destroy() {
    if (closing.compareAndSet(false, true)) {
        Set<Map.Entry<URL, BlueprintContainer>> entries = containerMap.entrySet();
        for (Map.Entry<URL, BlueprintContainer> entry : entries) {
            URL url = entry.getKey();
            BlueprintContainer container = entry.getValue();
            closeContainer(url, container);
        }
    }
    super.destroy();
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL)

Example 4 with BlueprintContainer

use of org.osgi.service.blueprint.container.BlueprintContainer in project controller by opendaylight.

the class BlueprintBundleTracker method shutdownAllContainers.

private void shutdownAllContainers() {
    shuttingDown = true;
    restartService.close();
    // Close all CSS modules first.
    ConfigSystemService configSystem = getOSGiService(ConfigSystemService.class);
    if (configSystem != null) {
        configSystem.closeAllConfigModules();
    }
    LOG.info("Shutting down all blueprint containers...");
    Collection<Bundle> containerBundles = new HashSet<>(Arrays.asList(bundleContext.getBundles()));
    while (!containerBundles.isEmpty()) {
        // eligible to be destroyed. We loop until we've destroyed them all.
        for (Bundle bundle : getBundlesToDestroy(containerBundles)) {
            containerBundles.remove(bundle);
            BlueprintContainer container = blueprintExtenderService.getContainer(bundle);
            if (container != null) {
                blueprintExtenderService.destroyContainer(bundle, container);
            }
        }
    }
    LOG.info("Shutdown of blueprint containers complete");
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) ConfigSystemService(org.opendaylight.controller.config.api.ConfigSystemService) Bundle(org.osgi.framework.Bundle) HashSet(java.util.HashSet)

Example 5 with BlueprintContainer

use of org.osgi.service.blueprint.container.BlueprintContainer in project admin-console-beta by connexta.

the class BundleUtils method populateServices.

private void populateServices(Bundle bundle, BundleField toPopulate) {
    Optional<BlueprintContainer> blueprintContainer = getBlueprintContainer(bundle);
    if (blueprintContainer.isPresent()) {
        List<ComponentMetadata> cmpMetas = blueprintContainer.get().getComponentIds().stream().map(id -> blueprintContainer.get().getComponentMetadata(id)).collect(Collectors.toList());
        for (ComponentMetadata meta : cmpMetas) {
            if (meta instanceof ReferenceListMetadata) {
                populateServiceRefLists((ReferenceListMetadata) meta, bundle, toPopulate);
            } else if (meta instanceof ReferenceMetadata) {
                populateServiceRef((ReferenceMetadata) meta, bundle, toPopulate);
            } else if (meta instanceof BeanMetadata || meta instanceof ServiceMetadata || meta instanceof PassThroughMetadata) {
                continue;
            } else {
                LOGGER.warn("Unable to handle blueprint metadata of type {} for bundle {}.", meta.getClass(), bundle.getSymbolicName());
            }
        }
        getRegisteredServices(bundle).forEach(ref -> toPopulate.addService(createServiceField(ref)));
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) ServiceReferenceField(org.codice.ddf.admin.query.dev.system.fields.ServiceReferenceField) ServiceReferenceListField(org.codice.ddf.admin.query.dev.system.fields.ServiceReferenceListField) BundleService(org.apache.karaf.bundle.core.BundleService) LoggerFactory(org.slf4j.LoggerFactory) PackageField(org.codice.ddf.admin.query.dev.system.fields.PackageField) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) ArrayList(java.util.ArrayList) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) Parser(org.apache.felix.utils.manifest.Parser) ServiceField(org.codice.ddf.admin.query.dev.system.fields.ServiceField) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) Clause(org.apache.felix.utils.manifest.Clause) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) GetBundles(org.codice.ddf.admin.query.dev.system.discover.GetBundles) Bundle(org.osgi.framework.Bundle) BundleField(org.codice.ddf.admin.query.dev.system.fields.BundleField) ServiceReference(org.osgi.framework.ServiceReference) Logger(org.slf4j.Logger) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) List(java.util.List) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata)

Aggregations

BlueprintContainer (org.osgi.service.blueprint.container.BlueprintContainer)29 Test (org.junit.Test)14 Bundle (org.osgi.framework.Bundle)11 ServiceReference (org.osgi.framework.ServiceReference)6 Helper.mvnBundle (org.apache.aries.blueprint.itests.Helper.mvnBundle)5 List (java.util.List)4 BundleContext (org.osgi.framework.BundleContext)4 DestroyTest (org.apache.aries.blueprint.sample.DestroyTest)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)3 URL (java.net.URL)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 Hashtable (java.util.Hashtable)2 Map (java.util.Map)2 BindingListener (org.apache.aries.blueprint.sample.BindingListener)2 Foo (org.apache.aries.blueprint.sample.Foo)2 InterfaceA (org.apache.aries.blueprint.sample.InterfaceA)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)2