You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Pierre De Rop (JIRA)" <ji...@apache.org> on 2015/04/28 10:03:06 UTC

[jira] [Commented] (FELIX-4869) Callbacks not invoked for dependencies that are added after the component is initialized

    [ https://issues.apache.org/jira/browse/FELIX-4869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14516617#comment-14516617 ] 

Pierre De Rop commented on FELIX-4869:
--------------------------------------

Hello Bram,

Thanks for reporting, I will try to reproduce this issue with a DM testcase and will let you know asap (today if possible).
Did you check if you have some exceptions in the OSG log service when you are facing the issue ?


Regarding your last comment, yes, iif you add multiple dependencies from the init() method, then you have to do it atomically and pass all dependencies in one shot using the varargs options. Please see the documentation on the Component.add(Dependency ... dependencies) in [1].

[1] http://felix.apache.org/apidocs/dependencymanager/4.0.0/org/apache/felix/dm/Component.html

> 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)