15. OSGi Basics
Dynamic module system for Java
Features:
• Service registry
• Lifecycle model
• Bundle dependency system
• Optional security layer
16. OSGi Terms
Bundle - Jar file with special OSGi entries in its
manifest and containing classes, resources, and
other jars
Lifecycle - States a bundle goes through:
uninstalled, installed, resolved, starting, stopping,
active
Service - An object instance exposed under the
one or more interfaces it implements and a map
of properties
20. What does that mean?
• Upgrade bundles (think super jars) at runtime
• Bundles can depend on other bundles at a
service, package, or jar level
• Bundles can hide packages from other bundles
and version exposed packages
23. 1. Ability for plugins to
depend on each other
Plugins can generate their own OSGi headers or:
<plugin-info>
<bundle-instructions>
<Require-Bundle> org.otherPlugin;bundle-
version=quot;[3.2.0,4.0.0)</Require-Bundle>
<Import-Package>
*,org.otherPlugin.api;version=”[3.2.0,4.0.0)” </
Import-Package>
</bundle-instructions>
</plugin-info>
24. 2. Ability for plugins to
define extension points
1. Plugin A exposes its implementation:
<component key=“foo” public=“true”
class=“org.bar.FooImpl” interface=“org.foo.Foo” />
2. Plugin B imports the service:
<component-import key=“foo” interface=“foo.Foo” />
25. 3. Better insulate plugins
from product changes
• Host applications can decide which versioned
packages to expose to plugins
scanner.addPackageIncludes(Arrays.asList(
“com.atlassian.*”,
“org.apache.commons.*”));
• Host applications expose specific host
components:
<bean name=quot;fooquot; class=quot;com.atlassian.
FooableBeanquot; plugin:available=quot;truequot; />
Or
@AvailableToPlugins
public class MyManager implements Manager
{...}
28. Built for integration
Shipped today with Atlassian applications
with different:
• Dependency injection libraries
• Web frameworks
• Persistence frameworks