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
    @PostConstruct
    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;
    
    @PostConstruct
    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

One thought on “e(fx)clipse 2.2.0 – Typesafe EventBus

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 )

Google+ photo

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

Connecting to %s