SlideShare une entreprise Scribd logo
1  sur  29
Télécharger pour lire hors ligne
 
 
 
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
intra-bundle dependency injection
Custom annotations!
@rotty3000
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
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
OSGi-CDI - Services: singleton
@rotty3000
import org.osgi.service.cdi.annotations.Service;
@Service
public class PresenterImpl implements Presenter {
...
}
1
2
3
4
5
6
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
OSGi-CDI - OSGi Logger
@rotty3000
import javax.inject.Inject;
import org.osgi.service.log.Logger;
@Inject
Logger video;
1
2
3
4
5
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
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
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
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
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
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
 

Contenu connexe

Tendances

A second look at Unit Testing with Roy Osherove at Microsoft Swit
A second look at Unit Testing with Roy Osherove at Microsoft SwitA second look at Unit Testing with Roy Osherove at Microsoft Swit
A second look at Unit Testing with Roy Osherove at Microsoft Swit
Roy Osherove
 

Tendances (20)

apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
 
React: JSX and Top Level API
React: JSX and Top Level APIReact: JSX and Top Level API
React: JSX and Top Level API
 
Writing testable Android apps
Writing testable Android appsWriting testable Android apps
Writing testable Android apps
 
Lets dance- Dutch Architecture Conference (LAC) 2018
Lets dance- Dutch Architecture Conference (LAC) 2018Lets dance- Dutch Architecture Conference (LAC) 2018
Lets dance- Dutch Architecture Conference (LAC) 2018
 
React custom renderers
React custom renderersReact custom renderers
React custom renderers
 
[제3회 스포카콘] Elasticsearch 동기화 개선을 위한 고군분투기
[제3회 스포카콘] Elasticsearch 동기화 개선을 위한 고군분투기[제3회 스포카콘] Elasticsearch 동기화 개선을 위한 고군분투기
[제3회 스포카콘] Elasticsearch 동기화 개선을 위한 고군분투기
 
Blood, sweat, and creating an API handbook
Blood, sweat, and creating an API handbookBlood, sweat, and creating an API handbook
Blood, sweat, and creating an API handbook
 
Pure APIs: Development workflows for successful API integrations
Pure APIs: Development workflows for successful API integrationsPure APIs: Development workflows for successful API integrations
Pure APIs: Development workflows for successful API integrations
 
[Fevr] Can't live if livin' is without rendering
[Fevr] Can't live if livin' is without rendering[Fevr] Can't live if livin' is without rendering
[Fevr] Can't live if livin' is without rendering
 
Use Geth to Deploy Contract
Use Geth to Deploy ContractUse Geth to Deploy Contract
Use Geth to Deploy Contract
 
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
 
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
 
Use Geth to Access a Deployed Contract
Use Geth to Access a Deployed ContractUse Geth to Access a Deployed Contract
Use Geth to Access a Deployed Contract
 
[제3회 스포카콘] [안드로이드] 클린 아키텍처 적용하기
[제3회 스포카콘] [안드로이드] 클린 아키텍처 적용하기[제3회 스포카콘] [안드로이드] 클린 아키텍처 적용하기
[제3회 스포카콘] [안드로이드] 클린 아키텍처 적용하기
 
Advanced Automation in Your API Lifecycle
Advanced Automation in Your API Lifecycle Advanced Automation in Your API Lifecycle
Advanced Automation in Your API Lifecycle
 
Design-first API Development using Swagger and Node
Design-first API Development using Swagger and NodeDesign-first API Development using Swagger and Node
Design-first API Development using Swagger and Node
 
Test your microservices with REST-Assured
Test your microservices with REST-AssuredTest your microservices with REST-Assured
Test your microservices with REST-Assured
 
A second look at Unit Testing with Roy Osherove at Microsoft Swit
A second look at Unit Testing with Roy Osherove at Microsoft SwitA second look at Unit Testing with Roy Osherove at Microsoft Swit
A second look at Unit Testing with Roy Osherove at Microsoft Swit
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
 
Serverless GraphQL for Product Developers
Serverless GraphQL for Product DevelopersServerless GraphQL for Product Developers
Serverless GraphQL for Product Developers
 

Similaire à OSGi CDI Integration Specification -- Raymond Augé, Liferay

OAE Developer Bootcamp
OAE Developer BootcampOAE Developer Bootcamp
OAE Developer Bootcamp
Bert Pareyn
 

Similaire à OSGi CDI Integration Specification -- Raymond Augé, Liferay (20)

CDI Integration in OSGi - Emily Jiang
CDI Integration in OSGi - Emily JiangCDI Integration in OSGi - Emily Jiang
CDI Integration in OSGi - Emily Jiang
 
Spring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsugSpring Cloud Function & Project riff #jsug
Spring Cloud Function & Project riff #jsug
 
What's cool in the new and updated OSGi Specs (2013)
What's cool in the new and updated OSGi Specs (2013)What's cool in the new and updated OSGi Specs (2013)
What's cool in the new and updated OSGi Specs (2013)
 
OSGi DevCon 2009 Review
OSGi DevCon 2009 ReviewOSGi DevCon 2009 Review
OSGi DevCon 2009 Review
 
Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM Maximize the power of OSGi in AEM
Maximize the power of OSGi in AEM
 
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten ZiegelerNew and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
New and cool in OSGi R7 - David Bosschaert & Carsten Ziegeler
 
DevRock #01 What's new ASP.net 5
DevRock #01 What's new ASP.net 5DevRock #01 What's new ASP.net 5
DevRock #01 What's new ASP.net 5
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
BEST REST in OpenStack
BEST REST in OpenStackBEST REST in OpenStack
BEST REST in OpenStack
 
Weld-OSGi, injecting easiness in OSGi
Weld-OSGi, injecting easiness in OSGiWeld-OSGi, injecting easiness in OSGi
Weld-OSGi, injecting easiness in OSGi
 
A tour through Swift attributes
A tour through Swift attributesA tour through Swift attributes
A tour through Swift attributes
 
Apidays Paris 2023 - Managing OpenAPI Documents at Scale, Stéve Sfartz, Cisco
Apidays Paris 2023 - Managing OpenAPI Documents at Scale, Stéve Sfartz, CiscoApidays Paris 2023 - Managing OpenAPI Documents at Scale, Stéve Sfartz, Cisco
Apidays Paris 2023 - Managing OpenAPI Documents at Scale, Stéve Sfartz, Cisco
 
apidays LIVE LONDON - Toward certifying Financial-grade API profile with Keyc...
apidays LIVE LONDON - Toward certifying Financial-grade API profile with Keyc...apidays LIVE LONDON - Toward certifying Financial-grade API profile with Keyc...
apidays LIVE LONDON - Toward certifying Financial-grade API profile with Keyc...
 
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
Creating Data Driven Web Apps with BIRT - Pierre Richer (Actuate)
 
Bootiful Development with Spring Boot and Angular - Connect.Tech 2017
 Bootiful Development with Spring Boot and Angular - Connect.Tech 2017 Bootiful Development with Spring Boot and Angular - Connect.Tech 2017
Bootiful Development with Spring Boot and Angular - Connect.Tech 2017
 
Apic dc api deep dive
Apic dc api deep dive Apic dc api deep dive
Apic dc api deep dive
 
Front End Development for Back End Developers - Devoxx UK 2017
 Front End Development for Back End Developers - Devoxx UK 2017 Front End Development for Back End Developers - Devoxx UK 2017
Front End Development for Back End Developers - Devoxx UK 2017
 
OAE Developer Bootcamp
OAE Developer BootcampOAE Developer Bootcamp
OAE Developer Bootcamp
 
Dependency Injection Styles
Dependency Injection StylesDependency Injection Styles
Dependency Injection Styles
 
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

OSGi CDI Integration Specification -- Raymond Augé, Liferay

  • 1.       OSGi CDI Integration Specification Raymond Augé - Sr. So ware Architect @rotty3000
  • 2. Why CDI In OSGi? Important Java specification Reduce developer friction Benefit from extensive feature set @rotty3000
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. OSGi-CDI - OSGi Logger @rotty3000 import javax.inject.Inject; import org.osgi.service.log.Logger; @Inject Logger video; 1 2 3 4 5
  • 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. 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. 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. 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. 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
  • 29. The OSGi-CDI Reference Implementation https://github.com/apache/aries-cdi @rotty3000