SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
 
 
 
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
 

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie OSGi CDI Integration Specification -- Raymond Augé, Liferay

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

Ähnlich wie 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...
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

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