Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
-
Upload
nikita-lipsky -
Category
Software
-
view
488 -
download
3
Transcript of Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
![Page 1: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/1.jpg)
Java 9 Modules. The Duke Yet Lives That OSGi Shall Depose
Nikita Lipsky
Excelsior LLC
1
![Page 2: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/2.jpg)
2
![Page 3: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/3.jpg)
Modules in IDE
3
![Page 4: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/4.jpg)
Modules in Mavencom.foo
app1.0
com.fooparse-api
2.0
com.foopersist-api
3.0
org.apachecommons
2.1
org.apachecommons-io
3.14
![Page 5: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/5.jpg)
Modules in Mavencom.foo
app1.0
com.fooparse-api
2.0
com.foopersist-api
3.0
org.apachecommons
2.1
org.apachecommons
3.15
![Page 6: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/6.jpg)
OSGi
6
![Page 7: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/7.jpg)
Why Jigsaw is not OSGi?
Mark Reinhold (the Chief Architect of the Java Platform Group):
“…As it (OSGi) stands, moreover, it’s useful for library and application modules but, since it’s built strictly on top of the Java SE Platform, it can’t be used to modularize the Platform itself”
7
![Page 8: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/8.jpg)
Why Jigsaw is not OSGi?
Question: why the presence of j.l.Object in Java Language Specification, implemented in Java in turn, does not lead to a bootstrap problem?
Факт: Существует реализация Java SE, где OSGi поддерживается на уровне JVM (на уровне платформы).
8
![Page 9: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/9.jpg)
Why Jigsaw is not OSGi?
Question: why the presence of j.l.Object in Java Language Specification, implemented in Java in turn, does not lead to a bootstrap problem?
Fact: There is a Java SE implementation that supports OSGi at the JVM level (at the platform level).
9
![Page 10: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/10.jpg)
Nikita Lipsky• 20+ years in software development
• Excelsior JET project initiator– 16+ years of contributions– compiler engineer – team lead– product lead– etc.
• Twitter: @pjBooms
10
![Page 11: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/11.jpg)
Excelsior JET?• AOT-centric Java SE implementation
– certified as Java Compatible since 2005
• AOT compiler + Java Runtime– mixed compilation: AOT + JIT– AOT support for custom classloaders (Eclipse RCP, Tomcat)
• Toolkit– Startup Optimizer– Deployment
11
![Page 12: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/12.jpg)
Agenda
• Why OSGi
• How OSGi does it
• Why NOT OSGi
• Why Jigsaw is not OSGi
• Jigsaw mantra
• Jigsaw problems
12
![Page 13: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/13.jpg)
Where OSGi?
Standardized by OSGi Alliance (IBM, Adobe, Bosch, Huawei, NTT, Oraсle)
Implementations:
• Equinox – Eclipse IDE, Eclipse RCP, IBM Websphere
• Apache Felix– Oracle WebLogic, Glassfish, Netbeans
13
![Page 14: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/14.jpg)
Why OSGi?
14
![Page 15: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/15.jpg)
Why OSGi?• Modularity
– Reduced complexity– Hide internals (encapsulation)– Dependency management and easy deployment
• Dynamic updates• Versioning• Lazy• Simple, fast, small, secure, etc.https://www.osgi.org/developer/benefits-of-using-osgi/
15
![Page 16: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/16.jpg)
Модульная система OSGi
16
![Page 17: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/17.jpg)
OSGi Module SystemOSGi module – Bundle:• Jar or directory• Import/export is defined in META-INF/MANIFEST.MF:
Manifest-Version: 1.0 Bundle-ManifestVersion: 2
Bundle-SymbolicName: B
Bundle-Version: 1
Bundle-Name: B Bundle
Export-Package: org.bar
Import-Package: org.foo;version=“[1,2)”
17
![Page 18: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/18.jpg)
OSGi Module System
• OSGi bundle imports/exports
– packages (Import-Package/Export-Package)
– services (Import-Service/Export-Service).
• May import other bundles directly
– Require-Bundle directive
– However it is not the best practice (less flexible)
18
![Page 19: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/19.jpg)
OSGi Module System
19
Bundle A
Class ABundle B
Class B
Bundle C
Class CExport-Package: packageCImport-Package: packageA
Export-Package: packageAI
Import-Package: packageA,packageC
![Page 20: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/20.jpg)
OSGi Runtime
• Resolves Import/Export of OSGi bundles(wiring)
• Defines bundle life cycle
– May start (activate) bundles lazily
– Enables on-the-fly bundle updates without system restart (aka hot redeploy).
20
![Page 21: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/21.jpg)
Jar/Classpath HellApp1.0
LibraryFoo2.0
LibraryBar3.0
LibraryBaz2.1
LibraryBaz3.1
21
![Page 22: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/22.jpg)
Versioning in OSGi
• OSGI resolves JAR hell:
– import/export is qualified by version
– If two bundles require a library bundle of two different versions, both versions will be loaded
22
![Page 23: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/23.jpg)
Why OSGi?So, OSGi promises:• Modularity
– explicit dependencies– encapsulation
• JAR Hell problem resolution– via versioning
• Hot ReDeploy– via ability to update a separate bundle dynamically
23
![Page 24: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/24.jpg)
Why OSGi?So, OSGi promises:• Modularity
– explicit dependencies– encapsulation
• JAR Hell problem resolution– via versioning
• Hot ReDeploy– via ability to update a separate bundle dynamically
24
![Page 25: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/25.jpg)
Why OSGi?So, OSGi promises:• Modularity
– explicit dependencies– encapsulation
• JAR Hell problem resolution– via versioning
• Hot ReDeploy– via ability to update a separate bundle dynamically
25
![Page 26: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/26.jpg)
Why OSGi?So, OSGi promises:• Modularity
– explicit dependencies– encapsulation
• JAR Hell problem resolution– via versioning
• Hot ReDeploy– via ability to update a separate bundle dynamically
26
![Page 27: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/27.jpg)
27
![Page 28: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/28.jpg)
How OSGi?
28
![Page 29: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/29.jpg)
Versioning in OSGi
Question: How to implement versioning?
Task: For given A module importing Lib (v1) library, and B module importing Lib (v2), it is required that both versions of Lib working without conflicts.
Solution: load the versions of the library by different classloaders.
29
![Page 30: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/30.jpg)
Versioning in OSGi
Question: How to implement versioning?
Task: For a given module A importing library Lib (v1), and module B importing Lib (v2), it is required that both versions of Lib work without conflicts.
Solution: load the versions of the library by different classloaders.
30
![Page 31: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/31.jpg)
Versioning in OSGi
Question: How to implement versioning?
Task: For a given module A importing library Lib (v1), and module B importing Lib (v2), it is required that both versions of Lib work without conflicts.
Solution: load versions of the library by different classloaders.
31
![Page 32: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/32.jpg)
Versioning in OSGi
Thus each OSGi bundle is loaded by its own classloader:
• Subtype of java.lang.ClassLoader
• Unique class namespace
• No conflicts with classes of other bundles
32
![Page 33: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/33.jpg)
Versioning in OSGi
33
com.fooApp1.0
com.fooparse-api
2.0
com.foopersist-api
3.0
org.apachecommons
2.1
org.apachecommons
3.1
CL
CL
CL
CL
CL
Different versions of apache commons may simultaneously present in the JVM
Each bundle hasits own classloader
![Page 34: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/34.jpg)
Encapsulation in OSGi
34
![Page 35: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/35.jpg)
Encapsulation in OSGisrc/com/foo/exported/A.java:
package com.foo.exported;
import com.foo.internal.B;
public class A {B useB;
}
src/com/foo/internal/B.java:
package com.foo.internal;
public class B {
}
How to make the class B inaccessible from outside?
35
![Page 36: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/36.jpg)
Encapsulation in OSGi
Question: how to make an internal class of a module declared public inaccessible outside?
36
![Page 37: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/37.jpg)
Encapsulation in OSGi
Question: how to make an internal class of a module declared public inaccessible outside?
Answer: classloaders (!) may hide internal classes.
37
![Page 38: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/38.jpg)
Dynamic Updates
Task: update one (!) changed bundle in a running program without stopping it
38
![Page 39: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/39.jpg)
Dynamic Updates
Task: update one (!) changed bundle in a running program without stopping it
Solution: CLASSLOADERS!
(unload old bundle, load new bundle by a new classloader)
39
![Page 40: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/40.jpg)
Bundle life cycle
40
![Page 41: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/41.jpg)
Lazy start
Start of bundles in OSGi is implemented via the bundle activators feature:• Each bundle may have an activator
– Bundle-Activator manifest directive– Implementation of an interface with methods start(), stop()
– Static class initializer analogue for bundles
41
![Page 42: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/42.jpg)
Lazy start
Start of bundles in OSGi is implemented via the bundle activators feature:
public interface BundleActivator {void start(BundleContext context) throws Exception;void stop(BundleContext context) throws Exception;
}
42
![Page 43: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/43.jpg)
Lazy start
• Bundle start can be defined by OSGi configuration
• Otherwise the bundle starts when it is required by other started bundles
43
![Page 44: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/44.jpg)
Lazy start
Task: start (load) bundles only when they become needed for program execution
44
![Page 45: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/45.jpg)
Lazy start
Solution: CLASSLOADERS (again!) in OSGi invoke the start()method of the bundle activator right before loading of the first class of a bundle
Since classloading in the JVM is lazy, bundle activation becomes lazy AUTOMATICALLY
45
![Page 46: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/46.jpg)
Lazy start
Solution: CLASSLOADERS (again!) in OSGi invoke the start()method of the bundle activator right before loading of the first class of a bundle
Since classloading in the JVM is lazy, bundle activation becomes lazy AUTOMATICALLY
46
![Page 47: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/47.jpg)
Lazy start
Solution: CLASSLOADERS (again!) in OSGi invoke the start()method of the bundle activator right before loading of the first class of a bundle
Since classloading in the JVM is lazy, bundle activation becomes lazy AUTOMATICALLY
47
![Page 48: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/48.jpg)
How OSGi?
All solved in one fell swoop!48
![Page 49: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/49.jpg)
49
![Page 50: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/50.jpg)
Why Not OSGi?
50
![Page 51: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/51.jpg)
Modularity?Bundle A
Bundle B
51
![Page 52: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/52.jpg)
Modularity?Bundle A
Bundle B Bundle C
52
![Page 53: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/53.jpg)
Modularity?Bundle A
Bundle B Bundle C
Bundle D
53
![Page 54: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/54.jpg)
Modularity?Bundle A
Bundle B Bundle C
Bundle D
54
![Page 55: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/55.jpg)
Modularity?Bundle A
Bundle B Bundle C
Bundle D
55
![Page 56: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/56.jpg)
Modularity?Bundle A
Bundle B Bundle C
Bundle D
56
![Page 57: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/57.jpg)
Modularity?
OSGI allows cycles in
the dependency graph
Exercise: understand, why
that is bad
A
B C
D
57
![Page 58: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/58.jpg)
On the fly updates?
58
![Page 59: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/59.jpg)
On the fly updates?
Bundle ABundle B
59
![Page 60: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/60.jpg)
On the fly updates?
Bundle ABundle B
Let’s update bundle B
60
![Page 61: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/61.jpg)
On the fly updates?
Bundle ABundle B
61
![Page 62: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/62.jpg)
On the fly updates?
Bundle A
Bundle B
62
![Page 63: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/63.jpg)
On the fly updates?
Bundle A
NEWBundle B
63
![Page 64: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/64.jpg)
On the fly updates?
Bundle ANEWBundle B
64
![Page 65: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/65.jpg)
On the fly updates?
Bundle ABundle B
Does it work for bundle A?
65
![Page 66: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/66.jpg)
On the fly updates?
Bundle B
Class B
Bundle A
Class А
66
![Page 67: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/67.jpg)
On the fly updates?
Bundle B
Class B
Bundle A
Class А
If bundle B imports bundle А then there is a class from B that references a class from A
67
![Page 68: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/68.jpg)
Symbolic references resolution
B.java:class B {
A useA;int f1 = A.f;int f2 = A.foo();
}
A.java:class A {
static int f;static int foo(){};
}68
![Page 69: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/69.jpg)
Symbolic references resolution
69
B.class…
CONSTANT_Class: A
CONSTANT_FieldRef: A.f@int
CONSTANT_MethodRef: A.foo()I
…
A.class…
Field: f@int
Method: foo()I
…
![Page 70: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/70.jpg)
Symbolic references resolution
• A class references other classes and their fields/methods symbolically
70
![Page 71: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/71.jpg)
Symbolic references resolution
• A class references other classes and their fields/methods symbolically
• JVM resolves those symbolic references with real values at runtime
71
![Page 72: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/72.jpg)
Symbolic references resolution
• A class references other classes and their fields/methods symbolically
• JVM resolves those symbolic references with real values at runtime
• Once a reference is resolved, the value of the reference is never changed!
72
![Page 73: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/73.jpg)
On the fly updates?
• If a reference from a class B to a class A is resolved then the class А cannot be unloadedfrom the JVM without unloading the class B
73
![Page 74: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/74.jpg)
On the fly updates?
• If a reference from a class B to a class A is resolved then the class А cannot be unloadedfrom the JVM without unloading the class B
• Hence if a bundle В imports a bundle А then the bundle А cannot be unloaded without also unloading the bundle B
74
![Page 75: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/75.jpg)
On the fly updates?
Bundle ABundle B
Let’s update bundle A
75
![Page 76: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/76.jpg)
On the fly updates?
Bundle ABundle B
76
![Page 77: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/77.jpg)
On the fly updates?
Bundle A
Bundle B
77
![Page 78: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/78.jpg)
On the fly updates?
Бандл ABundle B
78
![Page 79: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/79.jpg)
On the fly updates?
Now let’s remember
cyclic dependencies
Exercise: try to update
SWT bundle in running Eclipse
A
B C
D
79
![Page 80: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/80.jpg)
80
![Page 81: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/81.jpg)
On the fly updates?
• On the fly updates in OSGi work, more or less, only for leaf bundles that are not imported by other bundles – plugins
81
![Page 82: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/82.jpg)
On the fly updates?
• On the fly updates in OSGi work, more or less, only for leaf bundles that are not imported by other bundles – plugins
• There are much simpler ways than OSGi to implement plugins
82
![Page 83: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/83.jpg)
On the fly updates?
Even leaf bundles are not so easy to unload from the JVM:
• The classes from leaf bundles can live in the JVM after their unloading
– Known problem: Classloaders Memory Leak
83
![Page 84: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/84.jpg)
One does not simply
unload a class from the JVM84
![Page 85: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/85.jpg)
Versioning?
85
![Page 86: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/86.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
86
![Page 87: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/87.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
87
![Page 88: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/88.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
A
88
![Page 89: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/89.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
A A
89
![Page 90: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/90.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
A
A
90
![Page 91: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/91.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
A A
91
![Page 92: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/92.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
A A
92
![Page 93: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/93.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
A A
I’m “A”!
93
![Page 94: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/94.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
A A
I’m “A”!No, I’m
“A”!
94
![Page 95: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/95.jpg)
Versioning?App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
AAAAA!AAAAA!
AA
95
![Page 96: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/96.jpg)
96
![Page 97: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/97.jpg)
Loading constraints
• Loading constraints prohibit two classes with the same fully qualified name to appear in the namespace of another class
97
![Page 98: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/98.jpg)
Loading constraints
B.java:class B {
T1 f1 = A.f;int f2 = A.m(t2);
}
A.java:class A {
static T1 f;static int m(T2 t)
If B is loaded by L1 classloader and A is loaded by L2 then the JVM will check that (T1, L1) = (T1, L2) and (T2, L1) = (T2, L2)
==
98
![Page 99: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/99.jpg)
Versioning?
• JVM throws java.lang.LinkageError on loading constraints violation
99
![Page 100: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/100.jpg)
Versioning?
• JVM throws java.lang.LinkageError on loading constraints violation
• OSGi DOES NOT help developers to avoid loading constraints violation
– Just google for “OSGI” and “LinkageError” to estimate the scale of the problem
100
![Page 101: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/101.jpg)
Versioning?
There are bundles in the latest Eclipse versions with potential loading constraints violations and nobody cares!
101
![Page 102: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/102.jpg)
Versioning?
Conclusion: OSGi does not solve JAR Hell but raises it to a new, more sophisticated level.
102
![Page 103: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/103.jpg)
Versioning?
Conclusion: Do not use two different versions of the same library in one application!
103
![Page 104: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/104.jpg)
Encapsulation?
Question: well, at least the encapsulation problem is solved by OSGi, right?
104
![Page 105: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/105.jpg)
Reflection – universal countermeasure
against encapsulation in Java
Encapsulation?
setAccessible(true)
105
![Page 106: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/106.jpg)
Encapsulation?
Question: well, at least the encapsulation problem is solved by OSGi, right?
Answer: OSGi does not protect from unauthorized access via Reflection
106
![Page 107: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/107.jpg)
Lazy start?
107
![Page 108: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/108.jpg)
Lazy start?
108
![Page 109: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/109.jpg)
Lazy start?Bundle A
Bundle B Bundle C
Question: in what order the bundles will be activated?
109
![Page 110: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/110.jpg)
Lazy start?
Bundle activation order in OSGi depends on classloading order directly
– A bundle is started from loadClass() of the bundle classloader
110
![Page 111: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/111.jpg)
Lazy start?
Bundle activation order in OSGi depends on classloading order directly
– A bundle is started from loadClass() of the bundle classloader
However, class loading order is not defined by the JVM specification!
111
![Page 112: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/112.jpg)
Symbolic references resolutionA class may reference other classes and their fields/methods symbolically. A JVM may resolve references:
• Lazily– Each reference is resolved on first access
• Eagerly– All references are resolved at the time of class loading
112
![Page 113: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/113.jpg)
Lazy start?
The classloading order depends on the class reference resolution scheme in the given JVM implementation: lazy, less lazy, eager.
113
![Page 114: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/114.jpg)
Lazy start?
Bundle B activator:class B implements BundleActivator {
public void start() {assert A.f!= null;
}
Bundle A activator:class A implements BundleActivator {
static T f;public void start() {
f = new T();}
Typical case: В thinks that А is already activated, but in fact А can be activated after B, so assertion fails
114
![Page 115: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/115.jpg)
Lazy start?
• Bundle activation scheme in OSGi is a time bomb:
– If the JVM starts to resolve class references less lazily, practically all OSGi applications will stop working
115
![Page 116: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/116.jpg)
Why NOT OSGi?
• Modularity with cycles
• Hot Redeploy works for leaf bundles only
• No protection from loading constraints violation
• No protection of implementation details from reflective access
• Bundle activation order depends substantially on class reference resolution scheme
116
![Page 117: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/117.jpg)
Jigsaw
117
![Page 118: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/118.jpg)
Jigsaw
118
![Page 119: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/119.jpg)
Jigsaw vs. OSGi
OSGi is dynamic essentially
– modules appear at run time only
119
![Page 120: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/120.jpg)
Jigsaw vs. OSGi
Jigsaw was thought up as static from the beginning.
Practically all JDK tools know about modules:– javac: respects modules visibility rules
– jdeps: analyses dependencies
– jar, jmod: pack modules
– jlink: prepares final image for deployment
– java: there are modules in runtime as well
120
![Page 121: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/121.jpg)
Module example// src/java.sql/module-info.javamodule java.sql {
requires transitive java.logging;requires transitive java.xml;
exports java.sql;exports javax.sql;exports javax.transaction.xa;uses java.sql.Driver;
}
121
![Page 122: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/122.jpg)
Jigsaw vs. OSGi
Jigsaw prohibits (explicit) cycles
in the dependency graph
Modules import modules
and not packages.
122
![Page 123: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/123.jpg)
Versioning
There was versioning in the first drafts of Jigsaw (similar to OSGi).
123
![Page 124: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/124.jpg)
Versioning
There was versioning in the first drafts of Jigsaw (similar to OSGi).
However versioning was removed later …
124
![Page 125: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/125.jpg)
Versioning
There was versioning in the first drafts of Jigsaw (similar to OSGi).
However versioning was removed later …
Why?
125
![Page 126: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/126.jpg)
Versioning
Versioning immediately means:
1 module 1 classloader
126
![Page 127: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/127.jpg)
Versioning
Versioning immediately means:
1 module 1 classloader
It was exactly so in the first Jigsaw drafts!
127
![Page 128: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/128.jpg)
Jigsaw and classloaders
Jigsaw is not just modules, but also the Java SE platform split into modules.
128
![Page 129: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/129.jpg)
Jigsaw and classloaders
Backward compatibility problem:
According to the specification
getClassloader() == nullfor core platform classes.то противоречит
That precludes splitting of the platform into modules, with each module loaded by its loader
129
![Page 130: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/130.jpg)
Jigsaw and classloaders
Backward compatibility problem:
According to the specification
getClassloader() == nullfor core platform classes.то противоречит
That precludes splitting of the platform into modules, with each module loaded by its loader
130
![Page 131: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/131.jpg)
Jigsaw and classloaders
Problem 2: How to protect developers from loading constraints violation?
131
![Page 132: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/132.jpg)
Versioning
Another detail: import in early Jigsaw versions (as in OSGi) was qualified by not a single version but by а version range:
– A module may declare that it can work with a dependency of “from” version to “to” version
132
![Page 133: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/133.jpg)
Versioning
Problem 3: Resolving dependencies (wiring modules) from version ranges is an NP-complete problem!
– Reduced to 3-SAT
133
![Page 134: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/134.jpg)
Versioning
… after that versioning in JPMS breathed its last.
134
![Page 135: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/135.jpg)
Versioning
… after that versioning in JPMS breathed its last.
No versioning – no classloaders for modules.
135
![Page 136: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/136.jpg)
Jigsaw
• No dynamic updates
• No versioning
136
![Page 137: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/137.jpg)
Jigsaw
• No dynamic updates
• No versioning
So what does it have?
137
![Page 138: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/138.jpg)
Jigsaw Mantra
Reliable Configuration
Strong Encapsulation
138
![Page 139: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/139.jpg)
Reliable Configuration
Такая ситуация в Jigsaw просто запрещена!
App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
139
![Page 140: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/140.jpg)
Reliable Configuration
Jigsaw simply prohibits this situation!
App1.0
Foo2.0
Bar3.0
Baz2.1
Baz3.1
140
![Page 141: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/141.jpg)
Reliable Configuration
Right (reliable) configuration:
App1.0
Foo2.5
Bar3.0
Baz3.1
141
![Page 142: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/142.jpg)
Reliable Configuration
Reliable configuration:
• All module dependencies are resolved
• No cyclic dependencies
• No modules containing the same packages (split packages)
These properties are checked at startup (wiring)
142
![Page 143: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/143.jpg)
Strong Encapsulation
setAccessible(true)
143
![Page 144: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/144.jpg)
Strong Encapsulation
Java 9 modules are first class citizens
• Define visibility access rules
– via declared export
• There is no access to non-exported functionality outside of the module even via reflection
– Even setAccessible(true) does not work
144
![Page 145: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/145.jpg)
Strong Encapsulation
Java 9 modules are first class citizens
• Define visibility access rules
– via declared export
• There is no access to non-exported functionality outside of the module even via reflection
– Even setAccessible(true) does not work
145
![Page 146: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/146.jpg)
Strong Encapsulation
Java 9 modules are first class citizens
• Define visibility access rules
– via declared export
• There is no access to non-exported functionality outside of the module even via reflection
– Even setAccessible(true) does not work
146
![Page 147: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/147.jpg)
So Jigsaw does not have problems?
147
![Page 148: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/148.jpg)
148
![Page 149: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/149.jpg)
Reliable Configuration?
• Reflective access was prohibited between modules without explicit dependencies in early Jigsaw drafts
• However it had to be relaxed when classloaders had gone from JPMS– because Class.forName() has to work
backward compatible
149
![Page 150: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/150.jpg)
Reliable Configuration?
• Reflective access was prohibited between modules without explicit dependencies in early Jigsaw drafts
• Had to be relaxed when classloaders had gone from JPMS– because Class.forName() had to remain
backward compatible
150
![Page 151: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/151.jpg)
Reliable Configuration?
However if you may have reflective dependencies that are not explicitly declared, where is the guarantee that the resulting configuration is reliable?
151
![Page 152: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/152.jpg)
Reliable Configuration?
Split packages are prohibited, but what about application containers (Tomcat, Java EE)?
152
![Page 153: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/153.jpg)
Jigsaw Layers *
To solve the application containers problem
Layers feature was introduced in JPMS:
• Local module system for each application in a container
• Two modules containing the same package have to belong to different layers
153
![Page 154: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/154.jpg)
Jigsaw Layers *
* The picture is from Alex Buckley’s presentation: Project Jigsaw Under the hood154
![Page 155: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/155.jpg)
Strong Encapsulation?
155
![Page 156: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/156.jpg)
Strong Encapsulation?
The platform is split into modules:
• Which means that private APIs become really private
156
![Page 157: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/157.jpg)
Strong Encapsulation?
The platform is split into modules:
• Which means that private APIs become really private
• But what about
sun.misc.Unsafe ?
157
![Page 158: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/158.jpg)
Strong Encapsulation?
Ok, Java community (temporarily)
defended sun.misc.Unsafe (in an unequal fight)!
158
![Page 159: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/159.jpg)
Strong Encapsulation?
But what about Dependency Injection?
159
![Page 160: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/160.jpg)
Strong Encapsulation?
DI frameworks essentially depend on:
• reflective access to the code in which they inject dependencies
• including non-exported code
160
![Page 161: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/161.jpg)
Strong Encapsulation?
module my.module {exports my.module.pack;
}
161
![Page 162: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/162.jpg)
Strong Encapsulation?
module my.module {exports my.module.pack;exports my.module.internal.object.orgy;
}
162
![Page 163: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/163.jpg)
Strong Encapsulation?
module my.moduleO{
exports my.module.pack;}
163
![Page 164: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/164.jpg)
Strong Encapsulation?
open module my.module {
exports my.module.pack;}
164
![Page 165: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/165.jpg)
Strong Encapsulation?
Open modules were introduced to solve the DI frameworks problem:
• An open module allows reflective access to its non-exported functionality
165
![Page 166: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/166.jpg)
Strong Encapsulation?
Open modules provide not-so-strong encapsulation, but it is better than nothing.
166
![Page 167: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/167.jpg)
Jigsaw
Well, but what benefits me in Jigsaw at last?
167
![Page 168: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/168.jpg)
Jigsaw benefitsIf all your dependencies are on the classpath now, migrating to the modulepath would improve the architecture of your application by eliminating:• cycles in the dependencies• split packages (jar hell)• unsound access into implementation details of
other modules• dependencies to JDK private API
168
![Page 169: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/169.jpg)
Jigsaw benefitsIf all your dependencies are on the classpath now, migrating to the modulepath would improve the architecture of your application by eliminating:• cycles in the dependency graph• split packages (jar hell)• unsound access into implementation details of
other modules• dependencies to JDK private API
169
![Page 170: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/170.jpg)
Jigsaw benefitsIf all your dependencies are on the classpath now, migrating to the modulepath would improve the architecture of your application by eliminating:• cycles in the dependency graph• split packages (jar hell)• unsound access into implementation details of
other modules• dependencies to JDK private API
170
![Page 171: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/171.jpg)
Jigsaw benefitsIf all your dependencies are on the classpath now, migrating to the modulepath would improve the architecture of your application by eliminating:• cycles in the dependency graph• split packages (jar hell)• unsound reliance upon implementation details of
other modules• dependencies to JDK private API
171
![Page 172: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/172.jpg)
Jigsaw benefitsIf all your dependencies are on the classpath now, migrating to the modulepath would improve the architecture of your application by eliminating:• cycles in the dependency graph• split packages (jar hell)• unsound reliance upon implementation details of
other modules• dependencies on JDK private APIs
172
![Page 173: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/173.jpg)
Jigsaw benefits
Jigsaw introduces a migration path to the modulepath:
• Old classpath forms Unnamed Modulе
• Jars from classpath may be temporally moved as is to modulepath as Auto Modules
• Module declaration can be added to auto modules later
173
![Page 174: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/174.jpg)
Jigsaw benefits
Jigsaw introduces a migration path to the modulepath:
• Old classpath forms Unnamed Module
• Jars from classpath may be temporally moved as is to modulepath as Auto Modules
• Module declaration can be added to auto modules later
174
![Page 175: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/175.jpg)
Jigsaw benefits
Jigsaw introduces a migration path to the modulepath:
• Old classpath forms Unnamed Modulе
• Jars from classpath may be temporarily moved “as-is” to modulepath as Auto Modules
• Module declaration can be added to auto modules later
175
![Page 176: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/176.jpg)
Jigsaw benefits
Jigsaw introduces a migration path to the modulepath:
• Old classpath forms Unnamed Modulе
• Jars from classpath may be temporarily moved “as-is” to modulepath as Auto Modules
• Module declaration can be added to auto modules later
176
![Page 177: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/177.jpg)
Jigsaw benefitsUnfortunately, most Java developers won’t benefit from JPMS immediately:• Java EE standards do not define how they will
interoperate with JPMS yet• Even servlet containers standard knows nothing
about modules so far– Dependencies in war файлах are essentially old plain
classpath!
177
![Page 178: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/178.jpg)
Jigsaw benefitsUnfortunately, most Java developers won’t benefit from JPMS immediately:• Java EE standards do not define how they will
interoperate with JPMS yet• Even the servlet container standard knows
nothing about modules so far– Dependencies in war files are old plain classpath in
fact!
178
![Page 179: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/179.jpg)
The birth is inevitable!
179
![Page 180: Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose](https://reader031.fdocuments.us/reader031/viewer/2022022415/5a64aa9a7f8b9a36568b5415/html5/thumbnails/180.jpg)
Conclusion• OSGi is a nice attempt to give modules to Java
developers– but OSGi has many problems unfortunately– including fundamental
• Jigsaw is a carefully designed system without visible fundamental problems– but with a system of checks and balances– there are community acceptance problems
180