In your case simply inject the ttnMqttClient in the @Reference and do the subscribe in @Activate when you get the config and the unsubscribe in @Deactivate.
Christian 2016-10-13 23:00 GMT+02:00 Daghan ACAY <daghana...@hotmail.com>: > 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> – See your > emails as clean, short chats. > > _______________________________________________ > OSGi Developer Mail List > osgi-dev@mail.osgi.org > https://mail.osgi.org/mailman/listinfo/osgi-dev > -- -- Christian Schneider http://www.liquid-reality.de <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.liquid-reality.de> Open Source Architect http://www.talend.com <https://owa.talend.com/owa/redir.aspx?C=3aa4083e0c744ae1ba52bd062c5a7e46&URL=http%3a%2f%2fwww.talend.com>
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev