osgi fundamentals

50
@MilenDyankov OSGi Fundamentals

Upload: milen-dyankov

Post on 06-Jan-2017

927 views

Category:

Software


0 download

TRANSCRIPT

Page 1: OSGi fundamentals

@MilenDyankov

OSGi Fundamentals

Page 2: OSGi fundamentals

OSGi = Modularity

Page 3: OSGi fundamentals

"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."

Page 4: OSGi fundamentals

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

Page 5: OSGi fundamentals

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

Page 6: OSGi fundamentals

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

Page 7: OSGi fundamentals

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5 JuServices

Buzzword compliant Modularity Maturity Model

Page 8: OSGi fundamentals

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

Page 9: OSGi fundamentals

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5 JuServices

Buzzword compliant Modularity Maturity Model

Page 10: OSGi fundamentals

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5 JuServices

Buzzword compliant Modularity Maturity Model

Page 11: OSGi fundamentals

Buzzword compliant Modularity Maturity Model

JuServices

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

Page 12: OSGi fundamentals

Buzzword compliant Modularity Maturity Model

JuServices

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5 OSGi

Page 13: OSGi fundamentals

productintermediate

intermediate

material

Page 14: OSGi fundamentals
Page 15: OSGi fundamentals
Page 16: OSGi fundamentals
Page 17: OSGi fundamentals

Product

Entity

EntityEntity

Entity

Entity Entity

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Page 18: OSGi fundamentals

Application

Artifact

ArtifactArtifact

Artifact

Artifact Artifact

Export

Export

Export

Export

Export

Export

Export

Export

Export

Export

Export

Page 19: OSGi fundamentals

Artifact

Level 2decoupled from

artifact

Page 20: OSGi fundamentals

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. . .

Page 21: OSGi fundamentals

Buzzword compliant Modularity Maturity Model

JuServices OSGi

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

OK!

Page 22: OSGi fundamentals

Level 3decoupled from

identity

Artifact

Export

Artifact

Page 23: OSGi fundamentals

Level 3decoupled from

identity

Require-Bundle: com.fooFoo

Me

Page 24: OSGi fundamentals

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

Page 25: OSGi fundamentals

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

Page 26: OSGi fundamentals

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

Page 27: OSGi fundamentals

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!

Page 28: OSGi fundamentals

Buzzword compliant Modularity Maturity Model

JuServices OSGi

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

OK!

OK!

Page 29: OSGi fundamentals

Level 4decoupled fromimplementation

Artifact

Artifact

RequirementNeed toconnectdevice to

power outlet!

CapabilityCan

connectdevice to

power outlet!

RESOLVER

Page 30: OSGi fundamentals

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))”

Page 31: OSGi fundamentals

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

Page 32: OSGi fundamentals

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

Page 33: OSGi fundamentals

Buzzword compliant Modularity Maturity Model

JuServices OSGi

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

OK!

OK!

OK!

Page 34: OSGi fundamentals

Level 5

decoupled fromownership & time

JuServices

Artifact

Artifact

REGISTRY

Service

Service

Service

Service

Page 35: OSGi fundamentals

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

Page 36: OSGi fundamentals

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

Page 37: OSGi fundamentals

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

Page 38: OSGi fundamentals

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

Page 39: OSGi fundamentals

Level 5

decoupled fromownership & time

JuServices

Artifact

Artifact

REGISTRY

Service

Service

Service

Service

Register OSGI service (manually) SINGLETON

PROPERTIES CONTRACT

Page 40: OSGi fundamentals

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

Page 41: OSGi fundamentals

Level 5

decoupled fromownership & time

JuServices

Artifact

Artifact

REGISTRY

Service

Service

Service

Service

Declarative servicesand

Service Component Runtime (SCR)

Page 42: OSGi fundamentals

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

Page 43: OSGi fundamentals

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 { . . .

Page 44: OSGi fundamentals

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) {}

Page 45: OSGi fundamentals

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 ) { }

Page 46: OSGi fundamentals

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!

Page 47: OSGi fundamentals

The essence ofmodularity is

Not knowing

Page 48: OSGi fundamentals

The essence ofmodularity is

Not knowing

Which enforcesoptimization forPredictability

Page 49: OSGi fundamentals

Which results inapplicationAgility

The essence ofmodularity is

Not knowing

Which enforcesoptimization forPredictability

Page 50: OSGi fundamentals

[email protected]@MilenDyankov

http://www.liferay.com@Liferay