Testing Hotswapping on Java with Apache Felix’ OSGi Tutorial

About half a year ago I stumbled over the problem that Java does not allow certain types of changes on compiled coding on the fly (for good reason BTW). It is even not possible when using the debugger interface (see also JDPA for more details on this). On the other hand, however, I know from the ABAP/4 world that generating coding might be a very good idea sometimes, because in most cases it impacts performance less compared to writing generic coding (for example by using introspection or reflection). In this situation you often want to automize the generation thus immediately having to struggle with the problem that you need to reload changed compiled codes “on the fly” (during the runtime of the virtual machine) for example to correct errors or to deploy a new version. Since that time I was searching for some alternative which could work around many restrictions Java currently poses here. Looking around with Google I found that already some people before me had thought about this problem. I stumbled – for example – over the following papers:

Finally, I read in a forum that the OSGi standard (besides some other things) would provide such a feature. Reading a bit more at their website I figured out that this is not just about hotswapping Java Byte Code, but an entire approach of implementing a certain component model coming from the embedded device world. I was quite eager getting to know more about it and planned to conduct a more thorough practical look at an implementation of the standard some time.

First Steps with Felix

Within the last weeks I found this opportunity and had a closer look at Apache Felix, one of the major implementations of the OSGi standard. At their website they have a quite interesting tutorial which describes how to use the OSGi standard in an example-driven manner. Unfortunately, I did not find a downloadable package of the examples used in the tutorial so I was forced to copy and paste it locally into my Netbeans environment. If you want you can download this package from this post.

  Enhanced OSGi Felix Tutorial (1.8 MiB, 2,578 hits)


For those not familiar with this tutorial, here is a brief overview about which lesson/example is doing what:

Example Description
1 Event Listener for Bundle Activation
2 Implementation of a simple component which checks a word (represented as string) against a list of known English words (in a dictionary)
2b Implementation of a simple component which checks a word (represented as string) against a list of known French words (in a dictionary)
3 Implementation of a client for the dictionary services in 2 and 2b
4 An enhanced version of the client of 3
5 An even enhanced version of the client compared to 4 using automatic detection of active and inactive components using a service tracker (a utility class which automatically keeps track of active components)
6 Implementation of a spell checker service (looking up multiple words in a dictionary)

The tutorial goes on with further more complex scenarios. For my intent these examples already had been enough to understand the core concepts.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

7 Comments

  1. Yet another good post. I put in a plug for this blog at mine. Anyway, I am sure most people forget the point you are making.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  2. Great information. Keep up the great work. […]

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  3. Thanks much for this method excellent article content; this is the kind of step that continues me though out the day.I’ve already been searching around for one’s webpage just after I learned about these from a good friend and was pleased when I was able to find it just after searching for a while. Being a devoted blogger, I’m thrilled to view other people taking effort and adding towards the neighborhood. I just wished to review to show my thanks for your personal post as it is especially inviting, and many copy writers do not get the credit score they deserve. I am certain I’ll be back and will send a few of my mates.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  4. Thanks for sharing your thoughts on hotswap. Regards

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

*