Generic, annotation-driven event notification frameworks

You can already do this today with EventBus.

Following example is from EventBus Getting Started guide. Statusbar that updates based on published events, and no need to register statusbar control/widget as listener of publisher(s). Without EventBus, statusbar will need to be added as listener to many classes. Statusbar can also be created and destroyed at any time.

public StatusBar extends JLabel {
    public StatusBar() {
        AnnotationProcessor.process(this);
    }
    @EventSubscriber(eventClass=StatusEvent.class)
    public void updateStatus(StatusEvent statusEvent) {
        this.setText(statusEvent.getStatusText();
    }
}

A similar project is ELF (Event Listener Framework) but it seems to be less mature.

I'm currently researching about event notification frameworks on Publish-Subscribe Event Driven Programming | Kev's Spring vs Java EE Dev and the followup articles.


I've made http://neoevents.googlecode.com to handle this kind of annotation based event handler.

@actionPerformed
private void onClick() {
    //do something
}

protected void initComponents() {
    JButton button = new JButton("Click me!!!");
    button.addActionListener(new ActionListener(this) );
}

It looks as simple as I was expecting it to be. Annotations are available for every single listener in J2SE.


Don't mistake complicated for clever. It seems to me that this would be:

  1. A nightmare to debug
  2. Difficult to follow (from a maintenance perspective, or someone attempting to change something 6 months down the line)
  3. Full of if (event instanceof NodeCreatedEvent) like code. Why this is better than subclassing an adapter I have no idea!