3 min read

 

OSGi and Apache Felix 3.0 Beginner’s Guide

OSGi and Apache Felix 3.0 Beginner's Guide

Build your very own OSGi applications using the flexible and powerful Felix Framework

  • Build a completely operational real-life application composed of multiple bundles and a web front end using Felix
  • Get yourself acquainted with the OSGi concepts, in an easy-to-follow progressive manner
  • Learn everything needed about the Felix Framework and get familiar with Gogo, its command-line shell to start developing your OSGi applications
  • Simplify your OSGi development experience by learning about Felix iPOJO
  • A relentlessly practical beginner’s guide that will walk you through making real-life OSGi applications while showing you the development tools (Maven, Eclipse, and so on) that will make the journey more enjoyable

      

A simple Bookshelf project

The case study we will construct here is a three-tiered web-based bookshelf application. Each tier consists of a functional area of the application.

The first tier is the data inventory tier, which is responsible for storing the books as well as providing management functionality.

The second tier, the main bookshelf service, holds the business logic around the bookshelf functionality.

The third tier is the user interaction tier. It provides user access to the application through a command-line interface at first, then through a simple servlet, and later through a JSP web application.

This split between the user interface, business logic, and inventory is good practice. It adds flexibility to the design by allowing the upgrade or replacement of each of the layer implementations without impacting the others and thus reducing regression testing.

Let’s look at each of those layers in more detail.

The data inventory tier

For our case study, we will need a data inventory layer for storing, searching, and retrieving books.

The Book interface defines the read-only book bean and it provides the user access to the bean attributes. This interface is used when the Book entry does not require any updates. The MutableBook interface exposes the attribute-setting methods for the book bean. It is used when the caller needs to update the bean attributes.

This separation between Book and MutableBook is especially useful when developing a multi-threaded, multi-session implementation of the data inventory repository. It allows us to keep track of changes by monitoring the beans as they change and notify components of those changes when needed.

We will define a BookInventory interface that abstracts over the repository implementation specifics.

In addition to the CRUD functionality, the book inventory interface also offers a factory method for creating new book entries. This factory method gives the caller a mutable book.

What’s CRUD?

CRUD is short for Create-Retrieve-Update-Delete. It is the typical functionality-set expected from an inventory service:

  • Create: Add a new book to the inventory. This operation typically checks the repository for an item with the same identifier (unique reference) and throws an exception if there’s an attempt to add an item that already exists.
  • Retrieve: Load a book based on its unique reference, also get a list of references of items that match a set of filter criteria
  • Update: Modify an existing book properties, based on its unique reference
  • Delete: Remove an existing book from the inventory based on its unique reference

We’ll separate the inventory API definition from its implementation, packaging each of them in its own bundle. It is recommended that you write another implementation for those interfaces—one that’s based on permanent storage, when you’re more comfortable with the process.

The separation between the API and implementation will allow you to swap an implementation with another one when it is ready. We will focus on the mock implementation(out of the scope of this article) and leave it to you to implement other potential flavors of it (in the previous dashed boxes).

LEAVE A REPLY

Please enter your comment!
Please enter your name here