Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RFC 193: OSGi CDI

RFC 193: OSGi CDI

CDI (Context and Dependency Injection) is the standardised dependency injection model in Java EE 6. The CDI-OSGi specification brings CDI to OSGi to publish and consume OSGi services.

The CDI-OSGi specification (RFC-193) introduces a way to use CDI in OSGi. This brings the ease-of-use of CDI to OSGi, and more importantly, brings the OSGi and Java EE worlds closer together. It allows seamless integration between standard CDI code and the OSGi service model. Other features include sending and observing EventAdmin events using CDI events. In this presentation you will get an overview of the possibilities of this new specification, including some in-depth discussion of difficulties in integrating the OSGi service lifecycle with CDI.

The speaker is a member of the OSGi Enterprise Expert Group and works on the CDI-OSGi specification.

Paul Bakker

March 26, 2013
Tweet

More Decks by Paul Bakker

Other Decks in Programming

Transcript

  1. In CDI every class that is injected somewhere is a

    managed Why the @OSGiComponent qualifier? We can’t know this up front in an OSGi application
  2. @RequestScoped MyService @RequestScoped BeanA @RequestScoped BeanB @Inject @Inject Request 1

    @RequestScoped MyService @RequestScoped BeanA @Inject Request 2 Scopes in CDI
  3. Default scope Request Conversation Session Singleton Scopes in OSGi CDI

    OSGi services do not support scopes However, RFC 195 might be helpful Prototype Service Scope
  4. @Inject OSGi Services OSGi Service Registry CDI BeanManager OSGi Service

    CDI bean Registers Lookup @Inject @OSGiService
  5. Null object pattern If MyService is not available, a null

    proxy is injected Injection happens every time MyService is registered / deregistered
  6. Required dependencies B A @Inject @OSGiService(required = true) C @Inject

    @OSGiService(required = true) Dependency graph
  7. Required dependencies B A @Inject @OSGiService(required = true) C @Inject

    @OSGiService(required = true) If C is deregistered, so are B and A
  8. Required dependencies B A @Inject @OSGiService(required = true) C @Inject

    @OSGiService(required = true) If C is deregistered, so are B and A
  9. Required dependencies B A @Inject @OSGiService(required = true) C @Inject

    @OSGiService(required = true) If C becomes available, so are B and A
  10. Required dependencies B A @Inject @OSGiService(required = true) C @Inject

    @OSGiService(required = true) If C becomes available, so are B and A
  11. Required dependencies If C is deregistered, B and A don’t

    care B A @Inject @OSGiService(required = true) C @Inject @OSGiService(required = false) C is not required...
  12. Required dependencies If C is deregistered, B and A don’t

    care B A @Inject @OSGiService(required = true) C @Inject @OSGiService(required = false) C is not required...
  13. Required dependencies If C is deregistered, B and A don’t

    care B is not required, C is B A @Inject @OSGiService(required = false) C @Inject @OSGiService(required = true)
  14. Required dependencies If C is deregistered, B and A don’t

    care B is not required, C is B A @Inject @OSGiService(required = false) C @Inject @OSGiService(required = true)
  15. Event admin EventAdmin CDI-OSGi bridge Observer EventAdmin EventHandler CDI bean

    Send EventAdmin event using CDI events Notify Publish @Inject @EventAdmin Event event
  16. Event admin CDI-OSGi bridge Observer EventAdmin CDI event listener EventAdmin

    producer Listener to EventAdmin events using CDI observers @Observes @EventAdmin Publish Notify