Hello Philipp;

On Wed, Oct 1, 2014 at 9:34 AM, Bulu <b...@romandie.com> wrote:

> Hello Pierre
> Thanks. Indeed my additional conditions were not added atomically.
>
> Should the setInstanceBound(true) be called on each dependency separately
> before being added to the list?
> Does setInstanceBound() make only sense on adapters or should I call it
> for all type of components when dependencies are added in init()? (the
> JavaDoc " Sets this dependency to be instance bound or not." is not so
> helpful).
>
> Is it only for adapters that additional conditions must be added
> atomically or for all type of components?
>
>
for all types of components (and for all required dependencies defined
within the init method); and you can then add each dependency in the list
safely; then after, you can add the list atomically, using
component.add(List dependencies) method.

For instance:

class MyComponent {
        void init(Component c) {
            DependencyManager dm = c.getDependencyManager();
            List l = new ArrayList();

            l.add(dm.createServiceDependency()
                     .setInstanceBound(true)
                     .setService(OtherService1.class, "(name=xxx)")
                     .setRequired(true));

            l.add(dm.createServiceDependency()
                     .setInstanceBound(true)
                     .setService(OtherService2.class, "(name=yyy)")
                     .setRequired(true));

            // atomically adds the list to our component
            c.add(l);
        }


To clarify, in dm 3.2.0, when you add some extra-dependencies from your
init() method, the setInstanceBound(true) method ensures that when your
component is being created (because it has been injected with all initial
required dependencies defined from the Activator), then it then won't be
immediately destroyed if the dynamically added dependencies from the init
method are not yet available.

But in the DM 4.0.0, using the setInstanceBound method for all init's
dependencies has been relaxed it is not necessary to use it anymore. But we
also changed the add method, using varargs list of dependencies, so you can
define multiple extra-dependencies without using a List:

// Using DM 4.0

class MyComponent {
        void init(Component component) {
            DependencyManager dm = c.getDependencyManager();

            // Atomically adds two dependencies in our component.

            component.add(
                 dm.createServiceDependency()
                     .setInstanceBound(true)
                     .setService(OtherService1.class, "(name=xxx)")
                     .setRequired(true),
                 dm.createServiceDependency()
                     .setInstanceBound(true)
                     .setService(OtherService2.class, "(name=yyy)")
                     .setRequired(true))
            );
        }
}

kind regards;
/pierre

Regards Philipp
>
>
>
> On 30.09.2014 23:03, Pierre De Rop wrote:
>
>> Hello Philipp,
>>
>> I don't know if this may help, but if you are using DM 3.2.0, please don't
>> forget that if you are declaring some extra-service dependencies from your
>> init() methods (in your adapter for example), then you have to declare
>> them
>> as "instance bound" dependencies: you have to make a call to the
>> setInstanceBound(true) method on the extra dependency declared from your
>> init methods.
>>
>> And also, if you have more than one dependency to add in your init()
>> method, then you should add them atomically using a list of Dependencies,
>> passed to the dm.add(List dependencies) method.
>>
>> You can take a look at [1] for an example.
>>
>> kind regards;
>> /Pierre
>>
>> [1]
>> http://svn.apache.org/viewvc/felix/trunk/dependencymanager/
>> test/src/test/java/org/apache/felix/dm/test/integration/api/
>> MultipleExtraDependenciesTest.java?revision=1532440&view=markup
>>
>> On Tue, Sep 30, 2014 at 7:46 PM, Bulu <b...@romandie.com> wrote:
>>
>>  Obviously it works great on the small example... :-)
>>> Ergo: the problem is in my code or more complex than explained...
>>>
>>>
>>> On 30.09.2014 19:14, Marcel Offermans wrote:
>>>
>>>  On 30 Sep 2014, at 9:50 am, Bulu <b...@romandie.com> wrote:
>>>>
>>>>   Hi all
>>>>
>>>>> Using DM I declare adapter services like this
>>>>>
>>>>> // without filter
>>>>> mgr.add(createAdapterService(SomeClass.class,null)
>>>>>                  .setImplementation(...)
>>>>>                  .setCallbacks(...));
>>>>>
>>>>> // with filter
>>>>> String someFilter = ...
>>>>> mgr.add(createAdapterService(OtherClass.class, someFilter))
>>>>>                  .setImplementation(...)
>>>>>                  .setCallbacks(...));
>>>>>
>>>>> I notice that, if I first start this adapter bundle and later the
>>>>> SomeClass and OtherClass appear, all get picked up correctly and
>>>>> forwarded
>>>>> to the callbacks.
>>>>>
>>>>> However, if first the SomeClass and OtherClass service are present and
>>>>> later the Adapter gets started, it only picks up the ones without
>>>>> filter
>>>>> (in the example the "SomeClass", but not the "OtherClass" services).
>>>>>
>>>>> I know the filter is correct, as it does work when done in the right
>>>>> order. The services are the same in both cases.
>>>>>
>>>>> Has anybody else noticed this? Is the problem in my code?
>>>>>
>>>>>  Not sure, could you provide a small working example or test?
>>>>
>>>> Greetings, Marcel
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>>
>

Reply via email to