【发布时间】:2018-03-25 10:11:09
【问题描述】:
我有这样的问题。我有两个 OSGI 蓝图包。其中一个就像服务,另一个正在使用它。我在 karaf 上运行它们。所以,我想实现功能,所以当我停止服务时,我的另一个包也应该停止。 我的xml的
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd ">
<reference id="weatherService" availability="mandatory" interface="com.myslyv4uk.weather.api.WeatherService" />
<bean id="showWeatherImpl" class="com.myslyv4uk.client.impl.ShowWeatherServiceImpl"
init-method="start" destroy-method="stop" >
<argument ref="weatherService" />
</bean>
</blueprint>
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd ">
<bean id="weatherServiceImpl" class="com.myslyv4uk.weather.impl.WeatherServiceImpl"
init-method="start" destroy-method="stop" />
<service ref="weatherServiceImpl">
<interfaces>
<value>com.myslyv4uk.weather.api.WeatherService</value>
</interfaces>
</service>
</blueprint>
Java 代码已跳过。我只会说 ShowWeatherService 使用 WeatherService 打印随机数。它们都有启动/停止方法。我需要以这种方式实现配置或功能,因此在从 karaf 卸载 WeatherService 包后,ShowWeatherService 也停止了。问题是我不能从 WeatherService 到 ShowWeatherService 的引用,因为它将是循环引用,它不会启动这个包。我该怎么办?如何从其他捆绑包中终止捆绑包?
【问题讨论】:
-
检查OSGi SCR。您可以根据是否存在 OSGi 服务(以及其他)来激活/停用“组件”
-
@GrzegorzGrzybek 感谢您的评论,但据我了解,这是声明性服务。我正在使用蓝图。重写为声明式服务是我想避免的最后手段
标签: java osgi osgi-bundle blueprint-osgi