Hi Neil,

Thanks a lot for those useful informations. I'll probably implement it with
the technique you described.

Best regards,
Nicolas







On Mon, Nov 28, 2016 at 12:44 PM, Neil Bartlett <[email protected]>
wrote:

>
> > On 28 Nov 2016, at 11:26, Nicolas Brasey <[email protected]>
> wrote:
> >
> > Hi Neil,
> >
> > Thanks for the quick reply.
> >
> > okay I see, I misinterpreted the specs then.
> >
> > In my specific case, I need to make sure the static reference is there
> > *before* the dynamic ones. What is the best patterns to ensure that ? Do
> I
> > need to write synchonization code inside my component for that, or do you
> > know a cleaner way with declarative services ?
>
>
> The specs do not make that guarantee, so you need to write your code in
> such a way that it doesn’t matter what order the references are processed.
>
> Typically this means deferring whatever action you take based on those
> references being bound. For example, both the static and the dynamic bind
> methods can call into a single “updateBindings” method, which checks
> whether everything is in place. That method will certainly need to be
> thread-safe, and synchronization is one way (though not the only way) to
> achieve that.
>
> Regards,
> Neil
>
>
> >
> > Thanks!
> >
> > Nicolas
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Mon, Nov 28, 2016 at 12:13 PM, Neil Bartlett <[email protected]>
> > wrote:
> >
> >>
> >>> On 28 Nov 2016, at 11:09, Nicolas Brasey <[email protected]>
> >> wrote:
> >>>
> >>> Hi,
> >>>
> >>> I have a bind order issue with a component that has :
> >>>
> >>> 1) A static reference specified with annotation @Reference on the
> private
> >>> field
> >>> 2) A dynamic multiple reference specificed with annotation on a method
> >>>
> >>> The static reference is not bound before the dynamic ones.
> >>
> >>
> >> That is not required. Dynamic references can be bound, unbound or
> replaced
> >> at any time… even potentially *while* the static references are being
> >> bound, or while the activate is executing.
> >>
> >>
> >>>
> >>> The code looks like this:
> >>>
> >>> @Component(immediate = true)
> >>> public class MyServiceImpl implements MyService {
> >>>
> >>>   @Reference
> >>>   private AclService aclService;
> >>>
> >>>   @Reference(
> >>>           cardinality = ReferenceCardinality.MULTIPLE,
> >>>           policy = ReferencePolicy.DYNAMIC
> >>>   )
> >>>   public void add(StateMachine stateMachine) {
> >>>      ....
> >>>       ....
> >>>   }
> >>>
> >>>
> >>> According to the Declarative Service specifications, the static
> >> references
> >>> should always be injected before the activate method.
> >>
> >>
> >> That’s correct.
> >>
> >>
> >>>
> >>>
> >>> Does anyone have any idea what might be wrong ?
> >>
> >>
> >> It doesn’t sound like anything is going wrong.
> >>
> >> Regards,
> >> Neil
> >>
> >>
> >>>
> >>>
> >>> My env is Apache Karaf 4.0.5 with Felix SCR 2.0.2
> >>>
> >>>
> >>> Thanks for you help!
> >>>
> >>> Nicolas
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to