Return-Path: X-Original-To: apmail-felix-dev-archive@www.apache.org Delivered-To: apmail-felix-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3AA4B180FF for ; Tue, 28 Apr 2015 09:21:07 +0000 (UTC) Received: (qmail 83786 invoked by uid 500); 28 Apr 2015 09:21:07 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 83682 invoked by uid 500); 28 Apr 2015 09:21:06 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 83411 invoked by uid 99); 28 Apr 2015 09:21:06 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Apr 2015 09:21:06 +0000 Date: Tue, 28 Apr 2015 09:21:06 +0000 (UTC) From: "Pierre De Rop (JIRA)" To: dev@felix.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FELIX-4869) Callbacks not invoked for dependencies that are added after the component is initialized MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FELIX-4869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14516709#comment-14516709 ] Pierre De Rop commented on FELIX-4869: -------------------------------------- I reproduced the problem, and will provide a patch today. > 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)