Presentation by Peter Kriens at OSGi Users' Forum UK meeting on Nov 16, 2011 in London.
Abstract: The OSGi Service Platform is a standard that specifies a comprehensive model of modules that communicate through a powerful, no overhead, Inter Module Communication mechanism: OSGi Services. OSGi enforces module-level isolation that forbids ad hoc cross-module class loading but this conflicts with prevalent Java software patterns that assume application-wide class visibility. OSGi Connect proposes the OSGi programming model without the module-level isolation. This presentation will show you how you can use OSGi Connect to begin to modularize your existing applications with the OSGi programming model with a minimal upfront investment.
5. 1. Ad Hoc
• Flat, manual class path
• Single name space
• Full visibility and normal
accessibility
• Monolithic
• Highly coupled
• Split Packages
• Add/Shuffle JARs until it works
woensdag 16 november 11
6. 1. Ad Hoc
• Flat, manual class path
• Single name space
e l l
H
• Full visibility and normal
accessibility
• Monolithic
AR
•
•
Highly coupled
Split Packages J
• Add/Shuffle JARs until it works
woensdag 16 november 11
7. 2. Managed
• Treat JARs as a module
• JAR Identity
• Naming
• Versioning
• Dependencies
• Repositories
woensdag 16 november 11
8. 2. Managed
a d
• Treat JARs as a module
n l o
w he t
• JAR Identity
• Naming
D o t
• Versioning
r n e
• Dependencies
n t e
• Repositories
i
woensdag 16 november 11
9. 3. Contracts
• Interface based design,
POJOs
• Provide contracts for
each connection
between JARs
• Implementation details
inside the JAR
• Versioning on contracts
woensdag 16 november 11
10. 3. Contracts
•
d e r
a
Interface based design,
o
POJOs
• Provide contracts for
l s
s k
s c
a a
each connection
l h
between JARs
• Implementation details
inside the JAR c
• Versioning on contracts
woensdag 16 november 11
11. 4. Fences
• Explicitly Import/Export
packages
• Explicitly specify
requirements and capabilities
• Enforce the module
boundaries
• Semantic Versioning
• Side-by-side versioning
supported
woensdag 16 november 11
12. 4. Fences
• Explicitly Import/Export
packages
• Explicitly specify
requirements and capabilities
o d!
•
•
Enforce the module
boundaries
Semantic Versioning
Go
• Side-by-side versioning
supported
woensdag 16 november 11
13. 5. Optimize
• Exploit concepts for
modules and contracts
• Delegated Control
• Optimize the code base to
leverage new patterns:
• Extender
• Whiteboard
• Repeat
woensdag 16 november 11
14. 5. Optimize
• Exploit concepts for
modules and contracts
• Delegated Control
• Optimize the code base to
leverage new patterns:
• Extender
• Whiteboard
• Repeat
woensdag 16 november 11
15. Today
1.
Ad Hoc
2. 3.
Managed Contracts
4.
Fences
5.
Optimize
woensdag 16 november 11
16. Today
1.
Ad Hoc Enterprise
DI
vn ,C
m ice ing
2. 3.
Ivy Managed Contracts
gu r
saw sp
jig
4.
Fences
5.
Optimize
woensdag 16 november 11
17. Today
1.
Ad Hoc Enterprise
DI
vn ,C
m ice ing
2. 3.
Ivy Managed Contracts
gu r OSGi
saw s p
jig
4.
Fences
5.
Optimize
woensdag 16 november 11
18. Today
1.
Ad Hoc Enterprise
DI
vn ,C
m ice ing
2. 3.
Ivy Managed Contracts
gu r OSGi
saw s p
jig
4.
Fences
5.
Optimize
woensdag 16 november 11
50. 5. Optimize
A B C
D E F
G H I
woensdag 16 november 11
51. Back to the Brick Wall
woensdag 16 november 11
52. Migration
A B C
D E F
G H I
woensdag 16 november 11
53. Migration
A B C
D E F
G H I
woensdag 16 november 11
54. Migration
A B C
D E F
G H I
woensdag 16 november 11
55. Migration
A B C
D E F
G H I
woensdag 16 november 11
56. Migration
A B C
D E F
G H I
woensdag 16 november 11
57. So we need a broker
that runs without
fences...
woensdag 16 november 11
58. So we need a Broker
that runs without
Fences...SR
o j o
P
woensdag 16 november 11
59. POJOSR
• Developed by Karl Pauls
• JavaOne presentation 24811
• http://pojosr.googlecode.com
• Based on Apache Felix
woensdag 16 november 11
60. Gain
• Existing libraries and many bundles work without
modification
• Bundle (JAR) activation (have their own local main)
• µServices
• Dynamicity (in µServices)
• Extender pattern (react on JAR content)
• Migration path to Fences (OSGi)
• Existing OSGi and non-OSGi tooling can be used
woensdag 16 november 11
61. Loss
• No dynamic install/uninstall/update
• No side-by-side versioning
• No module privacy
• No explicit dependencies
• No Lazy activation
• No Bundle classpath
• No Native Code support
woensdag 16 november 11
62. Migrating
• Example: extend ant … the tool we all
(sometimes) love and (sometimes) hate
• We make different <helloXXX/> tasks
woensdag 16 november 11
63. Ant Your Service
• Base ant
• Activator
• Extender
ant
...
...
woensdag 16 november 11
64. Ant Your Service
• Base ant pojosr
ant
• Activator
• Extender
ant
...
...
woensdag 16 november 11
65. Ant Your Service
• Base ant pojosr
ant
• Activator
• Extender
ant
...
...
woensdag 16 november 11
66. Ant Your Service
Class<Task>
• Base ant pojosr
ant
• Activator
• Extender
ant
...
...
woensdag 16 november 11
67. Ant Your Service
Class<Task>
hello
activator
• Base ant pojosr
ant
• Activator
• Extender
ant
...
...
woensdag 16 november 11
68. Ant Your Service
Class<Task>
hello
activator
• Base ant pojosr
ant
• Activator
• Extender
ant
...
...
woensdag 16 november 11
69. Ant Your Service
<project name="master">
<path id="bundles">
<fileset dir="bundles">
<include name="*.jar" />
</fileset>
</path>
<taskdef name="auto"
classname="aQute.ant.connect.AutoTask" classpathref="bundles" />
<auto />
<helloActivator />
</project>
woensdag 16 november 11
70. Ant Your Service
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
Properties props = new Properties();
props.put("ant", "helloActivator");
context.registerService(Class.class.getName(),
HelloTask.class, props);
}
public void stop(BundleContext context) throws Exception {
}
}
public class HelloTask extends Task {
String message = "Hello Activator";
public void execute() { System.out.println(message); }
public void setMessage(String m) { this.message = m; }
}
woensdag 16 november 11
71. Ant Your Service
public class Activator implements BundleActivator {
t
public void start(BundleContext context) throws Exception {
f
Properties props = new Properties();
u
props.put("ant", "helloActivator");
r
context.registerService(Class.class.getName(),
c
HelloTask.class, props);
}
public void stop(BundleContext context) throws Exception {
}
}
public class HelloTask extends Task {
String message = "Hello Activator";
public void execute() { System.out.println(message); }
public void setMessage(String m) { this.message = m; }
}
woensdag 16 november 11
72. Ant Your Service
Class<Task>
hello
activator
• Base ant pojosr
pojo
ant
• Activator
• Extender
ant
...
...
woensdag 16 november 11
73. Ant Your Service
Class<Task>
hello
activator
• Base ant pojosr
pojo
ant
hello
extendee
• Activator
• Extender
ant
...
...
woensdag 16 november 11
74. Ant Your Service
Class<Task>
hello
activator
• Base ant pojosr
pojo
ant
hello
extendee
• Activator
Manifest-Version: 1.0
• ant Ant-Task: helloExtender=HelloTask
Extender
...
...
woensdag 16 november 11
75. Ant Your Service
public class HelloTask extends Task {
String message = "Hello Extender";
public void execute() { System.out.println(message); }
public void setMessage(String m) { this.message = m; }
}
woensdag 16 november 11
76. Ant Your Service
public class HelloTask extends Task {
String message = "Hello Extender";
public void execute() { System.out.println(message); }
public void setMessage(String m) { this.message = m; }
}
u ft
c r
N O
woensdag 16 november 11
77. Conclusion
• Moving to Fences is hard because popular
instance creation patterns are
fundamentally not modular
• Services-First approach works without
Fences
• After completion, moving to Fences is
much easier
woensdag 16 november 11
78. Good Fences
Make Good Neighbors
woensdag 16 november 11
79. Good Fences
od ul es
Make Good Neighbors
m
woensdag 16 november 11