org.mmbase.core.event
Class AbstractEventBroker

java.lang.Object
  extended byorg.mmbase.core.event.AbstractEventBroker
Direct Known Subclasses:
AllEventBroker, IdEventBroker, NodeEventBroker, RelationEventBroker

public abstract class AbstractEventBroker
extends Object

This is the base class for all event brokers in mmbase. the function of an event broker is to know about a specific kind of event, as well as a specific kind of event listener. All events should be derived from the org.mmbase.core.event.Event class, and all listeners from the org.mmbase.core.event.EventListener interface.
Allthough event listeners have to implement the EventListener interface, the actual method that will be called to pass on the event is not part of this interface, as it is specific for the kind of event you want to listen for. This is a contract between the broker implementation and the event listerer interface.
This class dous most of the work of keeping references to all the listeners and allowing for adding/removing them. Only a fiew type specific actions are delegated to the super class.
The EventListener also provides a method for passing on constraint properties to a event broker. If you want to create your own event type you can use this feature to accomplish that not all events of your type are propagated to the listener.

Since:
MMBase-1.8
Author:
Ernst Bunders

Field Summary
protected  Set listeners
           
 
Constructor Summary
AbstractEventBroker()
           
 
Method Summary
 boolean addListener(EventListener listener)
           
abstract  boolean canBrokerForEvent(Event event)
          this method should return true if this event broker can broker for events of this type.
abstract  boolean canBrokerForListener(EventListener listener)
          this method should return true if this broker can accept and propagate events to the listener of this type.
 boolean equals(Object o)
           
 int hashCode()
           
protected abstract  void notifyEventListener(Event event, EventListener listener)
          This method has two functions.
 void notifyForEvent(Event event)
           
 void removeListener(EventListener listener)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

listeners

protected Set listeners
Constructor Detail

AbstractEventBroker

public AbstractEventBroker()
Method Detail

canBrokerForListener

public abstract boolean canBrokerForListener(EventListener listener)
this method should return true if this broker can accept and propagate events to the listener of this type. There are no fixed criteria for this. Most implementions do event instanceof <EventListener associated with this broker>

Parameters:
listener -

canBrokerForEvent

public abstract boolean canBrokerForEvent(Event event)
this method should return true if this event broker can broker for events of this type. There are no fixed criteria for this. Most implementions do event instanceof <EvenType associated with this broker>

Parameters:
event -

notifyEventListener

protected abstract void notifyEventListener(Event event,
                                            EventListener listener)
                                     throws ClassCastException
This method has two functions. It must cast both event and listener to the proper type and invoke the event on the listener. But it must allso check if the listener has constraint properties set. if so it must use them to decide if the event should be invoked on this listener.

Parameters:
event -
listener -
Throws:
ClassCastException

addListener

public boolean addListener(EventListener listener)

removeListener

public void removeListener(EventListener listener)

notifyForEvent

public void notifyForEvent(Event event)

toString

public String toString()

equals

public boolean equals(Object o)

hashCode

public int hashCode()


MMBase build 1.8.1.20060716