What is OSGi and How Apache Felix, Apache Karaf, Equinox, Knopflerfish, Virgo, Blueprint and Pax Exam are related to OSGi?

OSGi stands for Open Service Gateway initiative. The OSGi specification describes means to achieve better modularity when using Java. Applications or components come in the form of bundles, and these bundles can be remotely installed, started, stopped, updated, and uninstalled without requiring a reboot. Though the original focus of OSGi was initially on service gateways (as the name suggest), the OSGi specification have evolved beyond that and is now used in wide range of applications, and Eclipse IDE is one popular example. Modular architecture reduces complexity, allows for better changeability, parallel development, improved testability, reuse and flexibility, and thus reducing time and expenses for development and maintenance. Read more about OSGi specific benefits @ http://www.osgi.org/Technology/WhyOSGi.

Three key aspects of OSGi are bundles, life cycle, and services, and these are provided through an OSGi container. A bundle is a jar, and bundles allow developers to package code into deployable units and even to control which package needs to imported, exported, and their access levels. Multiple versions of a bundle can be installed into OSGi at the same time. Technically, each bundle is loaded into its own class space. Life cycle management allows starting, stopping, updating, or removing bundles and downloading of management policies, remotely and via an API. Services can be provided by one bundle to another bundle dynamically: services can become available and unavailable at any time. The service registry allows bundles to detect the addition of new services, or the removal of services, and adapt accordingly.

OSGi-based applications run within an OSGi container and an ODGi container is an implementation of the OSGi core framework specification. There are many open source OSGi containers like Apache Felix, Eclipse Equinox and Knopflerfish, and these three are open source implementations of the OSGi Release 4 core framework specification. The Eclipse IDE is built upon Equinox. Rather than downloading the core (e.g. Felix, equinox) and using it directly, you can use an OSGi runtime environment that wraps an OSGi core and provide developers with a simple interface to manage their OSGi applications. Apache Karaf and Eclipse Virgo are examples of such OSGi runtime environments and these two contains Felix and Equinox cores respectively by default.

Blueprint is a dependency injection framework specification for OSGi created based on Spring Dynamic Modules. Spring DM is almost similar and can even be considered as an implementation of the Blueprint specification. Blueprint support the dynamic nature of OSGi services by describing how the components get instantiated and wired together using an extender pattern: an extender bundle monitors the state of bundles in the framework and performs actions on behalf of those bundles based on their state. Technically, Blueprint defines the assembly of various components using xml files known as Blueprint XML files. An OSGi bundle is considered to be a Blueprint bundle when it contains one or more Blueprint XML files under the predefined directory location OSGI-INF/blueprint or as specified explicitly in the Bundle-Blueprint manifest header.

OPS4J Pax Exam is a useful tool while working with OSGi, especially while testing. Pax Exam lets you control the OSGi framework, a test framework (e.g. JUnit, TestNG6) and your test system at the same time. Test system is the system under test. Technically, Pax Exam has a test driver and a test container. The driver launches the OSGi framework and the test system. It builds on-the-fly bundles from your test cases and injects them into the container. The driver is a plain old Java application and does not itself require an OSGi framework. Pax Exam 3.x generalizes the in-container testing approach to cover not only OSGi, but also Java EE and CDI components and applications.

Integration and migration are two important concerns whenever we adopt a new technology. We can easily integrate OSGi with existing non OSGi bundles (java archives) or migrate existing java archives easily as OSGi bundles. We can convert a normal java archive file to a basic OSGi bundle by adding some OSGi specific headers to the java archive manifest file, to identify the bundle, its version, its imported dependencies, and any exported packages the bundle provides. We can code for any additional feature than OSGi provide as and when required.

 

Summary

In this note, we have quickly touched upon OSGi and many products related to OSGi like Apache Felix, Apache Karaf, Eclipse Equinox, Eclipse Virgo, Blueprint and Pax Exam, so that you will at least know what they are if you come across their names. We will see them in detail in further tutorials. Also, note that implementing OSGi will not automatically make your application modular and provide all the benefits of modular architecture we saw initially. OSGi is a helping hand that makes it easy for us to create well defined modules and it is our responsibility to understand and use it well.

 

Reference

http://en.wikipedia.org/wiki/OSGi

http://www.osgi.org/Specifications/HomePage

http://www.osgi.org/Technology/WhyOSGi

https://felix.apache.org/

http://en.wikipedia.org/wiki/Apache_Felix

http://www.eclipse.org/equinox

https://www.eclipse.org/equinox/framework

http://en.wikipedia.org/wiki/Equinox_(OSGi)

http://en.wikipedia.org/wiki/Knopflerfish

https://aries.apache.org/modules/blueprint.html

https://ops4j1.jira.com/wiki/display/PAXEXAM3/Pax+Exam

Book: Instant OSGi Starter by Johan Edstrom and Jamie Goodyear.

Book: Creating Flexible Applications with OSGi and Spring by Craig Walls

Comments

Technically, each bundle is loaded into its own class space.

Was it useful?

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (52) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quizzes (17) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (1) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)