net.groboclown.eventbus.v2
Class EventBus

java.lang.Object
  |
  +--net.groboclown.eventbus.v2.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.

This has been redesigned to allow for multiple busses to co-exist within the same VM.

Version:
Alpha 0.9.0
Author:
Matt Albrecht

Field Summary
private static boolean DEBUG
           
private  LinkedList eventDistributors
           
private  HashMap filterId
           
private  HashMap idFilter
           
private  HashMap idObject
           
private  EventBusId localBusId
           
private  String localBusName
           
private  HashMap objectId
           
private  Object syncObj
           
 
Constructor Summary
EventBus()
          Default constructor
 
Method Summary
 void addEventDistributor(Class c)
           
 void addEventDistributor(IEventDistributor ed)
           
 void addEventDistributor(String className)
           
 void addListener(IEventBusListener listener)
          Add the given listener to the list, and generates a filter agent.
private static void debug(String text)
           
private static void debug(String text, Throwable t)
           
 String getBusId()
           
protected  EventBusId getEventId(Object obj)
           
 IEventBusListener[] getListenersForEvent(EventBusEvent ebe)
          Used by EventDistributors to retrieve the list of listeners for the given event.
 Object getLocalObject(EventBusId id)
           
protected  void loadExternalDistributors()
           
 void redirectEvent(EventBusEvent ebe)
          Redirects an EventBusEvent object to this bus's distributor list.
 boolean removeEventDistributor(IEventDistributor ed)
           
 boolean removeListener(IEventBusListener listener)
          Deregister the given listener and its filter.
protected  void sendBusEvent(String method, EventBusId data)
           
 void sendEvent(Object source, Serializable 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

syncObj

private Object syncObj

eventDistributors

private LinkedList eventDistributors

idObject

private HashMap idObject

objectId

private HashMap objectId

filterId

private HashMap filterId

idFilter

private HashMap idFilter

localBusName

private String localBusName

localBusId

private EventBusId localBusId

DEBUG

private static final boolean DEBUG
Constructor Detail

EventBus

public EventBus()
Default constructor
Method Detail

addEventDistributor

public void addEventDistributor(String className)
                         throws IllegalArgumentException

addEventDistributor

public void addEventDistributor(Class c)
                         throws IllegalArgumentException

addEventDistributor

public void addEventDistributor(IEventDistributor ed)
                         throws RemoteException

removeEventDistributor

public boolean removeEventDistributor(IEventDistributor ed)

addListener

public void addListener(IEventBusListener listener)
                 throws RemoteException
Add the given listener to the list, and generates a filter agent.

removeListener

public boolean removeListener(IEventBusListener listener)
Deregister the given listener and its filter.
Returns:
true if the listener was found and removed, or false if it could not be found.

getListenersForEvent

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

sendEvent

public void sendEvent(Object source,
                      Serializable data)
Sends the event with the given data to the correct listeners. The sending to the distributors occurs in this thread, while the distributor sending may occur in any thread.

redirectEvent

public void redirectEvent(EventBusEvent ebe)
Redirects an EventBusEvent object to this bus's distributor list.

getLocalObject

public Object getLocalObject(EventBusId id)

getBusId

public String getBusId()

loadExternalDistributors

protected void loadExternalDistributors()

getEventId

protected EventBusId getEventId(Object obj)

sendBusEvent

protected void sendBusEvent(String method,
                            EventBusId data)

debug

private static final void debug(String text)

debug

private static final void debug(String text,
                                Throwable t)


Written under the LGPL