【问题标题】:Activator.updated() method is not called in osgiosgi 中不调用 Activator.updated() 方法
【发布时间】:2015-04-24 00:17:26
【问题描述】:

我正在为 osgi 使用 Apache Felix。其他捆绑包运行良好。我已经向反应堆添加了新的捆绑包。 Activator.init() 方法被调用。但我永远不会进入 updated() 方法。有什么想法吗?

public class Activator extends DependencyActivatorBase implements ManagedServiceFactory {

    private static final Logger logger = LoggerFactory.getLogger(Activator.class);

    public static final String PID = "my.unique.pid";
    private final Map<String, Component> components = new HashMap<>();
    private volatile DependencyManager dependencyManager; /* injected by dependency manager */


    @Override
    public void init(BundleContext bc, DependencyManager dm) throws Exception {     
        Properties props = new Properties();
        props.put(Constants.SERVICE_PID, PID);
        dm.add(createComponent()
                .setInterface(ManagedServiceFactory.class.getName(), props)
                .setImplementation(this)
                .add(createConfigurationDependency().setPid(PID))
                );

        dm.add(createComponent()
                .setInterface(SessionRegister.class.getName(), null)
                .setImplementation(SessionRegisterImpl.class)
                );

        dm.add(createComponent()
                .setInterface(Plugin.class.getName(), null)
                .setImplementation(PriorityActionHandler.class)
                .add(createServiceDependency().setRequired(true).setService(PluginManager.class))
                );
    }

    @Override
    public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
        logger.debug("This method should be called and run!");


        if (properties == null) {
            logger.warn("Configuration is empty!");
            return;
        }

.
.
.

    }

【问题讨论】:

    标签: osgi apache-felix activator


    【解决方案1】:

    init 方法可能不是您想要的。您创建了一个ManagedServiceFactory 的组件,带有PID,并且您还使该组件具有服务依赖项(这意味着将其设为ManagedService,具有相同的PID,这是不允许的并且绝对令人困惑)。我假设您的意思是这两个中的任何一个。

    您现在拥有的更新方法假定您想成为ManagedServiceFactory,并且将为您提供的每个配置(一个或多个)调用更新。从您的代码中,我看不到您是否安装了 Configuration Admin 的实现,以及您是否实际上以某种方式为此 PID 提供了一个或多个配置。

    如果此答案对您没有帮助,请提供更多信息以进一步查明此问题。

    【讨论】:

    • 没关系...问题出在 init() 方法中...这个“.add(createConfigurationDependency().setPid(PID))”不应该在那里...它应该在更新()方法。
    • 我不太明白你的推理。为什么 updated() 方法需要添加配置依赖(当组件已经是 ManagedServiceFactory 时)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    相关资源
    最近更新 更多