Writing about technology, traveling, politics and more

Wednesday, December 31, 2008

Starting with OSGi - Tutorial 1

This is the first part of a series of tutorials which show how you can build context-aware applications with the MUSIC Context System. This system is part of the general MUSIC Middleware, developed by the MUSIC Consortium. As the MUSIC Context System is built on top of OSGi and it leverages Declarative Services (which are based on Service Binder), we start with an introduction to these technologies. For an additional, well-structured tutorial on OSGi and Declarative services, you can also check out this blog.

OSGi Component Framework Basics

The Open Service Gateway initiative (OSGi) commonly refers to a standard specifying a Java-based service platform that can be remotely managed. The core part of the specifications is a framework that defines an application life cycle management model, a service registry, an Execution environment and Modules (see Wikipedia entry on OSGi). There are currently five certified implementations complying to OSGi specification R4, including Eclipse Equinox and Knopflerfish.

As component frameworks, OSGi implementations provide a way to encapsulate and package functionality into well-defined packages. In this case, the packages correspond to bundles, which can import and export services as a way of interacting with other bundles. These bundles are packaged in JAR files which enclose the Java classes of the implementing code, along with the required metadata (i.e., the MANIFEST file).

Components and Services

Before we delve into the core of OSGi installation and use, we need to provide some additional explanation as per the motive for OSGi. Since the early 70's, computer scientists realized the importance of encapsulation (see this classic work from Parnas for example).

Encapsulation allows implementing complex software with only a small fraction of it (the API) exposed to its users. This makes it possible to edit and update the internal implementation of the software without requiring any action from its users. In its most modern form, encapsulation (or information hiding) is enabled using components and services.

One of the most popular definitions of software components specifies them as "[software components] are units of composition with contractually specified interfaces and explicit context dependencies only; [software components] can be deployed independently and is subject to composition by third parties" (Component Software - Beyond Object-Oriented Programming book). On the other hand, services are used to indicate a predefined set of functionality through an interface (functional logic) along with some policies and/or contracts defining its extra-functional properties, such as Quality of Service (QoS) contracts, etc.

In OSGi, encapsulation is achieved via software components and services. The former can register (i.e., provide) or use (i.e., consume) services dynamically, as needed. Services allow loose coupling of components, i.e., the service providers do not know about their users and the service users do not know about their providers. Notably, in OSGi the coupling is done dynamically (i.e., at runtime) which provides much more functionality and reliability to the systems.

Downloading and Installing the Framework

While there are multiple implementations of the OSGi specification, for the purposes of this tutorial we will use Eclipse's Equinox.

Your first step is to download Equinox. At the time of writing this tutorial, version 3.4.1 is the latest one, and is available for download at this link.

Once it is downloaded, you should unzip the file to the folder of your choice (e.g., in "c:\", which creates the "c:\eclipse\..." folders).

The core of the Equinox implementation of OSGi is in the "plugins" folder, in a JAR file named "org.eclipse.osgi_3.4 ... .jar". Copy that file to "c:\" and rename it to "equinox.jar".

Starting the OSGi Console

To start the (console view) of the framework, simply issue the following command:
C:\eclipse>java -jar equinox.jar -console

osgi>
The framework is up. You can issue your first command to the console. Try "help" or "ss". The first one prints a list of available commands. The second one, shows the short status of the framework, as in the following:
osgi> ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.2.R34x_v20080826-1230
This output says that there is only one bundle installed in the framework (the core OSGi implementation by Equinox), which is assigned the ID "0" and is currently "active". Each bundle can be further introspected with the "bundle" command, as follows:
osgi> bundle 0
System Bundle [0] Id=0, Status=RESOLVED
Registered Services {org.eclipse.osgi.framework.console.CommandProvider}={service.ranking=2147483647, service.id=1} {org.eclipse.osgi.framework.log.FrameworkLog}={service.ranking=2147483647, service.pid=0.org.eclipse.core.runtime.adaptor.EclipseLog, service.vendor=Eclipse.org, service.id=4} {org.eclipse.osgi.framework.log.FrameworkLog}={service.ranking=-2147483648, performance=true, service.pid=46org.eclipse.core.runtime.adaptor.EclipseLog, service.vendor=Eclipse.org, service.id=5} {org.eclipse.osgi.service.runnable.ApplicationLauncher}={service.id=22}
Services in use: {org.eclipse.osgi.framework.console.CommandProvider}={service.ranking=2147483647, service.id=1}
No exported packages [PackageAdmin service is not registered]
As it was already mentioned in the OSGi Basics, bundles interact with each other via services. In this case, the services are abstracted and correspond to plain Java Interfaces. As such, each bundle specify a list of offered (i.e., registered) and needed (i.e., used) services. Notably, this status shows that the Equinox bundle offers (and uses) the "org.eclipse.osgi.framework.console.CommandProvider" interface. This is a service which allows interfacing with the Command Line Interface (i.e., the console), and it will be revisited in one of the following tutorials.

Getting ready for Declarative Services

While the current bundle is sufficient for the core OSGi, additional bundles are needed in order to add more functionality. For example, in order to deploy bundles which use Declarative Services, you need to install the following bundles: "org.eclipse.equinox.ds_1. ... .jar", "org.eclipse.equinox.util_1. ... .jar" and "org.eclipse.osgi.services_3. ... .jar".

Please note that all the needed JAR files are available in the "./plugins" folder, and they can be installed by referencing them directly as follows:
osgi> install file:plugins\org.eclipse.equinox.ds_1.0.0.v20080427-0830.jar
Bundle id is 1

osgi> install file:plugins\org.eclipse.equinox.util_1.0.0.v20080414.jar
Bundle id is 2

osgi> install file:plugins\org.eclipse.osgi.services_3.1.200.v20071203.jar
Bundle id is 3

osgi> ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.2.R34x_v20080826-1230
1 INSTALLED org.eclipse.equinox.ds_1.0.0.v20080427-0830
2 INSTALLED org.eclipse.equinox.util_1.0.0.v20080414
3 INSTALLED org.eclipse.osgi.services_3.1.200.v20071203

osgi> start 1

osgi> start 2

osgi> start 3

osgi> ss

Framework is launched.

id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.2.R34x_v20080826-1230
1 ACTIVE org.eclipse.equinox.ds_1.0.0.v20080427-0830
2 ACTIVE org.eclipse.equinox.util_1.0.0.v20080414
3 ACTIVE org.eclipse.osgi.services_3.1.200.v20071203
Finally, please note that after you install a bundle, it is copied in "./configuration" (which is created by OSGi the first time you launch it) and thus it is not needed to keep it at the source folder anymore.

In this case, we have started all the bundles and executed the short status (ss) command afterwards.

Shutting the OSGi console down

To exit the console, you can simply issue the "shutdown" command followed by "exit" command:
osgi> shutdown

osgi> ss

Framework is shutdown.

id State Bundle
0 RESOLVED org.eclipse.osgi_3.4.2.R34x_v20080826-1230

osgi> exit

Homework 1.1: Run the "help" command in the console. Report what each of the following commands does:
  • status
  • diag ID
  • h ID
  • services
  • packages
  • close
Homework 1.2: Read the first chapter (Introduction) of Neil Bartlett's book. You can skip sections 1.3 and 1.8.

Tuesday, December 30, 2008

Tutorials for OSGi, Declarative Services and the MUSIC Context System

As a research associate at the University of Cyprus, I work for the MUSIC-IST (somehow, the anagram for "Self-Adapting Applications for Mobile Users in Ubiquitous Computing Environments"), which is an FP7 IP project funded by the European Union. It aims at enabling the development of context-aware, self adaptive applications. One of the most important novelties of MUSIC, is that it provides a comprehensive development methodology. This means that the developers have a plethora of guidance, tools and libraries available when they depart developing such an application. Furthermore, as it is based on a Middleware architecture, MUSIC provides flexibility and facilitates code reuse.

As part of my research, I am the principal architect and developer of the MUSIC Context System. In the following posts, I will describe how this system can be used to build context-aware applications. As this system builds on top of OSGi, and especially leverages the Declarative Services specification, the first tutorials cover the basics of OSGi, starting from installing and launching the framework. As new tutorials become available, I will update the list in this blog entry.

OSGi and Declarative Services
MUSIC Context System
The only requirement for attending these tutorials is a reasonable command of Object-Oriented programming in Java.

For comments, or suggestions regarding these tutorials, please contact the author via email (you can find it in my homepage: http://member.acm.org/~nearchos).

Resources
  1. OSGi website and and the Specifications of Release 4 (R4)
  2. Neil Bartlett's blog entries on Getting Started with OSGi and the first chapters of his book (in draft)
  3. A 6-page quick-start introduction to OSGi and Equinox (requires registration): Getting Started with Equinox and OSGi Refcard
  4. Andre L. C. Tavares, Marco Tulio Valente, A Gentle Introduction to OSGi, SIGSOFT Software Engineering Notes, Vol. 33, No. 5 (Aug. 2008), pp. 1-5
  5. A few books by Amazon are unfortunately not available until Summer ("Equinox and OSGi" and "OSGi in Action: Creating Modular Applications in Java")

Monday, December 29, 2008

2nd Workshop on Context-aware Adaptation Mechanisms for Pervasive and Ubiquitous Services (CAMPUS 2009)

Building on last year's success, the "2nd Workshop on Context-aware Adaptation Mechanisms for Pervasive and Ubiquitous Services (CAMPUS 2009)" will be organized again, in conjunction with the "4th International federated conference on Distributed Computing Techniques (DisCoTec 2009)".

As a member of the Program Committee of the workshop, I encourage you to consider submitting any work you have done relevant to "Context-awareness" or "Adaptation Mechanisms" for Pervasive and Ubiquitous Services. I honestly think is a good forum, with experienced reviewers, for discussing and potentially presenting your work.

Important dates:
Paper submission: March 20, 2009
Paper notification: April 24, 2009
Camera ready: May 08, 2009
Workshop: June 12, 2009

iPod touch

As promised in a blog entry some weeks ago, I now post my impressions of iPod touch.

I bought an iPod touch (2nd generation) as a gift to myself while we were visiting Hawaii. The Apple Store I got it from was great! So was the price ($230 plus tax), considering how much more expensive iPods are in Europe. Let me say here that I chose iPod to iPhone for two simple reasons: First, I already have a NOKIA phone with which I am very happy and, second, I wanted a device primarily for browsing the Internet without a laptop and for killing my time in airports etc.

The first impression was actually not very positive. I got frustrated because I could not get iPod paired with my iTunes account. The reason was that iTunes purchases are available only in selected countries (and Cyprus is not one them yet), which was OK with me. The problem was that although I did not mind not being able to buy staff (I have plenty of CDs already), I still wanted to be able to get the freely available products (mostly apps and podcasts). Thanks to instructions from this site, I was finally able to set up my iTunes account without having to enter any data for a credit card or mailing address (it is too bad Apple did not make it easier to skip attaching a credit card to an iTunes account).

Other than this little glitch though, I have to admit that iPod touch is an amazing gadget. Most of all, I enjoy the touch UI, and the orientation sensors which add a lot to the user experience (especially in the context of game apps). MUSIC and video playback are excellent. In my last 4.5h flight back from Schiphol, I felt as if time flew by! I was using my iPod touch to watch video snippets of stand-up comedy from Comedy Central and also I was playing with what has become my favorite iPod game: TAP Defense.

I would like to also cover the development aspects of iPhone/iPod touch, but unfortunately I soon realized that the development tools for iPhone and iPod touc are limited to Macs only.

In summary, the pros:
1. Great UI
2. Excellent web and mail applications
3. Great audio and video playback
4. The appstore is a vibrant active community generating challenging and useful apps
5. As a device, it is small and light
6. It charges from USB

and cons:
1. It does not have an embedded microphone
2. Docking base comes as an extra
3. Its accessories (e.g. docking station, video connector, power adapter) are quite expensive
4. The Development tools are available for Macs only

Sunday, December 28, 2008

Photos from Hawaii

It's been more than a month since we visited Hawaii now. But I need to write this blog entry so that I don't forget how wonderful everything was. I think Oahu is a gorgeous island, even though I understand that the other islands of Hawaii might be even prettier (at least less developed = more natural).

While Honolulu is a nice city, Waikiki is too touristic for my taste. But apart from this, the rest of the island is amazing. Even just outside the limits of the city, there are tropical forests and wonderful waterfalls. Just a few miles east of Honolulu, Hanauma bay, which is typically very busy, provides an astonishing experience. Then, the Polynesian Cultural Center to the northeast of the island is definitely worth visiting. Although the day we visited the Polynesian Cultural Center was quite rainy, it was still a quite memorable experience. And of course, the beaches of Hawaii, especially Kailua, is a must visit/must swim activity for everyone visiting Oahu.

I am looking forward to the next opportunity to visit Hawaii!

This and other pictures from Oahu are posted in my Picasa account: "Oahu, Hawaii".