SE3030 - Lecture 02 - Microkernel Architecture
SE3030 - Lecture 02 - Microkernel Architecture
(Plugin-architecture Pattern)
Software Architecture
3rd Year – Semester 1
By Udara Samaratunge
• A Java framework for developing (remotely) deployed service applications, that require:
– Reliability
– Large scale distribution
– Wide range of devices
– Collaborative
• An OSGi framework then offers you dynamic loading/unloading, configuration and control of these bundles -
without requiring restarts.
• Handles all class loading in a much better defined way than standard
Java.
– Versioning!
• Policy free
– Policies are provided by bundles
SA (SLIIT) By Udara Samaratunge 6
OSGi Bundle Architecture
• The following list contains a short definition of
the terms:
– Bundles - Bundles are the OSGi components made by
the developers.
– Services - The services layer connects bundles in a
dynamic way by offering a publish-find-bind model
for plain old Java objects.
– Life-Cycle - The API to install, start, stop, update, and
uninstall bundles.
– Modules - The layer that defines how a bundle can
import and export code.
– Security - The layer that handles the security aspects.
– Execution Environment - Defines what methods and
classes are available in a specific platform.
SA (SLIIT) By Udara Samaratunge 7
What is a Bundle?
• In Java terms, a bundle is a plain old JAR file.
But, with OSGI we don’t need to stop the whole application because everything is exposed either as
a component or as a service therefore we just need to install new component/service in OSGI
container.
when the services/components are updated in OSGI container there are various event listeners that
propagate the service/component update event to service/component consumers.
And accordingly consumers adapts themselves to use new version of web service (on the consumer side
we need to listen for various events so that consumers can decide whether to respond for change or not.
SA (SLIIT) By Udara Samaratunge 9
SA (SLIIT) By Udara Samaratunge 10
Practical Example
IDictionaryService
Dictionary Client
Service Service
Boolean checkWord(word)
Bundle ID = 11
OSGi Framework Service
bundle Client 1 Service
subscriber 1
subscriber 2
Dictionary
Client 2
Service
Bundle ID = 12
Client 3 Service
Bundle ID = 10
Publish the Bundle ID = 14 subscriber 3
service Bundle ID = 13
OSGi Environment
MTIT (SLIIT) By Udara Samaratunge 11
Practical Example
IDictionaryService IDictionaryService
Dictionary Client
Dictionary
Service Service
Service Boolean checkWord(ArrayList<String> words)
Boolean checkWord(word)
Old service
Service
Client 2
subscriber 2
Dictionary Client 3 Service
Service subscriber 3
Modified service
MTIT (SLIIT) OSGi Environment
By Udara Samaratunge 12
OSGi Environment
IDictionaryService
Manifest file Dictionary Client Manifest file
Service Activator Service Service
Boolean checkWord(word) Service Activator
IDictionarySevice
DictionarySeviceImpl
Dictionary Service Manifest file
• The framework uses the explicit imports and exports to wire up the bundles so they do not have to concern
themselves with class loading.
• Protection
– Java can not protect certain packages and classes from others.
• Versioning
– Java can not handle multiple versions of the same package in a VM
• The Framework Service Registry is available to all bundles to collaborate with other bundles.
• Different bundles (from different vendors) can implement the same interface
– Implementation is not visible to users
– Allows operator to replace implementations without disrupting service
• A bundle can create an object and register it with the OSGi service registry under one or more interfaces.
• A bundle can therefore register a service, it can get a service, and it can listen for a service to appear or disappear.
• Multiple bundles can register objects under the same interface or class with the same name.
• A bundle can decide to withdraw its service from the registry while other bundles are still using this service
• This logging framework can be deployed as an OSGi Bundle, which can be managed
independently.
• Therefore, it can be started when required by our application and can be stopped
when not in use.
• Also the OSGi container makes these bundles available as services, which can be
subscribed by other parts of application.
States of bundles
• Installed – finish bundle installation
• Active – start the bundle
• Resolved – stop the bundle
• http://www.osgi.org/Technology/WhatIsOSGi
• http://en.wikipedia.org/wiki/OSGi
• http://grepcode.com/file/repository.grepcode.com/java/eclipse.org/3.5/org.eclipse/osgi/3.5.0/org/osgi/frame
work/BundleContext.java#BundleContext.getBundle%28long%29
• http://felix.apache.org/site/apache-felix-framework-usage-documentation.html