felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre De Rop <pierre.de...@gmail.com>
Subject Re: Dependency Manager does not behave as expected
Date Wed, 16 Sep 2015 23:03:23 GMT
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.Felber@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-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message