Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
�
�
�
OSGi CDI Integration Specification
Raymond Aug� - Sr. So ware Architect
@rotty3000
Why CDI In OSGi?
Important Java specification
Reduce developer friction
Benefit from extensive feature set
@rotty3000
CDI - Features
as part of its feature set, is...
extensible (CDI has a full fledged SPI)
annotation processing engine
intr...
CDI - Internal wiring: @Inject
@rotty3000
import javax.inject.Inject;
public class PresenterImpl implements Presenter {
pr...
CDI - Internal wiring: @Produces
@rotty3000
import javax.enterprise.inject.Produces;
@Produces Presentation presentation(
...
OSGi-CDI - Services: singleton
@rotty3000
import org.osgi.service.cdi.annotations.Service;
@Service
public class Presenter...
OSGi-CDI - Services: prototype
@rotty3000
import org.osgi.service.cdi.annotations.Service;
import org.osgi.service.cdi.ann...
OSGi-CDI - References to OSGi Services
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Refe...
OSGi-CDI - References Cardinality: mandatory
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotation...
OSGi-CDI - References Cardinality: optional
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations...
OSGi-CDI - References Cardinality: multiple
... implies 0..n (multiple optional)
@rotty3000
import javax.inject.Inject;
im...
OSGi-CDI - References Cardinality: at least one
(or n)
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi....
OSGi-CDI - Reference Policy: reluctant
... reference is Greedy by default
@rotty3000
import javax.inject.Inject;
import or...
OSGi-CDI - References Dynamic: mandatory
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Re...
OSGi-CDI - References Dynamic: multiple
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Ref...
OSGi-CDI - References Dynamic: optional
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Ref...
OSGi-CDI - Reference: target
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@In...
OSGi-CDI - Reference: target
@BeanPropertyType
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotati...
OSGi-CDI - Reference: prototype required
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Mi...
OSGi-CDI - Reference: any type
... in support of whiteboards
@rotty3000
import javax.inject.Inject;
import org.osgi.servic...
OSGi-CDI - Reference: service events
@rotty3000
import javax.inject.Inject;
@Inject @ServiceVendor("Chicago JUG")
void mon...
OSGi-CDI - OSGi Logger
@rotty3000
import javax.inject.Inject;
import org.osgi.service.log.Logger;
@Inject
Logger video;
1
...
OSGi-CDI - Configuration
@rotty3000
import javax.inject.Inject;
import
org.osgi.service.cdi.annotations.ComponentPropertie...
OSGi-CDI - Configuration Types
@rotty3000
import org.osgi.service.cdi.annotations.BeanPropertyType;
@Retention(RUNTIME)
@B...
OSGi-CDI - Configuration: typed
@rotty3000
import javax.inject.Inject;
import
org.osgi.service.cdi.annotations.ComponentPr...
OSGi-CDI - Single Component
@rotty3000
import org.osgi.service.cdi.annotations.PID;
import org.osgi.service.cdi.annotation...
OSGi-CDI - Factory Component
@rotty3000
import org.osgi.service.cdi.annotations.PID;
import org.osgi.service.cdi.annotatio...
The OSGi-CDI Spec
https://osgi.org/specification/osgi.enterprise/7.0.0/service.cdi.html
@rotty3000
The OSGi-CDI Reference Implementation
https://github.com/apache/aries-cdi
@rotty3000
�
Prochain SlideShare
Chargement dans…5
×

OSGi CDI Integration Specification -- Raymond Augé, Liferay

19 vues

Publié le

The OSGi Alliance has developed a specification describing integration between OSGi and CDI. The combination of these two powerful development technologies opens the door to new possibilities. This talk will walk through the most essential features of the specification and show some code and running examples.

Publié dans : Technologie
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

OSGi CDI Integration Specification -- Raymond Augé, Liferay

  1. 1. � � � OSGi CDI Integration Specification Raymond Aug� - Sr. So ware Architect @rotty3000
  2. 2. Why CDI In OSGi? Important Java specification Reduce developer friction Benefit from extensive feature set @rotty3000
  3. 3. CDI - Features as part of its feature set, is... extensible (CDI has a full fledged SPI) annotation processing engine intra-bundle dependency injection Custom annotations! @rotty3000
  4. 4. CDI - Internal wiring: @Inject @rotty3000 import javax.inject.Inject; public class PresenterImpl implements Presenter { private final Laptop laptop; @Inject public PresenterImpl(Laptop laptop) { this.laptop = laptop; } } 1 2 3 4 5 6 7 8 9 10
  5. 5. CDI - Internal wiring: @Produces @rotty3000 import javax.enterprise.inject.Produces; @Produces Presentation presentation( LocalDate date, Presenter presenter, @Topic String topic, Details details) { return new Presentation.Builder(date) .withPresenter(presenter) .withTopic(topic) .withDetails(details) .build(); } 1 2 3 4 5 6 7 8 9 10 11 12
  6. 6. OSGi-CDI - Services: singleton @rotty3000 import org.osgi.service.cdi.annotations.Service; @Service public class PresenterImpl implements Presenter { ... } 1 2 3 4 5 6
  7. 7. OSGi-CDI - Services: prototype @rotty3000 import org.osgi.service.cdi.annotations.Service; import org.osgi.service.cdi.annotations.ServiceInstance; @Service @ServiceInstance(PROTOTYPE) public class Beer implements Drink { ... } 1 2 3 4 5 6 7
  8. 8. OSGi-CDI - References to OSGi Services @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Presenter presenter; 1 2 3 4 5
  9. 9. OSGi-CDI - References Cardinality: mandatory @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Presenter presenter; 1 2 3 4 5
  10. 10. OSGi-CDI - References Cardinality: optional @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Optional<Drink> drink; 1 2 3 4 5
  11. 11. OSGi-CDI - References Cardinality: multiple ... implies 0..n (multiple optional) @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference List<Drink> drink; 1 2 3 4 5
  12. 12. OSGi-CDI - References Cardinality: at least one (or n) @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.MinimumCardinality; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference @MinimumCardinality(1) List<Drink> drink; 1 2 3 4 5 6
  13. 13. OSGi-CDI - Reference Policy: reluctant ... reference is Greedy by default @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; import org.osgi.service.cdi.annotations.Reluctant; @Inject @Reference @Reluctant Presenter presenter; 1 2 3 4 5 6
  14. 14. OSGi-CDI - References Dynamic: mandatory @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Provider<Presenter> presenter; 1 2 3 4 5
  15. 15. OSGi-CDI - References Dynamic: multiple @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Provider<List<Presenter>> presenters; 1 2 3 4 5
  16. 16. OSGi-CDI - References Dynamic: optional @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Provider<Optional<Presenter>> presenter; 1 2 3 4 5
  17. 17. OSGi-CDI - Reference: target @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference(target = "(service.vendor=Chicago JUG)") List<Presenter> presenters; 1 2 3 4 5
  18. 18. OSGi-CDI - Reference: target @BeanPropertyType @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; import org.osgi.service.cdi.propertytypes.ServiceVendor; @Inject @Reference @ServiceVendor("Chicago JUG") List<Presenter> presenters; 1 2 3 4 5 6
  19. 19. OSGi-CDI - Reference: prototype required @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.MinimumCardinality; import org.osgi.service.cdi.annotations.PrototypeRequired; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference @MinimumCardinality(1) @PrototypeRequired List<Entry<Map<String, Object>, Drink>> drinks; 1 2 3 4 5 6 7
  20. 20. OSGi-CDI - Reference: any type ... in support of whiteboards @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; import org.osgi.service.cdi.propertytypes.ServiceVendor; @Inject @Reference(service = Reference.Any.class) @ServiceVendor("Chicago JUG") List<Object> all; 1 2 3 4 5 6 7
  21. 21. OSGi-CDI - Reference: service events @rotty3000 import javax.inject.Inject; @Inject @ServiceVendor("Chicago JUG") void monitorDrinks(BindServiceReference<Drink> drinks) { drinks .adding(this::doAdd) .modified(this::doModified) .removed(this::doRemoved) .bind(); } 1 2 3 4 5 6 7 8 9 10
  22. 22. OSGi-CDI - OSGi Logger @rotty3000 import javax.inject.Inject; import org.osgi.service.log.Logger; @Inject Logger video; 1 2 3 4 5
  23. 23. OSGi-CDI - Configuration @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.ComponentProperties; @Inject @ComponentProperties Map<String, Object> eventDetails; 1 2 3 4 5
  24. 24. OSGi-CDI - Configuration Types @rotty3000 import org.osgi.service.cdi.annotations.BeanPropertyType; @Retention(RUNTIME) @BeanPropertyType public @interface Details { String address(); String instructions(); } 1 2 3 4 5 6 7 8
  25. 25. OSGi-CDI - Configuration: typed @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.ComponentProperties; @Inject @ComponentProperties Details eventDetails; 1 2 3 4 5
  26. 26. OSGi-CDI - Single Component @rotty3000 import org.osgi.service.cdi.annotations.PID; import org.osgi.service.cdi.annotations.SingleComponent; @SingleComponent @PID(value = "details", policy = REQUIRED) @Service public PresenterImpl implements Presenter { @Inject Laptop laptop; @Inject @ComponentProperties Details eventDetails; } 1 2 3 4 5 6 7 8 9 10
  27. 27. OSGi-CDI - Factory Component @rotty3000 import org.osgi.service.cdi.annotations.PID; import org.osgi.service.cdi.annotations.FactoryComponent; @FactoryComponent("registration") @PID(value = "details", policy = REQUIRED) public class AttendeeImpl implements Attendee { @Inject @ComponentProperties Registration registration; @Inject @ComponentProperties Details eventDetails; } 1 2 3 4 5 6 7 8 9
  28. 28. The OSGi-CDI Spec https://osgi.org/specification/osgi.enterprise/7.0.0/service.cdi.html @rotty3000
  29. 29. The OSGi-CDI Reference Implementation https://github.com/apache/aries-cdi @rotty3000 �

×