osgi cdi integration specification
play

OSGi CDI Integration Specification Raymond Aug - Sr. Soware - PowerPoint PPT Presentation

OSGi CDI Integration Specification Raymond Aug - Sr. Soware Architect @rotty3000 Why CDI In OSGi? Reduce developer friction Important Java specification Benefit from extensive feature set @rotty3000 But Declarative Services (DS)?


  1. OSGi CDI Integration Specification Raymond Augé - Sr. So�ware Architect @rotty3000

  2. Why CDI In OSGi? Reduce developer friction Important Java specification Benefit from extensive feature set @rotty3000

  3. But Declarative Services (DS)? Liferay loves DS! 99% of all Liferay bundles (jars) are DS and the vast majority will remain DS forever. @rotty3000

  4. WHY use anything else? by design DS is... ultra light weight, DS annotations are syntax sugar, CLASS retention and processed at build time, runtime overhead is extremely low, does not provide an integration SPI, does not provide intra-bundle dependency injection. @rotty3000

  5. CDI as part of its feature set, is... extensible (CDI has a full fledged SPI) annotation processing engine intra-bundle dependency injection Custom annotations! @rotty3000

  6. CDI allows for... completely internal wiring. @rotty3000

  7. DS - Internal wiring: new 1 @Component 2 public class FooImpl { 3 private Pojo pojo; 4 5 public FooImpl() { 6 pojo = new PojoImpl(); 7 } 8 } @rotty3000

  8. CDI - Internal wiring: @Inject 1 public class FooImpl { 2 private Pojo pojo; 3 4 @Inject 5 public FooImpl(Pojo pojo) { 6 this.pojo = pojo; 7 } 8 } @rotty3000

  9. DS - Services: singleton 1 @Component 2 public class FooImpl implements Function { 3 ... 4 } @rotty3000

  10. OSGi-CDI - Services: singleton 1 @Service 2 public class FooImpl implements Function { 3 ... 4 } @rotty3000

  11. DS - Services: prototype 1 @Component(scope = PROTOTYPE) 2 public class FooImpl implements Function { 3 ... 4 } @rotty3000

  12. OSGi-CDI - Services: prototype 1 @Service @ServiceInstance(PROTOTYPE) 2 public class FooImpl implements Function { 3 ... 4 } @rotty3000

  13. DS - References 1 @Reference 2 Pojo pojo; @rotty3000

  14. OSGi-CDI - References 1 @Inject @Reference 2 Pojo pojo; @rotty3000

  15. DS - Cardinality: mandatory 1 @Reference 2 Pojo pojo; @rotty3000

  16. OSGi-CDI - Cardinality: mandatory 1 @Inject @Reference 2 Pojo pojo; @rotty3000

  17. DS - Cardinality: optional 1 @Reference(cardinality = OPTIONAL) 2 Pojo pojo; @rotty3000

  18. OSGi-CDI - Cardinality: optional 1 @Inject @Reference 2 Optional<Pojo> pojo; @rotty3000

  19. DS - Cardinality: multiple 1 @Reference 2 List<Pojo> pojos; @rotty3000

  20. OSGi-CDI - Cardinality: multiple 1 @Inject @Reference 2 List<Pojo> pojos; @rotty3000

  21. DS - Cardinality: at least one (or n) 1 @Reference(cardinality = AT_LEAST_ONE) 2 List<Pojo> pojos; @rotty3000

  22. OSGi-CDI - Cardinality: at least one (or n) 1 @Inject @Reference @MinimumCardinality(1) 2 List<Pojo> pojos; @rotty3000

  23. DS - Reference Policy: greedy 1 @Reference(policyOption = GREEDY) 2 Pojo pojo; @rotty3000

  24. OSGi-CDI - Reference Policy: reluctant 1 @Inject @Reference @Reluctant 2 Pojo pojo; @rotty3000

  25. DS - Dynamic: mandatory 1 @Reference(policy = DYNAMIC) 2 volatile Pojo pojo; @rotty3000

  26. OSGi-CDI - Dynamic: mandatory 1 @Inject @Reference 2 Provider<Pojo> pojo; @rotty3000

  27. DS - Dynamic: multiple 1 @Reference(policy = DYNAMIC) 2 volatile List<Pojo> pojos; @rotty3000

  28. OSGi-CDI - Dynamic: multiple 1 @Inject @Reference 2 Provider<List<Pojo>> pojos; @rotty3000

  29. DS - Dynamic: optional 1 @Reference(policy = DYNAMIC, cardinality = OPTIONAL) 2 volatile Pojo pojo; @rotty3000

  30. OSGi-CDI - Dynamic: optional 1 @Inject @Reference 2 Provider<Optional<Pojo>> pojo; @rotty3000

  31. DS - OSGi Logger 1 @Reference(service = LoggerFactory.class) 2 Logger logger; @rotty3000

  32. OSGi-CDI - OSGi Logger 1 @Inject 2 Logger logger; @rotty3000

  33. DS - Configuration 1 @Activate 2 Map<String, Object> props; @rotty3000

  34. OSGi-CDI - Configuration 1 @Inject @ComponentProperties 2 Map<String, Object> props; @rotty3000

  35. Configuration Types 1 @Retention(RUNTIME) 2 @BeanPropertyType // OSGi-CDI 3 @ComponentPropertyType // DS 4 public @interface Config { 5 String hostname() default "localhost"; 6 int port() default 8080; 7 Config.Protocol protocol() default Config.Protocol.https; 8 9 public enum Protocol {http, https} 1 } @rotty3000

  36. DS - Configuration: typed 1 @Activate 2 Config config; @rotty3000

  37. OSGi-CDI - Configuration: typed 1 @Inject @ComponentProperties 2 Config config; @rotty3000

  38. DS - Component 1 @Component( 2 configurationPid = {"foo", "bar"}, 3 configurationPolicy = REQUIRE) 4 public class FooImpl { 5 ... 6 } @rotty3000

  39. OSGi-CDI - Single Component 1 @SingleComponent 2 @PID("foo") 3 @PID(value = "bar", policy = REQUIRED) 4 public class FooImpl { 5 ... 6 } @rotty3000

  40. OSGi-CDI - Factory Component 1 @FactoryComponent("foo") 2 @PID("bar") 3 public class FooImpl { 4 ... 5 } @rotty3000

  41. The OSGi-CDI Spec https://osgi.org/specification/osgi.enterprise/7.0.0/service.cdi.html @rotty3000

  42. The OSGi-CDI Reference Implementation https://github.com/apache/aries-cdi @rotty3000

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend