0
votes

In OSGi (Apache Felix 4.2.1), I want my bundles to check for updates automatically on startup.

I do this with the following code (in my "management agent"). How can I tell whether a bundle was updated?

Bundle[] bundles = context.getBundles();
for (int i = 0; i < bundles.length; i++) {
  Bundle bundle = bundles[i];
  bundle.update();
}
// which bundle was updated?

I want to refresh the bundles automatically (using FrameworkWiring), but only if one of the .update() calls actually resulted in a new deployment from my server.

As I'm deploying from Maven to my OBR, my SNAPSHOT version have all the same number. From gogo, I can see that the Bnd-LastModified header changes, but how to automate this?

PS: If easy solutions exist which solve the whole update thing more nicely than rolling my own, I'm interested as well. It needs to be lean. (Apache Karaf?, Apache ACE? others?)

3

3 Answers

3
votes

They are all updated, because your code clearly calls update on all of them.

What you probably mean is how to tell whether a bundle needs to be updated. For this you could use the bundle.getLastModified() method, and compare it against the timestamp of the file. But this gets risky when you have timestamps generated by multiple computers, because their system clocks will never be precisely synchronized. If they are coming from a remote server (e.g. over HTTP) then forget it. You should probably use something like ETags or SHA hashing of the files after downloading.

2
votes

If you want to learn a bit more about Apache ACE, I can recommend reading the following two articles on the ACE website:

To be honest, if all you want is to updated a set of bundles on startup, then ACE is a bit overkill. It can be used to manage multiple "targets" (frameworks running OSGi) from a central server, automatically pushing updates to it and managing large sets of bundles and other artifacts, grouping them in features and distributions.

0
votes

Have you tried to implement a listener?