Search in sources :

Example 1 with ServiceMetadata

use of org.osgi.service.blueprint.reflect.ServiceMetadata in project aries by apache.

the class AbstractParserProxy method parseCDRForServices.

/**
	   * Extract Service metadata from a ComponentDefinitionRegistry. When doing SCA modelling, we
	   * need to suppress anonymous services. We don't want to do that when we're modelling for 
	   * provisioning dependencies. 
	   * @param cdr                       ComponentDefinitionRegistry
	   * @param suppressAnonymousServices Unnamed services will not be returned if this is true
	   * @return List<WrappedServiceMetadata>
	   */
private List<ExportedService> parseCDRForServices(ComponentDefinitionRegistry cdr, boolean suppressAnonymousServices) {
    _logger.debug(LOG_ENTRY, "parseCDRForServices", new Object[] { cdr, suppressAnonymousServices });
    List<ExportedService> result = new ArrayList<ExportedService>();
    for (ComponentMetadata compMetadata : findAllComponents(cdr)) {
        if (compMetadata instanceof ServiceMetadata) {
            ServiceMetadata serviceMetadata = (ServiceMetadata) compMetadata;
            String serviceName;
            int ranking;
            Collection<String> interfaces = new ArrayList<String>();
            Map<String, Object> serviceProps = new HashMap<String, Object>();
            ranking = serviceMetadata.getRanking();
            for (Object i : serviceMetadata.getInterfaces()) {
                interfaces.add((String) i);
            }
            // get the service properties
            List<MapEntry> props = serviceMetadata.getServiceProperties();
            for (MapEntry entry : props) {
                String key = ((ValueMetadata) entry.getKey()).getStringValue();
                Metadata value = entry.getValue();
                if (value instanceof CollectionMetadata) {
                    processMultiValueProperty(serviceProps, key, value);
                } else {
                    serviceProps.put(key, ((ValueMetadata) entry.getValue()).getStringValue());
                }
            }
            // serviceName: use the service id unless that's not set, 
            // in which case we use the bean id. 
            serviceName = serviceMetadata.getId();
            // If the Service references a Bean, export the bean id as a service property
            // as per 121.6.5 p669 of the blueprint 1.0 specification
            Target t = serviceMetadata.getServiceComponent();
            String targetId = null;
            if (t instanceof RefMetadata) {
                targetId = ((RefMetadata) t).getComponentId();
            } else if (t instanceof BeanMetadata) {
                targetId = ((BeanMetadata) t).getId();
            }
            // or auto-generated for an anonymous service. This must ALWAYS be set. 
            if (targetId != null && !targetId.startsWith(".")) {
                // Don't set this for anonymous inner components
                serviceProps.put("osgi.service.blueprint.compname", targetId);
                if (serviceName == null || serviceName.equals("") || serviceName.startsWith(".")) {
                    serviceName = targetId;
                }
            }
            if (serviceName != null && serviceName.startsWith("."))
                serviceName = null;
            // If suppressAnonymous services, do not expose services that have no name
            if (!suppressAnonymousServices || (serviceName != null)) {
                ExportedService wsm = _modellingManager.getExportedService(serviceName, ranking, interfaces, serviceProps);
                result.add(wsm);
            }
        }
    }
    _logger.debug(LOG_EXIT, "parseAllServiceElements", new Object[] { result });
    return result;
}
Also used : CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) HashMap(java.util.HashMap) ExportedService(org.apache.aries.application.modelling.ExportedService) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) ArrayList(java.util.ArrayList) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) Target(org.osgi.service.blueprint.reflect.Target) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata)

Example 2 with ServiceMetadata

use of org.osgi.service.blueprint.reflect.ServiceMetadata in project aries by apache.

the class BlueprintContainerImpl method notifySatisfaction.

public void notifySatisfaction(SatisfiableRecipe satisfiable) {
    if (destroyed.get()) {
        return;
    }
    LOGGER.debug("Notified satisfaction {} in bundle {}/{}: {}", satisfiable.getName(), bundle.getSymbolicName(), getBundle().getVersion(), satisfiable.isSatisfied());
    if (state == State.Create || state == State.Created) {
        Map<String, List<SatisfiableRecipe>> dependencies = getSatisfiableDependenciesMap();
        for (Map.Entry<String, List<SatisfiableRecipe>> entry : dependencies.entrySet()) {
            String name = entry.getKey();
            ComponentMetadata metadata = componentDefinitionRegistry.getComponentDefinition(name);
            if (metadata instanceof ServiceMetadata) {
                ServiceRecipe reg = (ServiceRecipe) repository.getRecipe(name);
                synchronized (reg) {
                    boolean satisfied = true;
                    for (SatisfiableRecipe recipe : entry.getValue()) {
                        if (!recipe.isSatisfied()) {
                            satisfied = false;
                            break;
                        }
                    }
                    if (satisfied && !reg.isRegistered()) {
                        LOGGER.debug("Registering service {} due to satisfied references", name);
                        reg.register();
                    } else if (!satisfied && reg.isRegistered()) {
                        LOGGER.debug("Unregistering service {} due to unsatisfied references", name);
                        reg.unregister();
                    }
                }
            }
        }
    } else {
        schedule();
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) Map(java.util.Map) HashMap(java.util.HashMap) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata)

Example 3 with ServiceMetadata

use of org.osgi.service.blueprint.reflect.ServiceMetadata in project aries by apache.

the class BlueprintContainerImpl method getMetadata.

private <T extends ComponentMetadata> void getMetadata(Class<T> clazz, Metadata component, Collection<T> metadatas) {
    if (component == null) {
        return;
    }
    if (clazz.isInstance(component)) {
        metadatas.add(clazz.cast(component));
    }
    if (component instanceof BeanMetadata) {
        getMetadata(clazz, ((BeanMetadata) component).getFactoryComponent(), metadatas);
        for (BeanArgument arg : ((BeanMetadata) component).getArguments()) {
            getMetadata(clazz, arg.getValue(), metadatas);
        }
        for (BeanProperty prop : ((BeanMetadata) component).getProperties()) {
            getMetadata(clazz, prop.getValue(), metadatas);
        }
    }
    if (component instanceof CollectionMetadata) {
        for (Metadata m : ((CollectionMetadata) component).getValues()) {
            getMetadata(clazz, m, metadatas);
        }
    }
    if (component instanceof MapMetadata) {
        for (MapEntry m : ((MapMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof PropsMetadata) {
        for (MapEntry m : ((PropsMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof ServiceReferenceMetadata) {
        for (ReferenceListener l : ((ServiceReferenceMetadata) component).getReferenceListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
    if (component instanceof ServiceMetadata) {
        getMetadata(clazz, ((ServiceMetadata) component).getServiceComponent(), metadatas);
        for (MapEntry m : ((ServiceMetadata) component).getServiceProperties()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
        for (RegistrationListener l : ((ServiceMetadata) component).getRegistrationListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 4 with ServiceMetadata

use of org.osgi.service.blueprint.reflect.ServiceMetadata in project aries by apache.

the class AbstractParserProxy method traverseComponent.

/**
	   * Traverse {@link ComponentMetadata} instances to find all nested {@link ComponentMetadata} instances
	   * @param component
	   * @param output
	   */
private void traverseComponent(ComponentMetadata component, Set<ComponentMetadata> output) {
    if (!!!output.add(component))
        return;
    if (component instanceof BeanMetadata) {
        BeanMetadata bean = (BeanMetadata) component;
        traverse(bean.getFactoryComponent(), output);
        for (BeanArgument argument : bean.getArguments()) {
            traverse(argument.getValue(), output);
        }
        for (BeanProperty property : bean.getProperties()) {
            traverse(property.getValue(), output);
        }
    } else if (component instanceof ServiceMetadata) {
        ServiceMetadata service = (ServiceMetadata) component;
        traverse(service.getServiceComponent(), output);
        for (RegistrationListener listener : service.getRegistrationListeners()) {
            traverse(listener.getListenerComponent(), output);
        }
        for (MapEntry e : service.getServiceProperties()) {
            traverse(e.getKey(), output);
            traverse(e.getValue(), output);
        }
    } else if (component instanceof ServiceReferenceMetadata) {
        ServiceReferenceMetadata reference = (ServiceReferenceMetadata) component;
        for (ReferenceListener listener : reference.getReferenceListeners()) {
            traverse(listener.getListenerComponent(), output);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Aggregations

ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)4 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)3 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)3 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)3 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)2 BeanArgument (org.osgi.service.blueprint.reflect.BeanArgument)2 BeanProperty (org.osgi.service.blueprint.reflect.BeanProperty)2 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)2 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)2 Metadata (org.osgi.service.blueprint.reflect.Metadata)2 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)2 ReferenceListener (org.osgi.service.blueprint.reflect.ReferenceListener)2 RegistrationListener (org.osgi.service.blueprint.reflect.RegistrationListener)2 List (java.util.List)1 Map (java.util.Map)1 ExportedService (org.apache.aries.application.modelling.ExportedService)1 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)1