org.mmbase.core.event
Class EventBroker

java.lang.Object
  extended by org.mmbase.core.event.EventBroker
Direct Known Subclasses:
AbstractEventBroker, WeakEventBroker

public abstract class EventBroker
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 does 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
Version:
$Id: EventBroker.java 41174 2010-02-25 22:14:09Z michiel $
Author:
Ernst Bunders

Constructor Summary
EventBroker()
           
 
Method Summary
abstract  boolean addListener(EventListener listener)
           
protected abstract  Collection<EventListener> backing()
           
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)
           
 Collection<EventListener> getListeners()
           
 int hashCode()
           
protected abstract  void notifyEventListener(Event event, EventListener listener)
          This method has two functions.
 void notifyForEvent(Event event)
           
abstract  void removeListener(EventListener listener)
           
abstract  String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EventBroker

public EventBroker()
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 abstract boolean addListener(EventListener listener)

removeListener

public abstract void removeListener(EventListener listener)

backing

protected abstract Collection<EventListener> backing()
Since:
MMBase-1.8.5

getListeners

public Collection<EventListener> getListeners()
Since:
MMBase-1.8.5

notifyForEvent

public void notifyForEvent(Event event)

toString

public abstract String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


MMBase 2.0-SNAPSHOT - null