org.eclipse.ocl.examples.eventmanager.framework
Class RegistrationManagerTableBased

java.lang.Object
  extended by org.eclipse.ocl.examples.eventmanager.framework.RegistrationManagerTableBased

public class RegistrationManagerTableBased
extends java.lang.Object

The RegistrationManager is responsible for storing the listeners and their registrations and for computing the set of affected listeners for a certain event.
The RegistrationManager has knowledge about several things:


The first two points are defined in the init() method which is implemented in the subclass RegistrationManagerTableBased because originally there also were other subtypes of RegistrationManager (e.g. the GlobalRegistrationManager).
This knowledge enables the RegistrationManager to fill the EventFilterTables with new registrations and to compute all listeners that are registered to a certain event. The knowledge of the registrations that belong to a listener is primary for performance improvement at deregistration time. The TableForEventFilter provide registrations for an event in one context. When an event is being fired, the RegistrationManager will know which EventFilterTables to ask and can collect all registrations from all affected EventFilterTables. The RegistrationManager has the overview and can merge these candidates into a consolidated set of registrations. Afterwards these Registrations are converted into listeners that will have to be notified.

Author:
Daniel Vocke (D044825), Axel Uhl (D043530)

Field Summary
protected  TableForEventFilter eventTypeFilterTable
           
protected  java.util.Set<TableForEventFilter> tablesWithNegatedRegistrations
           
 
Constructor Summary
RegistrationManagerTableBased()
           
 
Method Summary
protected  void addTableForEventType(TableForEventFilter table, java.lang.Integer eventType)
          This method fills the tablesByEventType member with the passed parameters.
protected  void createAllTables(int size)
           
protected  java.util.Set<org.eclipse.ocl.examples.eventmanager.framework.Registration>[] createRegistrationSetArray()
          Creates an array that has length 2^filterTypeToBitMask.size() so that any combination of bit mask used as value in filterTypeToBitMask can be used as index into such an array.
 void deregister(org.eclipse.emf.common.notify.Adapter listener)
          Removes all registrations that belong to the passed listener from all EventFilterTables.
 void deregister(java.lang.ref.Reference<? extends org.eclipse.emf.common.notify.Adapter> listenerRef)
           
static int getDepth(LogicalOperationFilterImpl filter)
          Computes the depth of the subtree.
static OrFilter getDisjunctiveNormalForm(LogicalOperationFilterImpl filter)
          Transforms the (sub-)tree into disjunctive normal form.
 java.util.Collection<java.lang.ref.WeakReference<? extends org.eclipse.emf.common.notify.Adapter>> getListenersFor(org.eclipse.emf.common.notify.Notification event)
          This method returns a Collection of Adapters that were registered for the passed event.
protected  java.util.Collection<TableForEventFilter> getTablesForBitSet(int bitSet)
          When passing a bit set as returned by getBitSet(Collection), returns the collection of filter tables identified by this bit set.
protected  void init()
          The implementation of the init() method initialises the members above.
 boolean isListenerRegistered(org.eclipse.emf.common.notify.Adapter listener)
           
 int redundantFilters()
          Mostly for debugging and analysis.
 void register(EventFilter filterTree, java.lang.ref.WeakReference<? extends org.eclipse.emf.common.notify.Adapter> listener, ListenerTypeEnum listenerType)
          registers a listener with the passed filter expression.
protected  void registerTable(TableForEventFilter table, int posInAllTables)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

eventTypeFilterTable

protected TableForEventFilter eventTypeFilterTable

tablesWithNegatedRegistrations

protected java.util.Set<TableForEventFilter> tablesWithNegatedRegistrations
Constructor Detail

RegistrationManagerTableBased

public RegistrationManagerTableBased()
Method Detail

init

protected void init()
The implementation of the init() method initialises the members above. Performs the "configuration" of the RegistrationManager.


createAllTables

protected void createAllTables(int size)

register

public void register(EventFilter filterTree,
                     java.lang.ref.WeakReference<? extends org.eclipse.emf.common.notify.Adapter> listener,
                     ListenerTypeEnum listenerType)
registers a listener with the passed filter expression. The returned object of type RegistrationHandle is intended to be used as handle for deregistration puposes.

Parameters:
filterTree - the filter expression (may also be a tree)
listener - the listener to register

deregister

public void deregister(org.eclipse.emf.common.notify.Adapter listener)
Removes all registrations that belong to the passed listener from all EventFilterTables. The listener will not receive any events any more. This method is synchronized because there must be no changes to the FilterTables while they are working.

Parameters:
listener - the listener to deregister

deregister

public void deregister(java.lang.ref.Reference<? extends org.eclipse.emf.common.notify.Adapter> listenerRef)

getListenersFor

public java.util.Collection<java.lang.ref.WeakReference<? extends org.eclipse.emf.common.notify.Adapter>> getListenersFor(org.eclipse.emf.common.notify.Notification event)
This method returns a Collection of Adapters that were registered for the passed event.

Parameters:
event -
Returns:
a Collection of listeners that are registered for the passed event

isListenerRegistered

public boolean isListenerRegistered(org.eclipse.emf.common.notify.Adapter listener)
Parameters:
listener -
Returns:
whether the listener is registered

addTableForEventType

protected void addTableForEventType(TableForEventFilter table,
                                    java.lang.Integer eventType)
This method fills the tablesByEventType member with the passed parameters. It is only used in the init() method of subclasses.

Parameters:
table -
eventType -

getDisjunctiveNormalForm

public static OrFilter getDisjunctiveNormalForm(LogicalOperationFilterImpl filter)
Transforms the (sub-)tree into disjunctive normal form. This special form is needed internally for the following processing. The tree is not cloned before processing, so the clients that plan to reuse their FilterTrees will have to clone them using Object.clone() before registering to the EventFramework or invoking this method.

Returns:
a filter tree in disjunctive normal form which has exactly the same semantics like the original tree

getDepth

public static int getDepth(LogicalOperationFilterImpl filter)
Computes the depth of the subtree. NotFilters are ignored while computing the depth.

Returns:
the maximal depth of the tree.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createRegistrationSetArray

protected java.util.Set<org.eclipse.ocl.examples.eventmanager.framework.Registration>[] createRegistrationSetArray()
Creates an array that has length 2^filterTypeToBitMask.size() so that any combination of bit mask used as value in filterTypeToBitMask can be used as index into such an array.


registerTable

protected void registerTable(TableForEventFilter table,
                             int posInAllTables)

getTablesForBitSet

protected java.util.Collection<TableForEventFilter> getTablesForBitSet(int bitSet)
When passing a bit set as returned by getBitSet(Collection), returns the collection of filter tables identified by this bit set.


redundantFilters

public int redundantFilters()
Mostly for debugging and analysis. Expects the AndFilters to be stored in the Registrations. Scans through all Registration objects known by this event manager and determines how many overlapping distinct registrations with equal AndFilter there are. This is a prerequisite to judging how much of a performance improvement we may gain if we try to collate registrations with equal filters.