Bram Pouwelse created FELIX-4869:
------------------------------------
Summary: Callbacks not invoked for dependencies that are added
after the component is initialized
Key: FELIX-4869
URL: https://issues.apache.org/jira/browse/FELIX-4869
Project: Felix
Issue Type: Bug
Components: Dependency Manager
Reporter: Bram Pouwelse
When adding a ServiceDependency after the component is initialized the
dependency manager doesn't invoke callbacks for services already registered
before the dependency was added.
I'm using the 4.0.1 version of the dependency manager.
I've created a small example to demonstrate the issue.
{code:title=TestComponent.java}
...
public class TestComponent {
private volatile DependencyManager dm;
private volatile Component c;
public void addDependency(){
c.add(dm.createServiceDependency().setService(Object.class).setCallbacks("add",
"remove"));
}
public void add(ServiceReference<?> ref) {
System.out.println("added " + ref)
}
public void remove(ServiceReference<?> ref) {
System.out.println("removed " + ref)
}
}
{code}
When the dependency is added *after* the services are registered the add
callback is never invoked.
{code:title=Activator.java}
...
@Override
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
TestComponent testComponent = new TestComponent();
dm.add(createComponent().setImplementation(testComponent));
ctx.registerService(Object.class, new Object(), null);
ctx.registerService(Object.class, new Object(), null);
testComponent.addDependency();
}
...
{code}
When the dependency is added *before* the services are registered the add
callback are invoked.
{code:title=Activator.java}
...
@Override
public void init(BundleContext ctx, DependencyManager dm) throws Exception {
TestComponent testComponent = new TestComponent();
dm.add(createComponent().setImplementation(testComponent));
testComponent.addDependency();
ctx.registerService(Object.class, new Object(), null);
ctx.registerService(Object.class, new Object(), null);
}
...
{code}
I've noticed something similar when adding multiple service dependencies in the
init method. When adding the dependencies in one call to
Component#add(Dependency...) everything seems to work as expected but when
calling the add method one component at a time callbacks not invoked for the
second service dependency.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)