introduction to osgi (tokyo jug)
DESCRIPTION
TRANSCRIPT
![Page 1: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/1.jpg)
Introduction to OSGiNeil Bartlett – 東京 2009年12月23日
![Page 2: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/2.jpg)
Brief Intro to OSGi
❶
![Page 3: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/3.jpg)
OSGi: The Module System for Java
![Page 4: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/4.jpg)
Standard Java
ABC.JAR
JARs are Deployment
Units
They are Not Modules
![Page 5: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/5.jpg)
Meaningful name
Version
Vendor
Exports
Dependencies
What’s Missing?
ABC.JAR
![Page 6: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/6.jpg)
Dependencies
JARs do have dependencies
They are implicit.
A dependency is an assumption.
“I assume module X (version Y) is on the
classpath. If not I will crash and burn.”
![Page 7: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/7.jpg)
Module = “Bundle”
![Page 8: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/8.jpg)
Meaningful name
Version
Vendor
Exports
Dependencies
Just a JAR + Metadata
org.foo.mylibManifest-Version: 1.0Bundle-SymbolicName: com.mylibBundle-Name: My Library BundleBundle-Vendor: Neil BartlettBundle-Version: 1.0.0Import-Package: javax.swing, org.w3c.domExport-Package: com.mylib1.ui;version=“1.0.0”, com.mylib1.util;version=“1.0.0”Bundle-RequiredExecutionEnvironment: J2SE-1.5
![Page 9: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/9.jpg)
MANIFEST.MF
Manifest-Version: 1.0Bundle-SymbolicName: com.mylibBundle-Name: My Library BundleBundle-Vendor: Neil BartlettBundle-Version: 1.0.0Import-Package: javax.swing, org.w3c.domExport-Package: com.mylib.ui;version=“1.0.0”, com.mylib.util;version=“1.0.0”Bundle-RequiredExecutionEnvironment: J2SE-1.5
![Page 10: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/10.jpg)
Works Outside OSGi
![Page 11: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/11.jpg)
Dependency Graphs
![Page 12: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/12.jpg)
![Page 13: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/13.jpg)
com.foo.bar
javax.swing
org.wibble
Imports..... and Exports
com.mylib
com.mylib.ui
com.mylib.util} {
![Page 14: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/14.jpg)
Package Resolution
com.foo.bar
A
![Page 15: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/15.jpg)
Package Resolution
com.foo.bar
A
com.foo.bar
B
![Page 16: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/16.jpg)
Package Resolution
com.foo.bar
A
com.foo.bar
B
![Page 17: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/17.jpg)
Versioned Dependency
com.foo.bar
[1.2.0,1.4.0) A
![Page 18: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/18.jpg)
Versioned Dependency
com.foo.bar
[1.2.0,1.4.0) A
com.foo.bar
1.4.5B
![Page 19: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/19.jpg)
Versioned Dependency
com.foo.bar
[1.2.0,1.4.0) A
com.foo.bar
1.4.5B ✘
![Page 20: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/20.jpg)
Versioned Dependency
com.foo.bar
[1.2.0,1.4.0) A
com.foo.bar
1.3.12B’
![Page 21: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/21.jpg)
Versioned Dependency
com.foo.bar
[1.2.0,1.4.0) A
com.foo.bar
1.3.12B’
![Page 22: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/22.jpg)
Side-by-Side Versions
com.foo.bar
1.4.5
com.foo.bar
1.3.12
com.foo.bar
[1.2.0,1.4.0)
com.foo.bar
[1.4.0,1.5.0)B
B’
X
Y
![Page 23: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/23.jpg)
Side-by-Side Versions
com.foo.bar
1.4.5
com.foo.bar
1.3.12
com.foo.bar
[1.2.0,1.4.0)
com.foo.bar
[1.4.0,1.5.0)B
B’
X
Y
![Page 24: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/24.jpg)
How it Works
Bundle-SymbolicName: com.mylib1Bundle-Version: 1.2.0Export-Package: com.mylib1.ui;version=“1.2.0”, com.mylib1.util;version=“1.2.0”
Bundle-SymbolicName: com.app1Bundle-Version: 2.2.3.alphaImport-Package: com.mylib1.ui;version=“[1.2.0,1.3.0)” com.mylib1.util;version=“[1.2.0,1.3.0)”
![Page 25: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/25.jpg)
Private Internals
Exports must be stated explicitly
Packages not listed in “Export-Package” are not
available to other bundles
![Page 26: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/26.jpg)
Versions
Standard numbering scheme with well-defined
ordering.
major.minor.micro.qualifier
First three numeric, last alphanumeric
Eg 1.0.0.beta2
Unspecified ! 0.0.0
![Page 27: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/27.jpg)
Version Ranges
Open, closed or implicit
[1.0.0, 2.0.0] ! 1.0.0 ! version ! 2.0.0
[1.0.0, 2.0.0) ! 1.0.0 ! version < 2.0.0
Informally “1.*”
1 ! [1.0.0, ")
Unspecified ! [0.0.0, ")
![Page 28: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/28.jpg)
Our Promise*: No More
NoClassDefFoundErrors!
![Page 29: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/29.jpg)
Dynamic!Dynamic!
![Page 30: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/30.jpg)
Dynamic
Install Bundles
Update Bundles
Uninstall Bundles
... all “on the fly”
![Page 31: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/31.jpg)
OSGi in Infrastructure
❷
![Page 32: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/32.jpg)
OSGi is the King of Infrastructure
All Major JEE Application Servers use OSGi
Most ESBs use OSGi
2 of 3 Open Source IDEs use OSGi
Even Build Tools (Maven and Hudson) Moving to OSGi
![Page 33: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/33.jpg)
Where are the “Business” Apps?
![Page 34: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/34.jpg)
OSGi for Applications
Until Recently, Application Servers used OSGi “on the inside”
Now SpringSource dm Server, Paremus Infiniflow, WAS 7, GlassFish v3 and WebLogic DM all expose OSGi
Application Developers can Finally Deploy OSGi bundles to their OSGi servers!
![Page 35: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/35.jpg)
Why is OSGi Attractive for Application Development?
![Page 36: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/36.jpg)
The Failure of Object Oriented Programming
❸
![Page 37: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/37.jpg)
OOP Was Meant to Enable Reuse
![Page 38: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/38.jpg)
HARDER THAN EXPECTED!
![Page 39: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/39.jpg)
“Building a new system would be a snap. Just get a
few classes, bunch them together... and voila!”
– Peter Kriens
![Page 40: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/40.jpg)
What Went Wrong??
![Page 41: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/41.jpg)
Tight Coupling
![Page 42: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/42.jpg)
COMPLEXITY
![Page 43: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/43.jpg)
Classes coupled to Other Classes
![Page 44: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/44.jpg)
Packages coupled to Other Packages
![Page 45: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/45.jpg)
Packages coupled to JARs
![Page 46: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/46.jpg)
JARs coupled to More JARs
![Page 47: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/47.jpg)
Which are coupled to yet more JARs...
![Page 48: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/48.jpg)
![Page 49: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/49.jpg)
Dependency Injection?
![Page 50: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/50.jpg)
DI Frameworks
Provide “Late Binding” of Implementations to Interfaces
But Not Late Enough!
![Page 51: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/51.jpg)
Spring Framework
<bean id="MyBean" class="org.example.MyBean"> <property name="dataSource" ref="OracleDataSource"/></bean>
<bean id="OracleDataSource" class="..."> <property name="..." /></bean>
![Page 52: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/52.jpg)
Traditional Spring
![Page 53: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/53.jpg)
Static DI
“Beans” are wired together once, at start-up
They cannot be rewired
Limited support for optional dependencies
![Page 54: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/54.jpg)
FRAGILE
![Page 55: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/55.jpg)
One Solution: Give Up!
![Page 56: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/56.jpg)
Reuse is Hard, So Don’t Try!
![Page 57: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/57.jpg)
Leave Code in One Place, and Call Remotely
(...also known as “SOA”)
![Page 58: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/58.jpg)
Component Oriented Programming
❹
![Page 59: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/59.jpg)
What is a “Component”?
![Page 60: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/60.jpg)
The Usual Analogy:
![Page 61: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/61.jpg)
LEGO?
![Page 62: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/62.jpg)
Not Really...
Dead Lumps of Plastic
Many Copies of the Same Thing
![Page 63: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/63.jpg)
BIOLOGY
![Page 64: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/64.jpg)
BIOLOGY
![Page 65: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/65.jpg)
Dr Alan Kay
Inventor of Object Oriented Programming & Smalltalk
“I thought of objects being like biological cells...”
![Page 66: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/66.jpg)
Components
Do Something, or Provide Something
Aware of and Adapt to their Environment
Have a Life-cycle (birth to death).
![Page 67: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/67.jpg)
“Do” Something
Open a socket
Monitor a device
Poll a queue
Display a GUI
.... etc.
![Page 68: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/68.jpg)
“Provide” Something
Publish a Service – may be used by other components
![Page 69: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/69.jpg)
The “Environment”
The “Environment” of a Component means:
Services provided by other Components
Resources, Devices, Network etc
![Page 70: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/70.jpg)
Components Adapt to their Environment
![Page 71: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/71.jpg)
Most services are available
The component flourishes
Good Environment
![Page 72: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/72.jpg)
Harsh Environment
Some non-essential services are unavailable
Component adapts and survives
![Page 73: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/73.jpg)
Very Harsh Environment
Essential services are unavailable
Component hibernates or dies
![Page 74: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/74.jpg)
Composition
Components Use other Components
In this way, whole Systems are Composed
Resilient, Elastic Systems
![Page 75: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/75.jpg)
Developing Components
❺
![Page 76: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/76.jpg)
Services
Components provide Services
Registered with a Service Registry
Services are POJOs!
Looked up by Java interface name
![Page 77: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/77.jpg)
In-Process SOA
ServiceProviderService
Consumer
ServiceBroker
Client Service
RegisterFind
Bind
ServiceContract
![Page 78: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/78.jpg)
Plain Old Java Objects
![Page 79: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/79.jpg)
The Glue Between Components
![Page 80: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/80.jpg)
Dynamics Make Services Slippery
![Page 81: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/81.jpg)
We Don’t Code Directly against Services (it’s too hard!)
![Page 82: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/82.jpg)
Let a Framework Handle the Hard Stuff
![Page 83: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/83.jpg)
Choice of Frameworks
Declarative Services (DS)
Blueprint (from Spring-DM)
iPOJO
Guice Peaberry
![Page 84: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/84.jpg)
Framework Interop
Perfect Interoperability of these Frameworks!
No need to choose “The One True Framework”
Use 3rd-party components implemented with other frameworks.
![Page 85: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/85.jpg)
Examining DS
Dynamic dependency injection (DI)
... and “uninjection”
![Page 86: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/86.jpg)
Starting Point...
import javax.sql.DataSource;
public class DbMailbox implements Mailbox {
private DataSource dataSource; void setDataSource(DataSource ds) { /*...*/ } void unsetDataSource(DataSource ds) { /*...*/ }
public long[] getAllMessages() { // ... }}
![Page 87: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/87.jpg)
Starting Point...
import javax.sql.DataSource;
public class DbMailbox implements Mailbox {
private DataSource dataSource; void setDataSource(DataSource ds) { /*...*/ } void unsetDataSource(DataSource ds) { /*...*/ }
public long[] getAllMessages() { // ... }}
No OSGi API Used
![Page 88: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/88.jpg)
Starting Point...
import javax.sql.DataSource;
public class DbMailbox implements Mailbox {
private DataSource dataSource; void setDataSource(DataSource ds) { /*...*/ } void unsetDataSource(DataSource ds) { /*...*/ }
public long[] getAllMessages() { // ... }}
No OSGi API Used
JavaBeans Style => Testable
![Page 89: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/89.jpg)
Make it a Componentimport javax.sql.DataSource;
@Componentpublic class DbMailbox implements Mailbox {
private DataSource dataSource; @Reference(service = DataSource.class) void setDataSource(DataSource ds) { /*...*/ } void unsetDataSource(DataSource ds) { /*...*/ }
public long[] getAllMessages() { // ... }}
![Page 90: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/90.jpg)
Annotations
@Component – Create a Component of this type.
Service is automatically published
@Reference – Use the specified service
![Page 91: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/91.jpg)
Add Life-cycle
@Activate void start() { thread = new Thread(); thread.start(); } @Deactivate void stop() { thread.interrupt(); }
![Page 92: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/92.jpg)
Make it Configurable @Activate void start(Map<String, Object> configuration) { thread = new Thread(); thread.start(); } @Modified void modify(Map<String, Object> newConfiguration) { // This method is optional } @Deactivate void stop() { thread.interrupt(); }
![Page 93: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/93.jpg)
Optional Reference
@Reference(service = LogService.class, optional = true)void setLogService(LogService log) { /* ... */ }void unsetLogService(LogService log) { /* ... */ }
![Page 94: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/94.jpg)
Multiple Reference
@Reference(service = MailboxListener.class, multiple = true)void addListener(MailboxListener listener) { /* ... */ }void removeListener(MailboxListener listener) { /* ... */ }
![Page 95: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/95.jpg)
DEMO
❻
![Page 96: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/96.jpg)
Mailbox Reader
Fixed
Mailbox
Mailbox
![Page 97: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/97.jpg)
Mailbox Reader
GrowingMailbox
MailboxListener
Mailbox
![Page 98: Introduction to OSGi (Tokyo JUG)](https://reader038.vdocuments.site/reader038/viewer/2022102823/5467d51baf7959b65d8b4e96/html5/thumbnails/98.jpg)
Mailbox Reader
TradesMailbox
MailboxListener
Mailbox
EventHandler
Event Broker
EventAdmin
Trade MatchingEngine
Order Entry
MatchingService