嵌入式OSGi框架中的消费服务

编程入门 行业动态 更新时间:2024-10-28 04:21:12
本文介绍了嵌入式OSGi框架中的消费服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有可嵌入的Felix.我有一些API捆绑包和Impl. API导出接口C .Impl导入该接口并在激活器中注册impl.现在我要获取C隐含的OSGi

I have embeddable Felix. I have some API bundle and Impl. API exports interface C.Impl imports that interface and register impl in activator. Now I want get C impl otside OSGi

FrameworkFactory ff = new FrameworkFactory(); ... BundleContext bc = fwk.getBundleContext(); ... final ServiceReference[] serviceReferences = bc.getServiceReferences(C.class.getName(), "(objectclass=" + C.class.getName() + ")"); for(ServiceReference serviceReference : serviceReferences){ final Object service = bc.getService(serviceReference); ... }

现在我想与它互动.我可以用反射来做

Now I want to interact with it. I can do it with reflection

System.out.println(service.getClass().getMethod("some").invoke(service)); //using

但我无法投射

System.out.println(service instanceof C); //prints false

我猜这来自不同的ClassLoader.但是我该如何解决呢?我们如何从外部与OSGi上下文进行交互?还是我们可以将其全部放入OSGi容器中?

I guess that comes from different ClassLoaders. But how I can solve it? How we can interract with OSGi context from outside? Or we can obly put it all into OSGi container?

推荐答案

如果要嵌入OSGi,则该服务的API(即接口"C")必须对外部应用程序可见,并通过系统导出到OSGi捆绑出口.外部应用程序无法从OSGi框架内包含的包中导入软件包.

If you are embedding OSGi, the API for the service (i.e. interface "C") has be to visible to the outer application and exported into OSGi via the system bundle exports. The outer application cannot import packages from the bundles contained inside the OSGi framework.

更多推荐

嵌入式OSGi框架中的消费服务

本文发布于:2023-11-03 13:34:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555249.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌入式   框架   OSGi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!