net.groboclown.eventbus.v1
Class EventBus

java.lang.Object
  |
  +--net.groboclown.eventbus.v1.EventBus

public class EventBus
extends Object

Master control unit which is in charge of registering event listeners, deregistering event listeners, and distributing events. There are no default distributors, so those must be manually added, or specified as external distributors through the command-line.

Version:
Alpha 0.9.0
Author:
Matt Albrecht

Field Summary
private  Hashtable classToMethodToListeners
           
private  Vector eventDistributors
           
private  Vector globalListeners
           
private  Hashtable justClassListeners
           
private  Hashtable justMethodListeners
           
protected static EventBus s_instance
           
 
Constructor Summary
protected EventBus()
          Default constructor - made protected so users won't instantiate the utility
 
Method Summary
 void addEventDistributor(Class c)
           
 void addEventDistributor(String className)
           
 void addListener(String evClass, String evMethod, IEventBusListener listener)
           
protected  void addStringListener(Hashtable h, String name, IEventBusListener listener)
           
static EventBus getInstance()
          Retrieve the shared instance of the utility class.
 IEventBusListener[] getListenersForEvent(EventBusObject ebo)
          Used by EventDistributors to retrieve the list of listeners for the given event.
protected  void loadExternalDistributors()
           
 boolean removeListener(String evClass, String evMethod, IEventBusListener listener)
          Deregister the given listener from the given class and method.
protected  boolean removeStringListener(Hashtable h, String name, IEventBusListener listener)
           
 void sendEvent(String evClass, String evName, Object source, Object data)
          Sends the event with the given data to the correct listeners.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

s_instance

protected static EventBus s_instance

eventDistributors

private Vector eventDistributors

globalListeners

private Vector globalListeners

justClassListeners

private Hashtable justClassListeners

justMethodListeners

private Hashtable justMethodListeners

classToMethodToListeners

private Hashtable classToMethodToListeners
Constructor Detail

EventBus

protected EventBus()
Default constructor - made protected so users won't instantiate the utility
Method Detail

getInstance

public static EventBus getInstance()
Retrieve the shared instance of the utility class.
Returns:
the utility instance

addEventDistributor

public void addEventDistributor(String className)
                         throws IllegalArgumentException

addEventDistributor

public void addEventDistributor(Class c)
                         throws IllegalArgumentException

addListener

public void addListener(String evClass,
                        String evMethod,
                        IEventBusListener listener)
Parameters:
evClass - the class to listen to, or null if you want to listen to any class.
evMethod - the method to listen to, or null if you want to listen to any method.

removeListener

public boolean removeListener(String evClass,
                              String evMethod,
                              IEventBusListener listener)
Deregister the given listener from the given class and method.
Returns:
true if the listener was found and removed, or false if it could not be found.

getListenersForEvent

public IEventBusListener[] getListenersForEvent(EventBusObject ebo)
Used by EventDistributors to retrieve the list of listeners for the given event.

sendEvent

public void sendEvent(String evClass,
                      String evName,
                      Object source,
                      Object data)
Sends the event with the given data to the correct listeners.

loadExternalDistributors

protected void loadExternalDistributors()

addStringListener

protected void addStringListener(Hashtable h,
                                 String name,
                                 IEventBusListener listener)

removeStringListener

protected boolean removeStringListener(Hashtable h,
                                       String name,
                                       IEventBusListener listener)


Written under the LGPL