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;
}
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();
}
}
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);
}
}
}
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);
}
}
}
Aggregations