1

Is there a recommended approach to patch an OSGi application on the runtime? I'm using equinox implementation of OSGi.

If I stop a particular bundle and install the patched bundle. How will it affect the other bundles at runtime?..

I saw this OSGi Application Patching Strategy and it does not give a clear answer.

Thanks.

Community
  • 1
  • 1
Aruna Karunarathna
  • 981
  • 2
  • 23
  • 55

2 Answers2

1

I suppose it depends on how good the bundles are.

There is a good example in "OSGi in Action" book, on page 73.

To try it yourself:

  1. Download the examples,
  2. Unpack the file and build the "chapter03" examples with Ant (osgi-in-action/chapter03/build.xml),
  3. Copy chapter03/paint-example/bundles/*-3.0.jar files into e.g. chapter03/shell-example/1,

In order to make the examples work (see issue) you need to do this:

  1. Download latest Apache Felix Framework distribution from this page, at the moment it's 4.2.1,
  2. Extract the org.apache.felix.main.distribution-4.2.1.zip file,
  3. Extract the felix-framework-4.2.1/bin/felix.jar file,
  4. Copy the default.properties file into the OSGi example's chapter03/shell-example/launcher.jar.

Now that you have everything ready:

// In console window #1:
$ cd chapter03/shell-example/
$ java -jar launcher.jar bundles

// In console window #2:
$ telnet localhost 7070
-> install file:1/paint-3.0.jar
-> install file:1/shape-3.0.jar
-> start 2
-> install file:1/circle-3.0.jar
-> install file:1/square-3.0.jar
-> start 4
-> start 5
-> install file:1/triangle-3.0.jar
-> start 6
// You can now draw all three shapes.

// Simulate upgrade/patch of "circle" bundle:
-> stop 4
// A "work in progress" sign is in place of the circles.
// You can still move them.

// Start the "circle" bundle again and they're back in the UI:
-> start 4

You can check the example source code to see how they did it. I hope this answers your question.

Cebence
  • 2,406
  • 2
  • 19
  • 20
1

It partly depends on whether the bundles together using services or imported/exported packages. Services are much more dynamic.

If the patched class is consumed as an exported package, its consumers will have a reference to the original class. To force a move to the new one, refresh packages must be called, either in a console or directly on a 'FrameworkWiring' instance. (It's now called 'refreshBundles' but the principle is similar.)

There is a full discussion in a closely related question, How does OSGi bundle update work?.

Community
  • 1
  • 1
Holly Cummins
  • 10,767
  • 3
  • 23
  • 25