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

osgi cdi integration specification
SMART_READER_LITE
LIVE PREVIEW

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)?


slide-1
SLIDE 1

OSGi CDI Integration Specification

Raymond Augé - Sr. Soware Architect @rotty3000

slide-2
SLIDE 2

Why CDI In OSGi?

Reduce developer friction Important Java specification Benefit from extensive feature set @rotty3000

slide-3
SLIDE 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

slide-4
SLIDE 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

slide-5
SLIDE 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

slide-6
SLIDE 6

CDI

allows for... completely internal wiring. @rotty3000

slide-7
SLIDE 7

DS - Internal wiring: new

@rotty3000

@Component public class FooImpl { private Pojo pojo; public FooImpl() { pojo = new PojoImpl(); } } 1 2 3 4 5 6 7 8

slide-8
SLIDE 8

CDI - Internal wiring: @Inject

@rotty3000

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

slide-9
SLIDE 9

DS - Services: singleton

@rotty3000

@Component public class FooImpl implements Function { ... } 1 2 3 4

slide-10
SLIDE 10

OSGi-CDI - Services: singleton

@rotty3000

@Service public class FooImpl implements Function { ... } 1 2 3 4

slide-11
SLIDE 11

DS - Services: prototype

@rotty3000

@Component(scope = PROTOTYPE) public class FooImpl implements Function { ... } 1 2 3 4

slide-12
SLIDE 12

OSGi-CDI - Services: prototype

@rotty3000

@Service @ServiceInstance(PROTOTYPE) public class FooImpl implements Function { ... } 1 2 3 4

slide-13
SLIDE 13

DS - References

@rotty3000

@Reference Pojo pojo; 1 2

slide-14
SLIDE 14

OSGi-CDI - References

@rotty3000

@Inject @Reference Pojo pojo; 1 2

slide-15
SLIDE 15

DS - Cardinality: mandatory

@rotty3000

@Reference Pojo pojo; 1 2

slide-16
SLIDE 16

OSGi-CDI - Cardinality: mandatory

@rotty3000

@Inject @Reference Pojo pojo; 1 2

slide-17
SLIDE 17

DS - Cardinality: optional

@rotty3000

@Reference(cardinality = OPTIONAL) Pojo pojo; 1 2

slide-18
SLIDE 18

OSGi-CDI - Cardinality: optional

@rotty3000

@Inject @Reference Optional<Pojo> pojo; 1 2

slide-19
SLIDE 19

DS - Cardinality: multiple

@rotty3000

@Reference List<Pojo> pojos; 1 2

slide-20
SLIDE 20

OSGi-CDI - Cardinality: multiple

@rotty3000

@Inject @Reference List<Pojo> pojos; 1 2

slide-21
SLIDE 21

DS - Cardinality: at least one (or n)

@rotty3000

@Reference(cardinality = AT_LEAST_ONE) List<Pojo> pojos; 1 2

slide-22
SLIDE 22

OSGi-CDI - Cardinality: at least one (or n)

@rotty3000

@Inject @Reference @MinimumCardinality(1) List<Pojo> pojos; 1 2

slide-23
SLIDE 23

DS - Reference Policy: greedy

@rotty3000

@Reference(policyOption = GREEDY) Pojo pojo; 1 2

slide-24
SLIDE 24

OSGi-CDI - Reference Policy: reluctant

@rotty3000

@Inject @Reference @Reluctant Pojo pojo; 1 2

slide-25
SLIDE 25

DS - Dynamic: mandatory

@rotty3000

@Reference(policy = DYNAMIC) volatile Pojo pojo; 1 2

slide-26
SLIDE 26

OSGi-CDI - Dynamic: mandatory

@rotty3000

@Inject @Reference Provider<Pojo> pojo; 1 2

slide-27
SLIDE 27

DS - Dynamic: multiple

@rotty3000

@Reference(policy = DYNAMIC) volatile List<Pojo> pojos; 1 2

slide-28
SLIDE 28

OSGi-CDI - Dynamic: multiple

@rotty3000

@Inject @Reference Provider<List<Pojo>> pojos; 1 2

slide-29
SLIDE 29

DS - Dynamic: optional

@rotty3000

@Reference(policy = DYNAMIC, cardinality = OPTIONAL) volatile Pojo pojo; 1 2

slide-30
SLIDE 30

OSGi-CDI - Dynamic: optional

@rotty3000

@Inject @Reference Provider<Optional<Pojo>> pojo; 1 2

slide-31
SLIDE 31

DS - OSGi Logger

@rotty3000

@Reference(service = LoggerFactory.class) Logger logger; 1 2

slide-32
SLIDE 32

OSGi-CDI - OSGi Logger

@rotty3000

@Inject Logger logger; 1 2

slide-33
SLIDE 33

DS - Configuration

@rotty3000

@Activate Map<String, Object> props; 1 2

slide-34
SLIDE 34

OSGi-CDI - Configuration

@rotty3000

@Inject @ComponentProperties Map<String, Object> props; 1 2

slide-35
SLIDE 35

Configuration Types

@rotty3000

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

slide-36
SLIDE 36

DS - Configuration: typed

@rotty3000

@Activate Config config; 1 2

slide-37
SLIDE 37

OSGi-CDI - Configuration: typed

@rotty3000

@Inject @ComponentProperties Config config; 1 2

slide-38
SLIDE 38

DS - Component

@rotty3000

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

slide-39
SLIDE 39

OSGi-CDI - Single Component

@rotty3000

@SingleComponent @PID("foo") @PID(value = "bar", policy = REQUIRED) public class FooImpl { ... } 1 2 3 4 5 6

slide-40
SLIDE 40

OSGi-CDI - Factory Component

@rotty3000

@FactoryComponent("foo") @PID("bar") public class FooImpl { ... } 1 2 3 4 5

slide-41
SLIDE 41

The OSGi-CDI Spec

https://osgi.org/specification/osgi.enterprise/7.0.0/service.cdi.html @rotty3000

slide-42
SLIDE 42

The OSGi-CDI Reference Implementation

https://github.com/apache/aries-cdi @rotty3000