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

java.lang.Object
  extended by java.lang.Thread
      extended by org.eclipse.ocl.examples.eventmanager.framework.CleanupThread
All Implemented Interfaces:
java.lang.Runnable

public class CleanupThread
extends java.lang.Thread

Observes a reference queue and removes Adapter s from it. It weakly references an EventManagerTableBased. When a reference to an adapter was added to the queue and henceforth removed by this thread, this means that the adapter is no longer strongly referenced. A EventManagerTableBased.deregister(Reference) is issued to clean up after the adapeter.

When the event manager becomes eligible for garbage collection, its EventManagerTableBased.finalize() method stops this thread by calling stopCleaner().

Author:
Axel Uhl (d043530)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CleanupThread(java.lang.ref.ReferenceQueue<org.eclipse.emf.common.notify.Adapter> adaptersNoLongerStronglyReferenced, EventManagerTableBased eventManager)
           
 
Method Summary
 void run()
           
 void stopCleaner()
          Indirectly but cleanly stops this thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CleanupThread

public CleanupThread(java.lang.ref.ReferenceQueue<org.eclipse.emf.common.notify.Adapter> adaptersNoLongerStronglyReferenced,
                     EventManagerTableBased eventManager)
Method Detail

stopCleaner

public void stopCleaner()
Indirectly but cleanly stops this thread. This happens by nulling the stopThreadAdapter field which was the only strong reference to the adapter held by it. The weak reference in stopThreadMarker will therefore be enqueued which serves as the stop marker, causing the run() loop to terminate.


run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread