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

java.lang.Object
  extended by org.eclipse.ocl.examples.eventmanager.framework.EventManagerTableBased
All Implemented Interfaces:
EventManager

public class EventManagerTableBased
extends java.lang.Object
implements EventManager

A scalable implementation of the EventManager interface, using hash tables to quickly dispatch incoming Notifications to the sets of registered event listeners. Uses a single EContentAdapter to listen to all changes in those ResourceSets for which it is responsible.

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

Field Summary
protected  java.util.WeakHashMap<org.eclipse.emf.common.notify.Adapter,java.util.Collection<AdapterCapsule>> notifierByListener
          listeners are not notified directly.
 
Constructor Summary
EventManagerTableBased()
           
EventManagerTableBased(org.eclipse.emf.ecore.resource.ResourceSet set)
           
 
Method Summary
 void addToObservedResourceSets(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
          Adds resourceSet to the resource sets from which this event manager receives notifications that it dispatches to adapters subscribed to this event manager.
 void beginCommand()
           
 void cancelCommand()
           
 void deregister(org.eclipse.emf.common.notify.Adapter listener)
           
protected  void finalize()
           
 void fireChangeEvent(org.eclipse.emf.common.notify.Notification event)
           
 void firePreChangeEvent(org.eclipse.emf.common.notify.Notification event)
           
 void handleEMFEvent(org.eclipse.emf.common.notify.Notification notification)
          Initialize the filtering process for a given Notification, all Adapter registered with a matching filter will be notified.
 void postCommitCommand()
           
 void preCommitCommand()
           
 void registerCommitListener(org.eclipse.emf.common.notify.Adapter listener, AbstractEventFilter eventFilterTree)
           
 void registerPreChangeListener(org.eclipse.emf.common.notify.Adapter listener, AbstractEventFilter eventFilterTree)
           
 void registerPreCommitListener(org.eclipse.emf.common.notify.Adapter listener, AbstractEventFilter eventFilterTree)
           
 void removeFromObservedResourceSets(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
          Stops receiving and dispatching notifications coming from resourceSet.
 void setActive(boolean active)
          Sometimes it can be convenient to temporarily stop the flow of events.
 void setFireEvents(boolean doFireEventsValue)
          Toogle the EventManager off, on given false and no Notifications will be delivered
 void subscribe(EventFilter eventFilterTree, org.eclipse.emf.common.notify.Adapter listener)
          Register an Adapter on the EventManager which will be notified for any Notification which matches the given filter.
 java.lang.String toString()
           
 boolean unsubscribe(org.eclipse.emf.common.notify.Adapter caller)
          Removes the given Adapter from the EventManager and the linked AbstractEventFilter, so that the given Adapter will not be notified anymore
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

notifierByListener

protected java.util.WeakHashMap<org.eclipse.emf.common.notify.Adapter,java.util.Collection<AdapterCapsule>> notifierByListener
listeners are not notified directly. The notification process is done by the appropriate AdapterCapsule. This Map provides the associated AdapterCapsule for a Listener. For each type of Listener there is a separate AdapterCapsule (That's why there might be multiple AdapterCapsules for one Listener instance (the instance could have been registered multiple times))

Constructor Detail

EventManagerTableBased

public EventManagerTableBased(org.eclipse.emf.ecore.resource.ResourceSet set)

EventManagerTableBased

public EventManagerTableBased()
Method Detail

setFireEvents

public void setFireEvents(boolean doFireEventsValue)
Toogle the EventManager off, on given false and no Notifications will be delivered

Parameters:
doFireEventsValue - false to disable Notificationdelivery, true to enable

setActive

public void setActive(boolean active)
Description copied from interface: EventManager
Sometimes it can be convenient to temporarily stop the flow of events. For example, if a particular event manager receives a particular set of events for a certain reason, and that reason temporarily doesn't apply, instead of completely removing the event manager from the underlying ResourceSet and thus removing the adapter from all objects in the resource set, it is more efficient to just block forwarding the events to the Adapters subscribed with this event manager.

Calling this method with active==false will stop this event manager from forwarding events to the Adapters subscribed. Calling it with active==true again will forward events received after the call again. Events that arrived in between are not forwarded and therefore "lost" for the subscribers to this event manager.

By default, an event manager starts in the "active" state.

Specified by:
setActive in interface EventManager

subscribe

public void subscribe(EventFilter eventFilterTree,
                      org.eclipse.emf.common.notify.Adapter listener)
Description copied from interface: EventManager
Register an Adapter on the EventManager which will be notified for any Notification which matches the given filter. If an equal or the same caller registers multiple times using equal filters, the caller will get notified as many times as it subscribed.

Specified by:
subscribe in interface EventManager
Parameters:
eventFilterTree - the AbstractEventFilter which is used to filter events for the given Adapter. Currently, there are still a few limitations as to the filter trees permissible. It is considered an error if the filter, after conversion into disjunctive normal form, contains more than one filter of a kind in an "AND" clause. Such filters, passed to this method, cause an IllegalArgumentException to be thrown.
listener - the adapter which should receive event which matches the filter. This event manager will only maintain weak references to the listener which means that the client should hold a strong reference in order to make sure that notifications will be received. This is a good idea anyhow since for de-registration using EventManager.unsubscribe(Adapter) the listener is required as well.

registerPreChangeListener

public void registerPreChangeListener(org.eclipse.emf.common.notify.Adapter listener,
                                      AbstractEventFilter eventFilterTree)

registerCommitListener

public void registerCommitListener(org.eclipse.emf.common.notify.Adapter listener,
                                   AbstractEventFilter eventFilterTree)

registerPreCommitListener

public void registerPreCommitListener(org.eclipse.emf.common.notify.Adapter listener,
                                      AbstractEventFilter eventFilterTree)

deregister

public void deregister(org.eclipse.emf.common.notify.Adapter listener)

fireChangeEvent

public void fireChangeEvent(org.eclipse.emf.common.notify.Notification event)

firePreChangeEvent

public void firePreChangeEvent(org.eclipse.emf.common.notify.Notification event)

beginCommand

public void beginCommand()

postCommitCommand

public void postCommitCommand()

preCommitCommand

public void preCommitCommand()

cancelCommand

public void cancelCommand()

handleEMFEvent

public void handleEMFEvent(org.eclipse.emf.common.notify.Notification notification)
Description copied from interface: EventManager
Initialize the filtering process for a given Notification, all Adapter registered with a matching filter will be notified. Normally, clients don't have to call this method explicitly. It will be called by the event manager automatically when an event has been received from any elements in the ResourceSet for which the event manager has been obtained (see EventManagerFactory.getEventManagerFor(ResourceSet)). However, for testing purposes and in case clients want to explicitly send events that have not emerged from the ResourceSet to registered clients, they may use this method.

Specified by:
handleEMFEvent in interface EventManager
Parameters:
notification - Notification to send to clients whose event filter matches the notification

unsubscribe

public boolean unsubscribe(org.eclipse.emf.common.notify.Adapter caller)
Description copied from interface: EventManager
Removes the given Adapter from the EventManager and the linked AbstractEventFilter, so that the given Adapter will not be notified anymore

Specified by:
unsubscribe in interface EventManager
Parameters:
caller - the Adapter to unsubscribe
Returns:
true if the adapter was registered

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

toString

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

addToObservedResourceSets

public void addToObservedResourceSets(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Description copied from interface: EventManager
Adds resourceSet to the resource sets from which this event manager receives notifications that it dispatches to adapters subscribed to this event manager. If this event manager already does receive notifications from resourceSet it is not registered a second time. In particular, it won't receive the same notifications multiple times.

Specified by:
addToObservedResourceSets in interface EventManager
See Also:
EventManager.removeFromObservedResourceSets(ResourceSet)

removeFromObservedResourceSets

public void removeFromObservedResourceSets(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
Description copied from interface: EventManager
Stops receiving and dispatching notifications coming from resourceSet.

Specified by:
removeFromObservedResourceSets in interface EventManager
See Also:
EventManager.addToObservedResourceSets(ResourceSet)