> On 13 Oct 2016, at 22:04, Ferry Huberts <maili...@hupie.com> wrote: > > Mandatory references are always injected before activate. > Optional references can be injected either before or after activate.
Well no that’s not exactly true. Static references — whether mandatory or optional — are always bound before activate. If optional then it’s possible for the reference to be bound to nothing (in this case the bind method will never be called). An optional-static reference *cannot* be injected after activate. That’s the definition of static. Dynamic references can be bound, unbound or re-bound at any time before, during or after activate. For example a mandatory-dynamic reference can be re-bound without deactivating a component if the service it is bound to goes away and there is a replacement service already available. Neil > > On 13/10/16 23:00, Daghan ACAY wrote: >> Hi all, >> >> I am trying to create a component that is instantiated by ConfigAdmin >> and uses multiple references to operate. Basically the component should >> instantiate through a factory configuration and use that configuration >> to set up its own @Reference s. You can see the code here: >> >> https://github.com/daghanacay/com.easyiot.device/blob/master/com.easyiot.LT100H.device.provider/src/com/easyiot/LT100H/device/provider/LT100HDeviceImpl.java >> >> All the mentioned @Reference ed components are instantiated by >> configuration as well, so at a given time the @Reference might not be >> available but my own component should still work. yet should the >> Reference available then it should be injected, basic 0-1 strategy. >> >> Problem I am facing with the current form of the code is that, the >> @Reference injection is happening before the @Activate method is called. >> This leads to NPE in the @Reference method due to null configuration. Is >> it possible to make this code work such that config is provided to the >> component before the dependency injection? >> >> I have tried annotating the class fields and set them "volatile". I even >> make them a list and use the class fields in the activate method this >> time the class fields were null due to 0-1 strategy. so I end up with >> annotating the methods. >> >> I might have designed this all wrong, so any help simple or fundamental >> is appreciated. >> >> Regards >> >> -Daghan >> >> Sent by MailWise <http://www.mail-wise.com/installation/2 >> <http://www.mail-wise.com/installation/2>> – See your >> emails as clean, short chats. >> >> >> >> _______________________________________________ >> OSGi Developer Mail List >> osgi-dev@mail.osgi.org <mailto:osgi-dev@mail.osgi.org> >> https://mail.osgi.org/mailman/listinfo/osgi-dev >> <https://mail.osgi.org/mailman/listinfo/osgi-dev> >> > > -- > Ferry Huberts > _______________________________________________ > OSGi Developer Mail List > osgi-dev@mail.osgi.org <mailto:osgi-dev@mail.osgi.org> > https://mail.osgi.org/mailman/listinfo/osgi-dev > <https://mail.osgi.org/mailman/listinfo/osgi-dev>
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev