title: Generic, annotation-driven event notification frameworks
body: <p>While simple, interface-driven event notification frameworks in Java have been around since pre-Cambrian times (e.g. java.beans.PropertyChangeSupport), it is becoming increasingly popular for frameworks to use annotation-driven event notification instead.  </p>
  
  <p>For an example, see <a href="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/2.2.0.GA/userguide_en/html_single/index.html#api.listener" rel="noreferrer">JBossCache 2.2</a>. The listener class has its listener methods annotated, rather than conforming to a rigid interface. This is rather easier to program to, and easier to read, since you don't have to write empty implementations of listener callbacks that you're not interested in (and yes, I know about listener adapter superclasses).</p>
  
  <p>Here's a sample from the JBossCache docs:</p>
  
  <pre><code>@CacheListener
  public class MyListener {
     @CacheStarted
     @CacheStopped
     public void cacheStartStopEvent(Event e) {
           switch (e.getType()) {
              case Event.Type.CACHE_STARTED:
                 System.out.println("Cache has started");
                 break;    
              case Event.Type.CACHE_STOPPED:    
                 System.out.println("Cache has stopped");
                 break;    
           }
     }    
  
     @NodeCreated    
     @NodeRemoved
     @NodeVisited
     @NodeModified
     @NodeMoved
     public void logNodeEvent(NodeEvent ne) {
           log("An event on node " + ne.getFqn() + " has occured");
     }
  </code></pre>
  
  <p>}</p>
  
  <p>The problem with this, is that it's very much more of an involved process writing the framework to support this sort of thing, due to the annotation-reflection nature of it.</p>
  
  <p>So, before I charge off down the road of writing a generic framework, I was hoping someone had done it already. Has anyone come across such a thing?</p>