The Event Framework Technical Reference

Abstract

Technical reference for [the new framework that was added as part of the queryResult cache release strategy project]


It is easy to add your own type of event. These can be MMBase related events or events that are pertinent to some application/extension you created. The great bonus is that your events are delivered across your mmbase cluster.

For every type of event you have to have two classes and one interface: an EventBroker, an Event and an EventListener interface.

This section tells you what you need to know about node and relation changes, how to use them, and how they all bounce and bounce inside MMBase these days.

This section tells you what you need to know about node and relation changes, how to use them, and how they all bounce and bounce inside MMBase these days.

Some things have changed in respect to the previous implementation using the org.mmbase.module.core.MMBaseObserver interface. This interface provided different methods for local and remote node changes. It was felt that this is not very useful; the usual practice seems to be to create one method to handle both types of events. It is still possible to determine if an event was local or remote by comparing the machine name of the event to the local one.

On the other hand was the information about the event provided to these methods very poor. This was the main motivation to change the event model.

The new org.mmbase.core.event.NodeEventListener and org.mmbase.core.event.RelationEventListener interfaces create a distinction between node and relation events. The classes org.mmbase.core.event.NodeEvent and org.mmbase.core.event.RelationEvent (and through them the events) provide much more information than before.

When you register a NodeEventListener or a RelationEventListener with the EventManager all node or relation events are propagated to it. This is many times what you want. In stead you want to listen to the events for nodes of a specific type. To make it as easy as it was before to register listeners to node and/or relation events of a specific builder, Some wrapper classes were created for NodeEventListener and RelationEventListener instances, that will filter the events for you (take a look at org.mmbase.core.event.TypedNodeEventListenerWrapper and org.mmbase.core.event.TypedRelationEventListenerWrapper. But you don't even have to use those directly. Both the MMBase and MMObjectBuilder classes have convenience methods to register your listeners. Take a look at Mmbase.addNodeRelatedEventsListener(String builder, Object listener) and MMObjectBuilder.addEventListener(Object listener). The object is your class implementing either NodeEventListener or RelationEventListener or both (discovered through introspection). Wrappers are created accordingly and registered as listeners.

This section provides insight into what happens when node and relation events are fired.

This section describes what happens when a local node or releation changes.

  1. Nodes are committed to the database by the StorageManager. When this has happened ChangeManager.commit() is called. Just as the StorageManager is there to handle all changes to the database when a node changes, the ChangeManager has this responsibility towards MMBase (i.e. Make sure every 'client' that needs to know about the change does do).

  2. The ChangeManager creates a NodeEvent instance and propagates it to the EventManager. If the changed node is a specialization of Insrel, a RelationEvent is subsequently created and propagated to the EventManager (EventManager.propagateEVent(Event)).

  3. The EventManager will find the brokers that can handle events of this type, and the event will be propagated to the broker's listeners. In case of a node or relation event, those include the builder matching the type of the event, the Obsterver instance for the event type. Mind you, for a node event the 'type' of the event is the builder of the node, while for a relation event it's type is both the relation source type as the relation destination type. The ClusterManager will receive the event regardless of it's type.

  4. The builder (all builders implement the NodeEventListener and the RelationEventListener) receiving the event will update it's node caches.

    The Observer receiving the event will iterate over all queries it holds reference to and evaluate the event against it to discover it the query must be flushed (for more information about QueryCache#Observer see the 'QueryCache Release Strategy' document).

    The ClusterManager implements the AllEventListener, so it will be notified for any and all event types. It will first check if the event is local. If this is so, it will serialize the event, and send it across the network to other nodes in the MMBase cluster.


This is part of the MMBase documentation.

For questions and remarks about this documentation mail to: [email protected]