简体   繁体   English

OSGi:如何知道捆绑包是否已更新

[英]OSGi: How to know if a bundle was updated

In OSGi (Apache Felix 4.2.1), I want my bundles to check for updates automatically on startup. 在OSGi(Apache Felix 4.2.1)中,我希望捆绑软件在启动时自动检查更新。

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. 我想自动刷新捆绑包(使用FrameworkWiring ),但.update().update()调用之一实际上导致了服务器上的新部署。

As I'm deploying from Maven to my OBR, my SNAPSHOT version have all the same number. 当我从Maven部署到OBR时,我的SNAPSHOT版本具有相同的编号。 From gogo, I can see that the Bnd-LastModified header changes, but how to automate this? 从gogo中,我可以看到Bnd-LastModified标头发生了变化,但是如何Bnd-LastModified自动化?

PS: If easy solutions exist which solve the whole update thing more nicely than rolling my own, I'm interested as well. PS:如果存在简单的解决方案,比起自己动手解决方案更能解决整个更新问题,我也很感兴趣。 It needs to be lean. 它需要精益。 (Apache Karaf?, Apache ACE? others?) (Apache Karaf?,Apache ACE?其他?)

They are all updated , because your code clearly calls update on all of them. 他们都在更新 ,因为你的代码中明确提出update上所有的人。

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. 为此,您可以使用bundle.getLastModified()方法,并将其与文件的时间戳进行比较。 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 (eg over HTTP) then forget it. 如果它们来自远程服务器(例如,通过HTTP),则将其忘记。 You should probably use something like ETags or SHA hashing of the files after downloading. 下载后,您可能应该使用文件的ETag或SHA哈希之类的东西。

If you want to learn a bit more about Apache ACE, I can recommend reading the following two articles on the ACE website: 如果您想了解有关Apache ACE的更多信息,我建议您阅读ACE网站上的以下两篇文章:

To be honest, if all you want is to updated a set of bundles on startup, then ACE is a bit overkill. 老实说,如果您只想在启动时更新一组捆绑软件,那么ACE有点过头了。 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. 它可用于从中央服务器管理多个“目标”(运行OSGi的框架),自动向其推送更新,并管理大量捆绑包和其他工件,将它们按功能和分布进行分组。

您是否尝试实现监听器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM