【问题标题】:How to wait the p2 profile gets completed如何等待 p2 配置文件完成
【发布时间】:2013-10-08 16:42:41
【问题描述】:

我们正在使用 p2 来更新我们的 RCP 应用程序,到目前为止它运行良好,直到今天我意识到在某些情况下 P2 IProfile 是 emty(不是 null 而是空的)并且当然总是返回 emty 结果查询。

这仅在启动应用程序时发生,这意味着如果我稍后请求相同的配置文件,我将获得完整的配置文件。

IProfile 的 Javadoc 提到 profile 是特定状态的快照这一事实。 所以看来我要提前查询 ProfileRegistry 并且配置文件还没有完成。 我在 javadoc 上找不到任何方法来等待配置文件被正确填写。

我会感谢任何能帮助我很好地解决这个问题的人,因为使用睡眠(有效)不是一个可接受的解决方案。 谢谢。

【问题讨论】:

  • 欢迎来到 P2 地狱。你能显示你的代码吗?您何时查询配置文件注册表?您加载哪个配置文件?等等。
  • 看我的回答帖子,我讨厌那种代码,如果你有更好的解决方案,我会很高兴。

标签: eclipse p2


【解决方案1】:

这是我实施的丑陋解决方案,主要是测试时间戳以确保配置文件已加载

// there seems to be a bug because if the agent is created too quickly then the profile is empty.
// so we loop until we get a proper profile
do {
    try {
       Thread.sleep(50);
    } catch (InterruptedException e) {
       interrupted = true;
    }
    if (agent != null) {
       agent.stop();
    }
    agent = agentProvider.createAgent(getP2AgentUri());
    IProfileRegistry profRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
    profile = profRegistry.getProfile(getP2ProfileId());
} while (profile != null && profile.getTimestamp() == 0 && !interrupted && !progress.isCanceled());

我使用的配置文件是 SELF,但我使用一种方法来获取 ProfileId,因为我有基于另一个外部 p2 配置文件的 JUnit 测试。

【讨论】:

  • 什么时候开始执行这个循环?一个天真的猜测是 P2 机器只是“不存在”到这一点,你得到的配置文件是 NULL。那么它可能与 Equinox 容器中的捆绑启动级别有关。
  • 如果你看看我写的我从来没有说过配置文件是空的,那一点,配置文件不是空的,就像它被 p2 找到但还没有完全变红。此循环在创建 eclipse 工作台后立即在 org.eclipse.ui.startup 扩展点中启动。
  • 好的,我看到“不是空的而是空的”。只是被您的“while”语句中的“profile!= null”检查弄糊涂了。但是,我无法重现这种不当行为。您是否检查过需要重新查询 P2 的次数?您还可以打开一些 P2 跟踪以查看更多正在发生的事情:wiki.eclipse.org/Equinox/p2/TracingOptions 或调试代码...
猜你喜欢
  • 2021-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多