Return-Path: X-Original-To: apmail-felix-users-archive@minotaur.apache.org Delivered-To: apmail-felix-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 08B00178CA for ; Thu, 17 Sep 2015 10:39:08 +0000 (UTC) Received: (qmail 50302 invoked by uid 500); 17 Sep 2015 10:39:07 -0000 Delivered-To: apmail-felix-users-archive@felix.apache.org Received: (qmail 50236 invoked by uid 500); 17 Sep 2015 10:39:07 -0000 Mailing-List: contact users-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@felix.apache.org Delivered-To: mailing list users@felix.apache.org Received: (qmail 50217 invoked by uid 99); 17 Sep 2015 10:39:07 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Sep 2015 10:39:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id DA79E1A218B for ; Thu, 17 Sep 2015 10:39:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.7 X-Spam-Level: X-Spam-Status: No, score=0.7 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, KAM_ASCII_DIVIDERS=0.8, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=basistech.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id giumla_UTOSH for ; Thu, 17 Sep 2015 10:39:01 +0000 (UTC) Received: from mail-ob0-f182.google.com (mail-ob0-f182.google.com [209.85.214.182]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 0D57A4458A for ; Thu, 17 Sep 2015 10:39:01 +0000 (UTC) Received: by obbda8 with SMTP id da8so10007979obb.1 for ; Thu, 17 Sep 2015 03:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basistech.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=b6BP+3eudAYvJJxWuD4pl+I6jmptiaOTVtW+Ge5Ibvk=; b=xKSjh/kdAcHJ/Vs7e1GoDzlkP5HSKu+Citp7HGkhC+qFLLndTQXUiZI2aIL9E/d7a+ Fsyav/vgvPBm6D6bzwAL6Yz41pFG6onj5jNNF5hNtgPMStSymllVJRNEM6ysqx+raMVa 8QW5NBTGUxc3nftYcH+GLutdk5MgyslykILYE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=b6BP+3eudAYvJJxWuD4pl+I6jmptiaOTVtW+Ge5Ibvk=; b=Lv6/0g6QH/tOTxyhR8U3gualyKF5oTLLVKcoUbOkJn8X6S8x5MHLQnL4JlNOHHpko+ e9s3nMXrpjl3v42Vknk2hQExHxczSNt6rPA5jhj6zscPGzjcsO/PeyQFbejRCB/E/TXy by5ywgb9l9rzG8BukSrMu8FhzXV3ngXmIWH4mhpV5k9oIh8WA8m3PsOPPY4kxvVIbRoD VPuGfhp35Nc+BxMMQkAu+h9ZW2uzovp+8oVcmg+ujzwPOnf+8HRJa+l86KQPuLFtzRzD iIY7U/ZaLao5htBZX1pr0LLUWo/995xA9C9Dym5xNZC4UixB/fV5qacWe6mNhLWq96WH h/Mw== X-Gm-Message-State: ALoCoQkslaJ2Se41OIIMbbF15YS+BhmgPaKe7/oe/G37G8mMUtrJTFdRQy+p8/kjknjr8trGer40 MIME-Version: 1.0 X-Received: by 10.182.158.72 with SMTP id ws8mr27295075obb.54.1442486340426; Thu, 17 Sep 2015 03:39:00 -0700 (PDT) Received: by 10.76.170.35 with HTTP; Thu, 17 Sep 2015 03:39:00 -0700 (PDT) In-Reply-To: <55FAB229020000170009D74D@mail.abacus.ch> References: <55F9F087020000170009D68C@mail.abacus.ch> <55FAB229020000170009D74D@mail.abacus.ch> Date: Thu, 17 Sep 2015 06:39:00 -0400 Message-ID: Subject: Re: Dependency Manager does not behave as expected From: Benson Margulies To: users@felix.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Sep 17, 2015 at 6:29 AM, Hubert Felber wr= ote: > Hi Pierre, > > Thank you for all your efforts! > > unfortunately I could not check it out using svn. > I get a "Redirect cycle detected for URL 'http://svn.apache.org/viewvc/fe= lix/sandbox/pderop/dependencymanager.test'" > on both linux and windows you don't checkout through a viewvc link. That's just for browsing. https://svn.apache.org/repos/asf/felix/sandbox/... > > > And I don=C2=B4t have Eclipse installed since we work with IntelliJ Idea.= ... > > nevertheless I was able to load the relevant files via http and try them. > > I made the same observation: as soon as a add a ServiceDependency > then ComponentImpl#startDependencies() is called -- before I added the co= mponent > to DM. > Of course the service cannot be started then, the state remains inactive,= but DM tries to do so and > maybe can do this, before I finished the component configuration. > > I reduced the snippet: > > Component comp =3D createComponent() > // .setInterface(toString(LoggingConfService.class, > // ManagedService.class), null) > // .setImplementation(LoggingConfigServiceImpl.class) > > // after this, DM tries to start the service -> state remains INACTIVE > > .add(createServiceDependency().setService(LoggingService.clas= s).setRequired(true)); > > // before I add the component to DM > > System.out.println("Adding component to dependency manager"); > dependencyManager.add(comp); > > > after this, DM tries to start the service agein -> state now is WAITING_F= OR_REQUIRED > which is what I expected. The service will start as soon as the dependenc= y is resolved. > > > You should be able to see this with a breakpoint on ComponentImpl#calcula= teNewState > after adding the service dependency. > In my opinion DM should not try to start the service before I finally add= the component > to DM, but now it tries to start the service, as soon as add a ServiceDep= endency. > > Tested with DM 4.1.0 > > Thank you again > Hubert > > >>>> Pierre De Rop 17.09.2015 01:03 >>> > Hi Hubert; > > I don't understand how this is possible, because a DM component initial > state is Inactive, and remains in this state until you add it to a > DependencyManager object. > > So, your service implementation can not be called in start() before you a= dd > the component to the dm object. > > Ok, in order to go ahead, I have made a (temporary) commit of a > dependencymanager.test project in my sandbox (see [1]). > > So, can you please take a look at it ? I tried to follow your samples by > creating two bundles: > > dependencymanager.test.log.jar -> contains the LoggingService + its > Activator > dependencymanager.test.logconfig.jar -> contains the LoggingConfigService > that depends on the LoggingService. > > Here is the Activator for the dependencymanager.test.logconfig.jar bundle > (I made it a bit more compact, by reusing the methods available from the > DependencyActivatorBase) > > public class Activator extends DependencyActivatorBase { > > @Override > public void init(BundleContext ctx, DependencyManager dm) throws > Exception { > Component comp =3D createComponent() > .setInterface(toString(LoggingConfigService.class, > ManagedService.class), null) > .setImplementation(LoggingConfigServiceImpl.class) > > .add(createServiceDependency().setService(LoggingService.class).setRequir= ed(true)); > > System.out.println("Adding component to dependency manager"); > dm.add(comp); > } > > // Helper used to convert an array of classes to an array of class > strings > String[] toString(Class ... services) { > return Stream.of(services).map(c -> > c.getName()).toArray(String[]::new); > } > > } > > > So, can you install an Eclipse mars + java8 + latest bndtool (Use the > dependencymanager.test directory as the eclipse workspace directory). > > Then open the bndtools perspective. > > Then click on File -> Import -> General -> Existing Projects into workspa= ce > -> Browse -> Ok -> Finish > > Then click on the dependencymanager.test/bnd.bnd file -> Run tab -> Run > OSGi. > > You will then see in the console: > > Adding component to dependency manager > LoggingConfigServiceImpl is starting. > > So, the "Adding component to dependency manager" message is displayed, th= en > after, when the component is added to the DependencyManager "dm" object, > then when the component is injected with the LoggingService, it is then > started and you see the log "LoggingConfigServiceImpl is starting" messag= e. > > You can also type "dm" shell command in the console: > > dm > > [8] dependencymanager.test.logconfig > [0] dependencymanager.test.logconf.LoggingConfigService, > org.osgi.service.cm.ManagedService registered > dependencymanager.test.log.LoggingService service required available > [9] dependencymanager.test.log > [1] dependencymanager.test.log.LoggingService registered > > > So, maybe if you try to play with this sample, you will then be able to > figure out what is going wrong in your own project ? > > hope this helps; > /Pierre > > [1] > http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.test/ > > > > > > > On Wed, Sep 16, 2015 at 10:43 PM, Hubert Felber > wrote: > >> Hi, >> >> as soon as I add a ServiceDependency to my component, Felix tries to >> start the service -- before I set the implementation and before I add >> the the component to the DM. >> >> I would expect, it waits until I finally add the component to the DM? >> >> Am I doing something wrong? >> >> Thank you >> Hubert >> >> public void init(BundleContext bundleContext, DependencyManager >> dependencyManager) throws Exception { >> Component component =3D dependencyManager.createComponent(); >> >> ServiceDependency serviceDependency =3D createServiceDependency(); >> serviceDependency.setService(LoggingServiceImpl.class); >> serviceDependency.setRequired(true); >> >> <<<< >> component.add(serviceDependency); // goes to >> ComponentImpl#calculateNewState() from here >> >>> >> component.setImplementation(LoggingConfigService.class); >> String[] classes =3D new >> String[]{LoggingConfigService.class.getName(), >> ManagedService.class.getName()}; >> >> component.setInterface(classes, properties); >> dependencyManager.add(component); // thought it should go >> to calculateNewState() from here ?? >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org >> For additional commands, e-mail: users-help@felix.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org > For additional commands, e-mail: users-help@felix.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@felix.apache.org For additional commands, e-mail: users-help@felix.apache.org