felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pierre De Rop (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FELIX-5320) Dependency Manager: adapter service propagates adaptee properties *after* the init (and start) callbacks are called
Date Wed, 10 Aug 2016 16:01:20 GMT

    [ https://issues.apache.org/jira/browse/FELIX-5320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15415489#comment-15415489
] 

Pierre De Rop commented on FELIX-5320:
--------------------------------------

Hi Andrea (sorry for late response, I'm getting back from vacations).

The "init" and "start" callbacks are not meant to be used in order to catch service properties
change events.
Let me clarify:

The "init" callback can be used by any component to add dynamic dependencies: so, for example,
you first declare some dependencies from the Activator, and once all dependencies are injected
in the component, then the component is invoked in its "init" callback (if it defines such
callback). So, this callback can then inspect already injected dependencies, and possibly
add more dependencies.

Then once all dependencies added from the init() callback are injected, then the "start" callback
is invoked. If no "init" callback is defined, then the "start" callback simply indicates that
all dependencies declared from the Activator have been injected.

Example code:

{code}
public class Activator extends DependencyActivatorBase {
    @Override
    public void init(BundleContext ctx, DependencyManager m) throws Exception {
        m.add(createComponent()
            .setImplementation(Foo.class)
            .add(createConfigurationDependency().setPid(Foo.class.getName()))
            .add(createServiceDependency().setService(LogService.class).setRequired(true)));
   }
}

public class Foo {
    volatile LogService log;
    volatile SomeOtherService otherService;

    void updated(Dictionary conf) {
        String xml = conf.get("some.properties);
        // parse xml
    }

   void init(Component c) {
         DependencyManager dm = c.getDependencyManager();
         String filter = ... // create a filter from xml configuration (for example)
         c.add(dm.createServiceDependency().setService(SomeOtherService.class, filter).setRequired(true));
   }

   void start() {
      // at this point, all dependencies declared from Activator are injected, as well as
the other dependencies declared from the init() method.
   }
{code}

Now, getting back from your original question: I think that if an adaptee service properties
are changed, then they are propagated to the adapter service itself. So, any service depending
on the Adapter service will then be invoked in its "changed" callback, if declared.

Such scenario is verified in the following DM integration test: [1]. In this test, you have
S1 component, S2Adapter which adapts S1 to S2 service, and S3 which depends on S2.

So, S3 depends on S2 like this:

{code}
        Component s3 = m.createComponent()
                .setImplementation(new S3(e))
                .add(m.createServiceDependency()
                     .setService(S2.class)
                     .setRequired(true)
                     .setCallbacks("add", "change", null));
{code}

and when S1 service properties are changed, then it is propagated to the S1Adapter service
properties, and finally "S3.change(Map properties, S2 s2)" is invoked.

let me know if the integration test code does what you would like to do, or may be I have
missing something ?

[1] http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/AdapterWithPropagationTest.java?revision=1663056&view=markup




> Dependency Manager: adapter service propagates adaptee properties *after* the init (and
start) callbacks are called
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-5320
>                 URL: https://issues.apache.org/jira/browse/FELIX-5320
>             Project: Felix
>          Issue Type: Bug
>          Components: Dependency Manager
>    Affects Versions: org.apache.felix.dependencymanager-r8
>            Reporter: Andrea Leofreddi
>
> In an adapter service, created using the createAdapterService method of DependencyManager
class, one would expect to find the adaptee's properties being propagated to the adapter service
itself, as stated in the documentation (http://felix.apache.org/documentation/subprojects/apache-felix-dependency-manager/reference/component-adapter.html).
> Instead no propagation happens, and both init and start methods won't see any propagated
properties.
> After investigating I've found that propagations indeed happens (via AdapterServiceImpl's
propagateAdapteeProperties) only after the callbacks are called.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message