Menu

#15 Improve handling of Netbean protocol Events

open-accepted
Bastl
None
5
2008-05-18
2007-10-20
David Terei
No

Don't like the way the VimConnection class handles events with the VimListener class. A received event is fired to all Listeners but this is inefficient seeing as an event will/should only ever trigger one listener.

Just using a big array/hash map of keys (event strings) to handler classes or methods seems the better option. Or just a giant switch statement.

We can still keep the basic handling of an event architecture which fires it to all listeners, but make one listener handle all events instead of an event per listener.

Discussion

  • Bastl

    Bastl - 2008-05-18

    Logged In: YES
    user_id=576604
    Originator: NO

    Right, i noticed that too recently. So mean something like:

    HashMap<String,Class> knownlisteners = new HashMap<String,Class>();

    knownlisteners.add("insert",TextInsert.class);
    // add Listener classes for all known events.

    for (IVimListener listener : listeners) {
    if (listener instanceof knownlisterns.get(ve.getEvent())
    listener.handleEvent(ve);
    }

    That way, the handleEvent methods in the Listener classes will get even simpler ... I like simple code :-)

     
  • Bastl

    Bastl - 2008-05-18
    • assigned_to: nobody --> bastl
    • status: open --> open-accepted
     

Log in to post a comment.