On Thu, Sep 17, 2015 at 6:29 AM, Hubert Felber <hubert.fel...@abacus.ch> wrote: > 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/felix/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Ā“t 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 > component > 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 = 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.class).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_FOR_REQUIRED > which is what I expected. The service will start as soon as the dependency is > resolved. > > > You should be able to see this with a breakpoint on > ComponentImpl#calculateNewState > 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 > ServiceDependency. > > Tested with DM 4.1.0 > > Thank you again > Hubert > > >>>> Pierre De Rop <pierre.de...@gmail.com> 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 add > 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 = createComponent() > .setInterface(toString(LoggingConfigService.class, > ManagedService.class), null) > .setImplementation(LoggingConfigServiceImpl.class) > > .add(createServiceDependency().setService(LoggingService.class).setRequired(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 workspace > -> 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, then > 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" message. > > 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 <hubert.fel...@abacus.ch> > 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 = dependencyManager.createComponent(); >> >> ServiceDependency serviceDependency = createServiceDependency(); >> serviceDependency.setService(LoggingServiceImpl.class); >> serviceDependency.setRequired(true); >> >> <<<< >> component.add(serviceDependency); // goes to >> ComponentImpl#calculateNewState() from here >> >>> >> component.setImplementation(LoggingConfigService.class); >> String[] classes = 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-unsubscr...@felix.apache.org >> For additional commands, e-mail: users-h...@felix.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@felix.apache.org > For additional commands, e-mail: users-h...@felix.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@felix.apache.org For additional commands, e-mail: users-h...@felix.apache.org