e(fx)clipse 2.2.0 – Typesafe EventBus

With e(fx)clipse we ship as part of our core-bundle (the one able to run in any OSGi and Plain-Java-Env) since 2.1 an org.eclipse.fx.core.event.EventBus which we enhanced in 2.2.0 to provide a certain level of typesafety.

Useage is straight forward:

  1. Define a Topic-Instance
    public class Constants {
      public static final org.eclipse.fx.core.event.Topic<String> MY_TOPIC 
        = new org.eclipse.fx.core.event.Topic<>("my/sample/Topic");
  2. Publishing is done with
    public void init(org.eclipse.fx.core.event.EventBus eventBus) {
      eventBus.publish( MY_TOPIC, "Hello World!", true );
  3. Subscribing to events
    import static my.sample.Constants.MY_TOPIC;
    import static org.eclipse.fx.core.event.EventBus.data;
    public void init(org.eclipse.fx.core.event.EventBus eventBus) {
      eventBus.subscribe( MY_TOPIC, data(this::handleTopic) );
    private void handleTopic(String data) {
      // ...

If you are interested in other new features of 2.2.0 look at this overview page

This entry was posted in e(fx)clipse. Bookmark the permalink.

1 Response to e(fx)clipse 2.2.0 – Typesafe EventBus

  1. Pingback: Why I think @UIEventTopic / @EventTopic have been a bad idea | Tomsondev Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.