use of org.apache.felix.dm.context.DependencyContext in project felix by apache.
the class ComponentImpl method removeInstanceBoundDependencies.
/**
* Removes and closes all instance bound dependencies.
* This method is called when a component is destroyed.
*/
private void removeInstanceBoundDependencies() {
for (DependencyContext dep : m_dependencies) {
if (dep.isInstanceBound()) {
m_dependencies.remove(dep);
generateNameBasedOnServiceAndProperties();
dep.stop();
}
}
}
use of org.apache.felix.dm.context.DependencyContext in project felix by apache.
the class ComponentImpl method add.
@Override
public Component add(final Dependency... dependencies) {
getExecutor().execute(() -> {
List<DependencyContext> instanceBoundDeps = new ArrayList<>();
for (Dependency d : dependencies) {
DependencyContext dc = (DependencyContext) d;
if (dc.getComponentContext() != null) {
m_logger.err("%s can't be added to %s (dependency already added to component %s).", dc, ComponentImpl.this, dc.getComponentContext());
continue;
}
m_dependencyEvents.put(dc, new ConcurrentSkipListSet<Event>());
m_dependencies.add(dc);
generateNameBasedOnServiceAndProperties();
dc.setComponentContext(ComponentImpl.this);
if (!(m_state == ComponentState.INACTIVE)) {
dc.setInstanceBound(true);
instanceBoundDeps.add(dc);
}
}
startDependencies(instanceBoundDeps);
handleChange();
});
return this;
}
use of org.apache.felix.dm.context.DependencyContext in project felix by apache.
the class AbstractDecorator method addDependency.
/**
* Add a Dependency to all already instantiated services.
*/
public void addDependency(Dependency... dependencies) {
for (Component component : m_services.values()) {
Dependency[] copy = Stream.of(dependencies).map(d -> (DependencyContext) d).map(dc -> dc.createCopy()).toArray(Dependency[]::new);
for (int i = 0; i < dependencies.length; i++) {
m_depclones.put(dependencies[i], copy[i]);
}
component.add(copy);
}
}
use of org.apache.felix.dm.context.DependencyContext in project felix by apache.
the class ComponentImpl method startDependencies.
private void startDependencies(List<DependencyContext> dependencies) {
// Start first optional dependencies first.
m_logger.debug("startDependencies.");
List<DependencyContext> requiredDeps = new ArrayList<>();
for (DependencyContext d : dependencies) {
if (d.isRequired()) {
requiredDeps.add(d);
continue;
}
if (d.needsInstance()) {
instantiateComponent();
}
d.start();
}
// now, start required dependencies.
for (DependencyContext d : requiredDeps) {
if (d.needsInstance()) {
instantiateComponent();
}
d.start();
}
}
use of org.apache.felix.dm.context.DependencyContext in project felix by apache.
the class ComponentImpl method remove.
@Override
public Component remove(final Dependency d) {
getExecutor().execute(() -> {
DependencyContext dc = (DependencyContext) d;
// First remove this dependency from the dependency list
m_dependencies.remove(d);
generateNameBasedOnServiceAndProperties();
// the removed dependency).
if (!(m_state == ComponentState.INACTIVE)) {
dc.stop();
}
// Finally, cleanup the dependency events.
m_dependencyEvents.remove(d);
handleChange();
});
return this;
}
Aggregations