osgi fundamentals
TRANSCRIPT
@MilenDyankov
OSGi Fundamentals
OSGi = Modularity
"When I use a word," Humpty Dumpty said,
in rather a scornful tone,
"it means just what I choose it to mean - neither
more nor less."
Modularity Maturity Modelproposed by Dr Graham Charters
at the OSGi Community Event 2011
Level 1 Ad Hoc nothing
Level 2 Modules decoupled from artifact
Level 3 Modularity decoupled from identity
Level 4 Loose-Coupling decoupled from implementation
Level 5 Devolution decoupled from ownership
Level 6 Dynamism decoupled from time
Level 1 Ad Hoc nothing
Level 2 Modules decoupled from artifact
Level 3 Modularity decoupled from identity
Level 4 Loose-Coupling decoupled from implementation
Level 5 Devolution decoupled from ownership
Level 6 Dynamism decoupled from time
Level 7 Peter Kriens only available to people who are Peter Kriens
Modularity Maturity Modelproposed by Dr Graham Charters
at the OSGi Community Event 2011
Modularity Maturity Modelproposed by Peter Kriens
in foreword to “Java Application Architecture”
Level 1 Ad Hoc
Level 2 Modules
Level 3 Modularity
Level 4 Loose-Coupling
Level 5 Devolution
Level 6 Dynamism
Unmanaged / chaos
Managing dependencies
Proper isolation
Minimize coupling
Service-oriented architecture
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5 JuServices
Buzzword compliant Modularity Maturity Model
Level 1 Monolith Unaware of own dependencies
Level 2 Composite Aware of infrastructural dependencies
Level 3 Containers Aware of functional dependencies
Level 4 Discovery Aware of functional requirements
Level 5 Adapts to changing requirementsJuServices
Buzzword compliant Modularity Maturity Model
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5 JuServices
Buzzword compliant Modularity Maturity Model
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5 JuServices
Buzzword compliant Modularity Maturity Model
Buzzword compliant Modularity Maturity Model
JuServices
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5
Buzzword compliant Modularity Maturity Model
JuServices
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5 OSGi
productintermediate
intermediate
material
Product
Entity
EntityEntity
Entity
Entity Entity
Offer
Offer
Offer
Offer
Offer
Offer
Offer
Offer
Offer
Offer
Offer
Application
Artifact
ArtifactArtifact
Artifact
Artifact Artifact
Export
Export
Export
Export
Export
Export
Export
Export
Export
Export
Export
Artifact
Level 2decoupled from
artifact
Foo
Level 2decoupled from
artifact
Manifest-Version: 1.0Bundle-ManifestVersion: 2Bundle-Name: Foo
Bundle-SymbolicName: com.fooBundle-Vendor: Foo, Inc.
Bundle-Version: 1.0.0. . .
Buzzword compliant Modularity Maturity Model
JuServices OSGi
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5
OK!
Level 3decoupled from
identity
Artifact
Export
Artifact
Level 3decoupled from
identity
Require-Bundle: com.fooFoo
Me
Level 3decoupled from
identity
Export-Package ::= export ( ',' export)*
List of packages (Java package + version) within this jarfile that external code is allowed to access!
Foo
Me
Level 3decoupled from
identity
Export-Package:\ com.standard.power.plugs;\
version=”1.0.0”,\com.foo.power.plugs.shop;\
version=”2.3.0”;\uses:=”com.standard.power.plugs”,\
...
Export-Package ::= export ( ',' export)*
List of packages (Java package + version) within this jarfile that external code is allowed to access!
Foo
Me
Level 3decoupled from
identity
Import-Package ::= import ( ',' import )*
List of packages (Java package + version-range) thatclasses in this jar file expect other bundles to provide!
Foo
Me
Level 3decoupled from
identity
Import-Package:\ com.standard.power.plugs;\
version=”[1,2)”,\com.foo.power.plugs.shop;\
version=”2.3.0”,\com.other.power.plugs.shop;\
version=”1.5.0”,\...
Foo
Me
Import-Package ::= import ( ',' import )*
List of packages (Java package + version-range) thatclasses in this jar file expect other bundles to provide!
Buzzword compliant Modularity Maturity Model
JuServices OSGi
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5
OK!
OK!
Level 4decoupled fromimplementation
Artifact
Artifact
RequirementNeed toconnectdevice to
power outlet!
CapabilityCan
connectdevice to
power outlet!
RESOLVER
Level 4decoupled fromimplementation
Artifact
Artifact
RequirementNeed toconnectdevice to
power outlet!
CapabilityCan
connectdevice to
power outlet!
RESOLVER
Require-Capability:power.supply;\
filter:=”(& (voltage>110)\(voltage<230))”,\
electrician;\filter:=”(& (price<50)\
(certified=yes))”
Level 4decoupled fromimplementation
Artifact
Artifact
RequirementNeed toconnectdevice to
power outlet!
CapabilityCan
connectdevice to
power outlet!
RESOLVER
Require-Capability:power.supply;\
filter:=”(& (voltage>110)\(voltage<230))”,\
electrician;\filter:=”(& (price<50)\
(certified=yes))”
org.osgi.framework.system.capabilities.extra= power.supply;voltage:Long=220
Level 4decoupled fromimplementation
Artifact
Artifact
RequirementNeed toconnectdevice to
power outlet!
CapabilityCan
connectdevice to
power outlet!
RESOLVER
Require-Capability:power.supply;\
filter:=”(& (voltage>110)\(voltage<230))”,\
electrician;\filter:=”(& (price<50)\
(certified=yes))”
org.osgi.framework.system.capabilities.extra= power.supply;voltage:Long=220
Provide-Capability:electrician;price:Long=10;certified=yes
Buzzword compliant Modularity Maturity Model
JuServices OSGi
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5
OK!
OK!
OK!
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
manifestmanifest
OSGi service registry
REGISTER
REGISTER
manifest
Interface
Service 1
. . .
Service N
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
manifestmanifest
OSGi service registry
REGISTER USE
manifest
Interface
Service 1
. . .
Service N
REGISTER
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
OSGi service registry
SERVLET
SERVLET
GET GET
REGISTER
REGISTER
HTTPServiceImpl
HTTPService
HTTPServiceImpl
REGISTER
manifest
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
manifest
OSGi service registry
HTTPServlet
REGISTER
SERVLET
SERVLETGET(when needed)
HTTPServiceImpl
Servlet1 (path=”/1”)
Servlet2 (path=”/2”)
REGISTER
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
Register OSGI service (manually) SINGLETON
PROPERTIES CONTRACT
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
Use an OSGI service (manually)
DONE WITHTHE SERVICE
START USINGTHE SERVCE
FINDA SERVCE
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
Declarative servicesand
Service Component Runtime (SCR)
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
/OSGI-INF/MyComponent.xml file:<?xml version="1.0" encoding="UTF-8"?>
<scr:component name=”MyComponent”xmlns:scr=”http://www.osgi.org/xmlns/scr/v1.2.0”>
<implementation class=”com.liferay.MyComponent”/></scr:component>
Manifest header:Service-Component: OSGI-INF/MyComponent.xml
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
@Component(configurationPid=”hello.component.pid”,configurationPolicy=ConfigurationPolicy.OPTIONAL,enabled=true,immediate=true,name=”HelloComponent”,property={
”vendor.name=Liferay”, ”other.property=value”
},service={HelloService.class, OtherService.class})
public class HelloComponent implements MultiService { . . .
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
@Activatevoid open(Map<String,?> properties) { }
@Deactivatevoid close() {}
@Modifiedvoid modified(Map<String,?> properties) {}
Level 5
decoupled fromownership & time
JuServices
Artifact
Artifact
REGISTRY
Service
Service
Service
Service
@Reference(cardinality=ReferenceCardinality.MANDATORY,name = “LogService”,policy = ReferencePolicy.STATIC,policyOption=ReferencePolicyOption.RELUCTANT,service = LogService.class,target = “(vendor.name=Liferay)”,unbind = “unsetLog”,updated = “updatedLog”
)void setLog( LogService log) {}void unsetLog( LogService log) { }void updatedLog( Map<String,?> ref ) { }
Buzzword compliant Modularity Maturity Model
JuServices OSGi
Level 1 Monolith
Level 2 Composite
Level 3 Containers
Level 4 Discovery
Level 5
OK!
OK!
OK!
OK!
The essence ofmodularity is
Not knowing
The essence ofmodularity is
Not knowing
Which enforcesoptimization forPredictability
Which results inapplicationAgility
The essence ofmodularity is
Not knowing
Which enforcesoptimization forPredictability