javantura v4 - what’s not new in modular java - milen dyankov

69
What's not new in modular Java! Milen Dyankov @ milendyankov Featuring JDK 9 Early Access with Project Jigsaw Developer advocate @ Liferay

Category:

Technology


1 download

TRANSCRIPT

Page 1: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

What's

notnew

in

modularJava!

Milen Dyankov@ milendyankov

Featuring JDK 9 Early Access with Project Jigsaw

Developer advocate @ Liferay

Page 2: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Think of

not newas in

not newconceptand not as in

not newcar

Page 3: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Whyis it

about timeto startthinkingabout

modularityin Java?

Page 4: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

JSR 277JSR 294

JSR 376JEP 200JEP 201JEP 220JEP 260JEP 261

...

2005

2014

Page 5: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Antwerp, Belgium,November 2015

“Survey” at

Page 6: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov
Page 7: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov
Page 8: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Whatis

modularity/particularly in Java/

anyway?

Page 9: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

"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 10: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

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 11: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

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 12: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

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 13: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5 JuServices

Buzzword compliant Modularity Maturity Model

Page 14: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

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 15: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5 JuServices

Buzzword compliant Modularity Maturity Model

Page 16: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5 JuServices

Buzzword compliant Modularity Maturity Model

Page 17: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Buzzword compliant Modularity Maturity Model

JuServices

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

Page 18: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Buzzword compliant Modularity Maturity Model

JuServices

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5 OSGi

Page 19: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Buzzword compliant Modularity Maturity Model

JuServices OSGi

JPMS

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

Page 20: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Buzzword compliant Modularity Maturity Model

JuServices OSGi

JPMS

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

Page 21: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Whatis

modularity from

applicationperspective ?

Page 22: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Javaapplication

Page 23: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Javaapplication

Java Platform

Libraries

Page 24: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

OSG

i

Page 25: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

There is nothing we can do about it!

OSG

i

Page 26: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

class loaders

There is nothing we can do about it!

OSG

i

Page 27: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

class loaders

There is nothing we can do about it!

Dynamic multi-layermodular runtime!

OSG

i

Page 28: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

class loaders

There is nothing we can do about it!

Dynamic multi-layermodular runtime!

It's so easy,everyone

shouldreleasebundles

(modules)!

OSG

i

Page 29: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

“Manypeople claim

OSGi is hard withoutacknowledging that modularizing

applications is the hard part. . . .

JSR 376 will demonstrate that OSGiwas just the messenger and actually not the cause.”

Peter Kriens

Page 30: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

JPM

S

Page 31: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Modules arefirst class citizens!

JPM

S

Page 32: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

JPM

S

Modules arefirst class citizens!

Nothing to do about it, must use modules!

Page 33: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

JPM

S

Modules arefirst class citizens!

Nothing to do about it, must use modules!

It's so easy,everyone

mustreleasemodules!

Page 34: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

not new

except nowyou kindahave to

newModularJava SE Platform!

ModularJava SE

Applications!

Page 35: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

“A lot of people

will discover that

their babies are not as

modular as they thought”Peter Kriens

Page 36: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Whenis

“keep itsimple!”

not enough?

Page 37: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

productintermediate

intermediate

material

Page 38: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov
Page 39: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov
Page 40: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov
Page 41: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Product

Entity

EntityEntity

Entity

Entity Entity

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Offer

Page 42: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Application

Artifact

ArtifactArtifact

Artifact

Artifact Artifact

Export

Export

Export

Export

Export

Export

Export

Export

Export

Export

Export

Page 43: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Artifact

OSGi JPMS

Manifest-Version: 1.0Bundle-SymbolicName: \

com.mycompany.mymodule

...

MANIFEST.MF

module com.mycompany.mymodule {

...

}

module-info.java

Level 2decoupled from

artifact

Page 44: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Buzzword compliant Modularity Maturity Model

JuServices OSGi

JPMS

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

OK!

Page 45: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Artifact

OSGi

Manifest-Version: 1.0Bundle-SymbolicName: \

com.mycompany.mymodule

Export-Package: \com.mycompany.mypackage

...

MANIFEST.MF

module com.mycompany.mymodule {

exports com.mycompany.mypackage;

...

}

module-info.java

Export

Level 3 decoupled from

identity

JPMS

Page 46: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

OSGi

Manifest-Version: 1.0Bundle-SymbolicName: \

com.mycompany.mymodule

Require-Bundle: \other.module

Import-Package: \com.some.package;version="[2,3)",...

...

MANIFEST.MF

module com.mycompany.mymodule {

requires other.module;

...

}

module-info.java

Artifact

Export

Artifact

Level 3 decoupled from

identity

JPMS

Page 47: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

OSGi

Manifest-Version: 1.0Bundle-SymbolicName: \

com.mycompany.mymodule

Require-Bundle: \com.foo

Import-Package: \com.generic.powerplug;version="[2,3)",...

...

MANIFEST.MF

module com.mycompany.mymodule {

requires com.foo;

...

}

module-info.java

Foo

Me

I need power plug!

I need Foo because I know it offerspower plugs and I know only Foo

offers power plugs!

Level 3 decoupled from

identity

JPMS

Page 48: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

OSGiLevel 3 decoupled from

identity

Manifest-Version: 1.0Bundle-SymbolicName: \

com.mycompany.mymodule

Require-Bundle: \com.foo

Import-Package: \com.generic.powerplug;version="[2,3)",...

...

MANIFEST.MF

module com.mycompany.mymodule {

requires com.foo;

...

}

module-info.java

Foo

Me I'm compatiblewith all 2.x.x

versions!

I expectdeveloper/user to know which version

will work and provideit on module path!

JPMS

Page 49: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

OSGiLevel 3 decoupled from

identity

Manifest-Version: 1.0Bundle-SymbolicName: \

com.mycompany.mymodule

Export-Package: \com.mycompany.mypackage;\

uses:="com.some.package”

...

MANIFEST.MF

module com.mycompany.mymodule {

exports com.mycompany.mypackage;

requires public other.module;

...

}

module-info.java

Artifact

Artifact

ArtifactExport

Uses

Export

JPMS

Page 50: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

OSGiLevel 3 decoupled from

identity

Manifest-Version: 1.0Bundle-SymbolicName: \

com.mycompany.devices

Export-Package: \com.mycompany.pc; \

uses:="foo.tools.powerplug”

...

MANIFEST.MF

module com.mycompany.devices {

exports com.mycompany.pc;

requires public foo.tools;

...

}

module-info.java

Me

Consumer

Foo

I used a powerplug from Foo! You may need it!

I used somethingfrom Foo tools,

so you now depend on Foo tools

as well!

JPMS

Page 51: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Buzzword compliant Modularity Maturity Model

JuServices OSGi

JPMS

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

Not fully decoupled from identity!

OK!

Page 52: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

OSGiLevel 4decoupled fromimplementation

Artifact

Artifact

RequirementNeed toconnectdevice to

power outlet!

CapabilityCan

connectdevice to

power outlet!

RESOLVER

Bundles with custommetadata

Requirements andCapabilities with LDAP like filters

Bundle lifecycle eventsand listeners

Extender pattern

Nothing OOTB. Use OSGi :)

Probably doable viaexternal resolverdynamic modules andlayers

JEE or 3rd partysolutions on top of JSR376 may providesolutions

JPMS

Page 53: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Buzzword compliant Modularity Maturity Model

JuServices OSGi

JPMS

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

Not fully decoupled from identity!

Some very basic APIs only!

OK!

Page 54: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

OSGiLevel 5

decoupled fromownership & time

JuServices

Artifact

Artifact

REGISTRY

Service

Service

Service

Service

Service registry withmetadata

Finding services viaLDAP like filters

Service lifecycle,events and listeners

Multiple componentframeworks

Whiteboard pattern

Traditional JavaServiceLoader (not dynamic) moved tomodule descriptor

Alternative: minimalstandalone Javaapplications withexternal servicediscovery

JPMS

Page 55: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Buzzword compliant Modularity Maturity Model

JuServices OSGi

JPMS

Level 1 Monolith

Level 2 Composite

Level 3 Containers

Level 4 Discovery

Level 5

Not fully decoupled from identity!

Very limited service layer! DIY dynamism!

OK!OK!

Some very basic APIs only!

Page 56: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Does this mean JPMSgot modularity wrong?

Page 57: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

When they say

modular Java it means

just what theychoose it to mean -

neither more nor less!

Page 58: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

JPMS solves some issues in Java platform!

Level 5 modularity was never one of them!

Reliableconfiguration

Strongencapsulation

A scalable Java SEPlatform

Greater platformintegrity

Improvedperformance

Page 59: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

“... once modularizationbecomes part of theJava core tool set,

developers will begin toembrace it en-masse,

and as they do so, theywill seek more robust

and more maturesolutions. Enter OSGi!”

Victor Grazi

Page 60: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Whenan application

needs modularity

at higher level ?

Page 61: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

The essence ofmodularity is

Not knowing

Page 62: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

1 platform

over 100 apps

over 600 modules

over 2500 μServices

Some examples of how

deals with not knowing

The essence ofmodularity is

Not knowing

Page 63: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Require-Capability: \osgi.contract; \filter:="(&(osgi.contract=JavaJAXRS)(version=2))"

Provide-Capability: \ osgi.contract; \ osgi.contract=JavaJAXRS; \ Uses:= "javax.ws.rs, \

javax.ws.rs.core, \javax.ws.rs.client, \ javax.ws.rs.container, \javax.ws.rs.ext"; \

version:Version=2

Some examples of how

deals with not knowing

The essence ofmodularity is

Not knowing

Page 64: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

@Component( immediate = true, property = {"javax.portlet.name=other_Portlet"}, service = PortletFilter.class)public class MyFilter implements RenderFilter {

...

Some examples of how

deals with not knowing

The essence ofmodularity is

Not knowing

Page 65: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

@Component( immediate = true, property = {"destination.name=" + MONITORING}, service = {MessageListener.class})public class MonitoringMessageListener ...

@Reference( cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY ) protected synchronized void registerProcessor(

...

Some examples of how

deals with not knowing

The essence ofmodularity is

Not knowing

Page 66: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

The essence ofmodularity is

Not knowing

Which enforcesoptimization forPredictability

Page 67: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

Which results inapplicationAgility

The essence ofmodularity is

Not knowing

Which enforcesoptimization forPredictability

Page 68: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov
Page 69: Javantura v4 - What’s NOT new in modular Java - Milen Dyankov

[email protected]@MilenDyankov

http://www.liferay.com@Liferay