org.apache.cocoon.portal.event.impl
Class DefaultEventManager

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.portal.impl.AbstractComponent
          extended byorg.apache.cocoon.portal.event.impl.DefaultEventManager
All Implemented Interfaces:
Configurable, Contextualizable, Disposable, EventManager, Initializable, LogEnabled, Serviceable, ThreadSafe

public class DefaultEventManager
extends AbstractComponent
implements EventManager, Configurable

This is the default implementation of the event manager. For each event class (interface and impl.) a DefaultEventManager.HierarchyInfo is created. This helper object contains all subscribed receivers for the event and *all* parents being it interfaces or classes. This makes adding new receivers very easy: we just get the hierarchy info for the event in question and then add the receiver. Sending events is also very easy, we lookup the hierarchy info for the event, get all receivers for this event and notify them. Finally we iterate over all parents and notify the receivers of the all the parents. The simplicity in subscribing and sending of events comes with the drawback that unsubscribing is more costly.

Version:
$Id: DefaultEventManager.java 325961 2005-10-17 19:03:10Z cziegeler $

Nested Class Summary
protected static class DefaultEventManager.HierarchyInfo
           
protected static class DefaultEventManager.MethodInfo
           
protected static class DefaultEventManager.ReceiverInfo
           
 
Field Summary
protected  ServiceSelector aspectSelector
           
protected  EventAspectChain chain
           
protected  Configuration configuration
          Our configuration.
protected  Map eventHierarchy
          Map of all event classes and their corresponding receivers.
protected  Map receiverClasses
          Introspected receiver classes.
 
Fields inherited from class org.apache.cocoon.portal.impl.AbstractComponent
context, manager, portalService
 
Fields inherited from interface org.apache.cocoon.portal.event.EventManager
ROLE
 
Constructor Summary
DefaultEventManager()
           
 
Method Summary
protected  void addToHierarchy(DefaultEventManager.HierarchyInfo info, Class c)
           
protected  void addToHierarchy(DefaultEventManager.HierarchyInfo info, List parents)
           
 void configure(Configuration conf)
           
 void dispose()
           
protected  DefaultEventManager.HierarchyInfo getHierarchyInfo(Class c)
          Create a hierarchy information.
protected  Map getObjectModel()
          Helper method to get the current object model
 void initialize()
           
protected  List introspect(Class receiverClass)
           
 void processEvents()
          Process the events
 void send(Event event)
          Publish an event.
protected  void send(Event event, DefaultEventManager.HierarchyInfo hierarchy, boolean recursive)
           
 void subscribe(Receiver receiver)
          Subscribes a receiver for a specific type of event.
 void unsubscribe(Receiver receiver)
          Unsubscribes a receiver for all events.
 
Methods inherited from class org.apache.cocoon.portal.impl.AbstractComponent
contextualize, service
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected Configuration configuration
Our configuration.


chain

protected EventAspectChain chain

aspectSelector

protected ServiceSelector aspectSelector

receiverClasses

protected Map receiverClasses
Introspected receiver classes.


eventHierarchy

protected Map eventHierarchy
Map of all event classes and their corresponding receivers.

Constructor Detail

DefaultEventManager

public DefaultEventManager()
Method Detail

getObjectModel

protected Map getObjectModel()
Helper method to get the current object model


configure

public void configure(Configuration conf)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException
See Also:
Configurable.configure(org.apache.avalon.framework.configuration.Configuration)

dispose

public void dispose()
Specified by:
dispose in interface Disposable
Overrides:
dispose in class AbstractComponent
See Also:
Disposable.dispose()

initialize

public void initialize()
                throws Exception
Specified by:
initialize in interface Initializable
Overrides:
initialize in class AbstractComponent
Throws:
Exception
See Also:
Initializable.initialize()

processEvents

public void processEvents()
                   throws ProcessingException
Description copied from interface: EventManager
Process the events

Specified by:
processEvents in interface EventManager
Throws:
ProcessingException
See Also:
EventManager.processEvents()

send

public void send(Event event)
Description copied from interface: EventManager
Publish an event. All registered receivers get notified.

Specified by:
send in interface EventManager
Parameters:
event - The event to broadcast.
See Also:
EventManager.send(org.apache.cocoon.portal.event.Event)

send

protected void send(Event event,
                    DefaultEventManager.HierarchyInfo hierarchy,
                    boolean recursive)

introspect

protected List introspect(Class receiverClass)

subscribe

public void subscribe(Receiver receiver)
Description copied from interface: EventManager
Subscribes a receiver for a specific type of event.

Specified by:
subscribe in interface EventManager
See Also:
EventManager.subscribe(org.apache.cocoon.portal.event.Receiver)

unsubscribe

public void unsubscribe(Receiver receiver)
Description copied from interface: EventManager
Unsubscribes a receiver for all events.

Specified by:
unsubscribe in interface EventManager
See Also:
EventManager.unsubscribe(org.apache.cocoon.portal.event.Receiver)

getHierarchyInfo

protected DefaultEventManager.HierarchyInfo getHierarchyInfo(Class c)
Create a hierarchy information.


addToHierarchy

protected void addToHierarchy(DefaultEventManager.HierarchyInfo info,
                              Class c)

addToHierarchy

protected void addToHierarchy(DefaultEventManager.HierarchyInfo info,
                              List parents)


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.