Return-Path: X-Original-To: apmail-karaf-dev-archive@minotaur.apache.org Delivered-To: apmail-karaf-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 07B6F18270 for ; Mon, 11 Jan 2016 08:35:36 +0000 (UTC) Received: (qmail 70049 invoked by uid 500); 11 Jan 2016 08:35:35 -0000 Delivered-To: apmail-karaf-dev-archive@karaf.apache.org Received: (qmail 70004 invoked by uid 500); 11 Jan 2016 08:35:35 -0000 Mailing-List: contact dev-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list dev@karaf.apache.org Received: (qmail 69993 invoked by uid 99); 11 Jan 2016 08:35:35 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jan 2016 08:35:35 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 08C32C301E for ; Mon, 11 Jan 2016 08:35:35 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.02 X-Spam-Level: X-Spam-Status: No, score=-0.02 tagged_above=-999 required=6.31 tests=[RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id ordewY7uKUAx for ; Mon, 11 Jan 2016 08:35:24 +0000 (UTC) Received: from 8.mo7.mail-out.ovh.net (8.mo7.mail-out.ovh.net [46.105.77.114]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 293E543BC9 for ; Mon, 11 Jan 2016 08:35:24 +0000 (UTC) Received: from mail325.ha.ovh.net (gw6.ovh.net [213.251.189.206]) by mo7.mail-out.ovh.net (Postfix) with ESMTP id B7A21FF890B for ; Mon, 11 Jan 2016 09:35:17 +0100 (CET) Received: from RCM-78.199.223.181 (localhost [127.0.0.1]) by mail325.ha.ovh.net (Postfix) with ESMTPA id A527A280076 for ; Mon, 11 Jan 2016 09:35:17 +0100 (CET) Received: from qtf31-1-78-199-223-181.fbx.proxad.net ([78.199.223.181]) by ssl0.ovh.net with HTTP (HTTP/1.1 POST); Mon, 11 Jan 2016 09:35:17 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 11 Jan 2016 09:35:17 +0100 From: ben@petinou.fr To: dev@karaf.apache.org Subject: How to manage several service instances with declarative services? Message-ID: <86ce97d48759d7f266072e86986f0cf3@petinou.fr> X-Sender: ben@petinou.fr User-Agent: Roundcube Webmail/1.1.3 X-Originating-IP: 78.199.223.181 X-Webmail-UserID: ben@petinou.fr X-Ovh-Tracer-Id: 7585469148811894762 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeekiedrkedtgdduvdduucetufdoteggodftvfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecu Hi everyone! I asked a question on stackoverflow regarding the use of Declarative Services in Karaf to manage multiple instances of a service, provided by different implementations of such a service. The question is explained in details here: http://stackoverflow.com/questions/34706041/how-to-manage-several-service-instances-in-declarative-services I received and answer telling me that using the @reference annotation on the list storing the services would solve my problem. For this, I would need to use DS 1.3. I thus asked on Karaf users mailing list what was the version of Felix SCR provided with Karaf 4.0.3 (http://mail-archives.apache.org/mod_mbox/karaf-user/201601.mbox/%3C8dbfa59508d5769609e2c78c0210c7aa%40petinou.fr%3E) and was told it was Felix SCR 2.0.2, which supports DS 1.3. So far so good. I was also kindly advised to ask this kind of questions here. So here I am :-) Following the answer on stackoverflow, I tried to add the @reference annotation to my service list like this: @Reference(service = FileReader.class) private List availableServices = new ArrayList<>(); But it does not compile: FileReaderFactory.java:[37,5] annotation type not applicable to this kind of declaration My project has a dependency on: org.osgi org.osgi.compendium 5.0.0 provided which seems to be the latest version available. I thus tried the "older way" by using explicit bind/unbind methods like this: @Reference(service = FileReader.class, unbind = "removeService") public void addService(final FileReader serviceToAdd) { System.out.println("FileReaderFactory.addService"); availableServices.add(serviceToAdd); System.out.println(availableServices); } public void removeService(final FileReader serviceToRemove) { System.out.println("FileReaderFactory.removeService"); availableServices.remove(serviceToRemove); System.out.println(availableServices); } If I have two implementations available, say TxtFileReader and XmlFileReader, only the first one is added to the list. The status of the second service (using scr:detail command) is "null". What am I missing? Kind regards, Ben