felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bram Pouwelse (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FELIX-4869) Callbacks not invoked for dependencies that are added after the component is initialized
Date Tue, 28 Apr 2015 10:16:05 GMT

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

Bram Pouwelse commented on FELIX-4869:
--------------------------------------

Good to hear you've found the issue, and even better that you'll have a patch today :) 

Are there snapshots available that I can use so I can give it a try? a release next week is
ok for me :)  

> 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
>            Assignee: Pierre De Rop
>
> 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)

Mime
View raw message