0

I am newbie to osgi and it may be the reason of such simple question.

A have a osgi bundle. Inside I have service,activator and pojo. Instance of pojo I create in activator.

How can I pass the reference of pojo to service before anyone uses this service?

The only way that comes to my mind is to access service as a standard service and use default identifier for setter, but it's not so good solution. CDI is not used.

1 Answers1

0

Who creates the instance of the service? If your activator, then pass the POJO to your service directly. If Declatative Services create your service, have the POJO be accessible using static methods from the activator.

Tassos Bassoukos
  • 16,017
  • 2
  • 36
  • 40
  • Thank you for your time. Service is created by DS. Do you mean to do static methods in activator? –  Apr 08 '14 at 19:43
  • One way to do is is having a static method in the Activator, like in the singleton pattern. However, could the service perhaps handle the POJO's lifecycle? That could be a cleaner way to write it, but it does depend on the particulars of thw OJO lifecycle vs budle lifecycle vs Service lifecycle. – Tassos Bassoukos Apr 09 '14 at 05:05
  • Do you mean it's better to do static method in service? –  Apr 09 '14 at 05:11
  • Thank you for help. Just the last question - what is created first - service or activator? –  Apr 09 '14 at 05:18
  • I'll need to look into the specs; I think the Activator, as DS only starts services when the bundle is in the Active state; don't quote me on that :-D – Tassos Bassoukos Apr 09 '14 at 05:20