【发布时间】:2015-01-12 11:46:27
【问题描述】:
我一直试图理解一种奇怪的 OSGI 行为。希望有人能对此有所了解。这是我的设置
1) 使用eclipse\plugins\org.eclipse.osgi_3.7.0.v20110613.jar
2) 我有一个导出服务的 Bundle (HelloworldService)
它在激活器中注册服务
公共无效开始(BundleContext上下文)抛出异常{ IHelloService helloService = new HelloServiceImpl(); helloServiceRegistration =context.registerService( IHelloService.class.getName(), helloService, null ); }3) 我有一个“消费者”捆绑包,它通过 ServiceTracker 使用该服务
ServiceReference externalServiceReference = Activator.getContext().getServiceReference(IHelloService.class.getName()); IHelloService externalService = (IHelloService) Activator.getContext().getService(externalServiceReference);现在,当我将这两个 jar 部署到 OSGI(helloworld.jar 和 helloworldservice.jar)时;它工作正常。我能够得到一个'IHelloService' impl 对象并对其进行调用。我可以启动/停止捆绑包以及它们何时返回;它工作得很好
问题发生在我“卸载”然后“安装”HelloWorldservice 捆绑包时。 在这种情况下; 'Helloworld' 消费者 externalServiceReference 为 NULL。 如果我查看捆绑信息;我看到了这个
osgi> 捆绑 1 mypackage.helloworld_1.0.0.qualifier [1] Id=1,状态=RESOLVED 数据根=C:\Users\\dev\eclipse\plugins\configuration\org.eclipse.obundles\1\data 没有注册服务。 没有正在使用的服务。 没有导出的包 进口包 mypackage.helloworldservice;版本="0.0.0" **陈旧** org.osgi.framework;版本="1.6.0" org.osgi.util.tracker;版本="1.5.0" 没有片段包 命名类空间 mypackage.helloworld; bundle-version="1.0.0.qualifier"[提供] 无需捆绑请注意,它的“导入包”已经过时了。这是有问题的行
进口包裹 mypackage.helloworldservice; version="0.0.0"陈旧>
现在我可以通过从控制台发出“更新”命令来解决此问题。
这是我的问题
1) 我如何在我的“消费者”捆绑包中以编程方式执行此操作.. 2) 如果我在生产系统上并且我部署了 helloworlservice.jar 的新“副本”(替换现有版本);我是否必须更新其所有用户.. 我认为 ServiceTracker 会即时为我提供服务
谢谢
【问题讨论】: