tags:

views:

11

answers:

1

I have several OSGi bundles, each of which can be updated from an OSGi Bundle Repository. When I start my OSGi framework (Apache Felix), I want the first bundle to start and check for updates for all installed bundles. If updates are available, it should update each of them (including itself) then continue starting (or possibly shutdown, and the OS will restart the app).

How is this best done in an OSGi compliant manner?

How should the first bundle update itself? Can it update itself while it is starting?

A: 

You may have a look at the state diagram in the OSGi Core Spec (this should be Fig.28). There you can see that a bundle in STARTING state can only move to ACTIVE state (with the exception when an exception is thrown). A bundle can only be updated when it is either in INSTALLED or RESOLVED state. For this it must be stopped in case it is in ACTIVE state.

The problem here is that you cannot stop a bundle when it is in STARTING state. And as long as the Activators start() method is executed the bundle is still in STARTING state, not ACTIVE.

What you can do is to start a thread in the Bundle that checks its state for ACTIVE and then call the update() method. But don't forget to terminate the thread, otherwise the garbage collector cannot free the resources of the current bundle's jar file.

akr