【问题标题】:How is asynchronous event delivery triggered in eclipse OSGi?eclipse OSGi中如何触发异步事件传递?
【发布时间】:2019-12-21 16:32:57
【问题描述】:

我正在使用EventAdmin 在eclipse OSGi 中发送和发布Events。发送工作正常,但我无法收到已发布的Events。传递已发布Events 的机制是什么?我可以手动触发这个机制吗?

【问题讨论】:

  • 您的标签中有 'eclipse-plugin' - 如果这只是用于插件,IEventBroker 为事件系统提供了一个更易于使用的界面。
  • 在运行配置中禁用“在 UI 线程中运行”解决了这个问题,有人能解释一下原因吗?

标签: java eclipse eclipse-plugin osgi eclipse-rcp


【解决方案1】:

接收事件使用whiteboard pattern。您使用接口 org.osgi.service.event.EvenHandler 发布一个 OSGi 服务。您也可以使用服务属性 EventConstants.EVENT_TOPIC 来定义您要收听的主题。

@Component(
    property = EventConstants.EVENT_TOPIC + "=my/topic"
)
public class MyReceiver implements EventHandler {

    @Override
    public void handleEvent(Event event) {
        System.out.println("Event received");
    }

}

有关所有详细信息,请参阅EventAdmin service spec。还有一个不错的tutorial at Vogella

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 2010-09-10
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    相关资源
    最近更新 更多