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?)

有帮助吗?

解决方案 2

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.

其他提示

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.

Have you tried to implement a listener?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top