首页 文章

OSGI:如何更新'consumer'包

提问于
浏览
0

我一直试图了解一个奇怪的OSGI行为 . 希望有人可以对此有所了解 . 这是我的设置

1)使用eclipse \ plugins \ org.eclipse.osgi_3.7.0.v20110613.jar

2)我有一个导出服务的Bundle(HelloworldService)

它将服务注册在激活器中

public void start(BundleContext context) throws Exception {

        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'inmpl对象并对其进行调用 . 我可以开始/停止捆绑,当他们回来时;它工作得很好

当我'卸载'然后'安装'HelloWorldservice包时会发生问题 . 在这种情况下; 'Helloworld'消费者externalServiceReference为NULL . 如果我查看捆绑信息;我明白了

osgi> bundle 1
mypackage.helloworld_1.0.0.qualifier [1]
  Id=1, Status=RESOLVED    Data Root=C:\Users\\dev\eclipse\plugins\configuration\org.eclipse.obundles\1\data
  No registered services.
  No services in use.
  No exported packages
  Imported packages
    mypackage.helloworldservice; version="0.0.0" **stale**
    org.osgi.framework; version="1.6.0"
    org.osgi.util.tracker; version="1.5.0"
  No fragment bundles
  Named class space
    mypackage.helloworld; bundle-version="1.0.0.qualifier"[provided]
  No required bundles

请注意,其“导入的包”具有GONE STALE . 这是有问题的一行

导入包mypackage.helloworldservice; version = "0.0.0" < stale >

现在我可以通过从控制台发出'update'命令来解决这个问题 .

这是我的问题

1)我如何从我的“消费者”包中以编程方式执行此操作.2)如果我在 生产环境 系统上并且部署了helloworlservice.jar的新“副本”(替换现有版本);我是否必须更新所有用户..我认为ServiceTracker会即时为我提供服务

谢谢

1 回答

  • 2

    使用者捆绑包从服务jar导入mypackage.helloworldservice包 . 卸载服务jar时,使用者jar仍然从已卸载的服务jar连接到现在过时的软件包 . 当你安装一个新的服务jar时,它会导出mypackage.helloworldservice包的新“副本”(我怀疑服务jar也没有导入mypackage.helloworldservice包) . 因此,您需要刷新使用者jar,以便将其连接到新的mypackage.helloworldservice包 .

相关问题