【发布时间】:2018-10-10 15:02:21
【问题描述】:
我正在尝试使用 OSGi 来构建模块化 IoT 单元。如果想在不牺牲通信代码的情况下更新系统的某些部分(例如传感器代码),反之亦然,这似乎是一种完美的技术。
问题是:
为什么在更新服务时需要重新启动所有依赖的捆绑包(在捆绑包内)?
private void updateBundle(String f) {
BundleContext mainBc = felix.getBundleContext();
Bundle bundle = mainBc.getBundle(f);
try {
bundle.update();
// if I don't do this, the services inside 'bundle' will NOT be updated
PackageAdmin pa = mainBc.getService(mainBc.getServiceReference(PackageAdmin.class));
pa.refreshPackages(mainBc.getBundles());
// at this point all bundles were restarted
} catch (BundleException e) {
System.err.println("Error while updating " + f);
e.printStackTrace();
}
}
从我的所有捆绑包都重新启动(或至少依赖的捆绑包)这一事实来看,更新捆绑包中的类定义有什么意义,因为所有应用捆绑包都将stopped 和started 重置所有状态和活跃的连接?
这就像从命令行重新启动我的应用程序一样,为什么我需要 osgi?
【问题讨论】:
标签: osgi apache-felix osgi-bundle