简体   繁体   English

尝试在OSGI中创建抽象包

[英]Trying to create an abstract bundle in OSGI

I'd like to create something as an abstract bundle in OSGI. 我想在OSGI中创建一些作为抽象包的东西。 The idea is that when let's say bundle Ax (x going from 1 to 9) needs to bind to bundle B through a service provided by B, this could be done more easily by making asbtractA (so Ax extends abstractA) 这个想法是,当我们说捆绑Ax(x从1到9)需要通过B提供的服务绑定到捆绑B时,可以通过创建asbtractA来更容易地做到这一点(因此Ax扩展了abstractA)

Here abstractA is a bundle with a declerative service file. 在这里,abstractA是一个包含命令服务文件的捆绑软件。 The xml file describes the referenced service to bundle B and in the appropriate class of abstractA the bind unbind and start method are implemented. xml文件描述了对捆绑软件B的引用服务,并在相应的abstractA类中实现了绑定解除绑定和启动方法。

Let's assume that Ax has a start method of it's own, startx, and binds to a couple of services, so the bundle has his own .xml file. 假设Ax拥有自己的启动方法startx并绑定到几个服务,因此该捆绑包具有自己的.xml文件。

Question: Will both start (from abstractBundle) and startx be called? 问题:是否会同时调用start(从abstractBundle)和startx? Will the binds from the referenced services of both bundleAx and bundleabstractA take place? 来自bundleAx和bundleabstractA的引用服务的绑定是否会发生?

There is no way to create an abstract bundle in OSGi. 无法在OSGi中创建抽象包。 What you can do though is of course use an abstract class to share some functionality between the bundles. 当然,您可以做的是使用抽象类在捆绑软件之间共享某些功能。

Btw. 顺便说一句。 if the only thing you want to achieve is to share the DS xml file then you should take a look at the annotation based config for DS. 如果您唯一想实现的就是共享DS xml文件,那么您应该看看DS的基于注释的配置。 This eliminates the need to write xml completely (it can be generated by a maven plugin from you annotations). 这消除了完全编写xml的需要(它可以由maven插件根据您的注释生成)。

Although of course your specific details are unclear to me, I question the use of 'inheritance' here. 尽管我当然不清楚您的具体细节,但我在这里质疑“继承”的使用。 It seems to me you may be better off using either: 在我看来,您最好使用以下两种方法:

  1. Delegation. 代表团。 Meaning: delegate the common functionality to a service in bundle A. 含义:将通用功能委托给捆绑软件A中的服务。
  2. A service factory solution. 服务工厂解决方案。 Meaning: create multiple services via a factory pattern where the factory is registered by bundle A. 含义:通过工厂模式创建多个服务,其中工厂由捆绑软件A注册。

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

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