gumbo.util
Class AbstractDisposable

java.lang.Object
  |
  +--gumbo.util.AbstractDisposable
All Implemented Interfaces:
Disposable
Direct Known Subclasses:
AbstractDelegatable, AbstractKeyboardSensor, AbstractMouseSensor, AbstractTreeNodeDelegator, Connection, DataModel, DataView, EventNode, MainWindow, MessageAgent, NullGraphicView, Relationship, SwingDataProxy

public abstract class AbstractDisposable
extends java.lang.Object
implements Disposable

A full implementation of the Disposable interface that includes detection and blocking of disposal cycles. Subclasses must implement implDispose(), which is called by dispose() when it is time for subclasses to dispose themselves.

Subclasses should chain disposal by calling super.implDispose() after disconnecting and/or disposing relations but before disposing any internal state. This assures that the state of the class and the superclass are valid during disconnect and super disposal, which may also involve disconnects requiring valid super and subclass state. protected void implDispose() { // disconnect/dispose relations (first) ... // dispose super super.implDispose(); // dispose self (last) ... }

Since finalization can seriously impact garbage collection performance, by default, finalize() is not called. If disposal is required as part of finalization then finalize() should be overridden as follows. Note that the finalizer is chained to the super class, which is placed in a finally clause to assure execution in case of an exception during disposal. protected void finalize() throws Throwable { try { dispose(); } finally { super.finalize(); } }

The dispose() method is final to prevent subclasses from breaking its internal busy (for cycle blocking) and disposed flags. The isDisposed() method is not final, which allows subclasses to perform local disposal detection (such as for native graphic resource).

If extended by a serializable subclass, the subclass should throw an exception if it is disposed and serialization is attempted. Otherwise, no state needs to be sent via custom serialization (the received object will be initialized as not disposed).

Version:
$Revision: 1.8 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.

Constructor Summary
AbstractDisposable()
           
 
Method Summary
 void dispose()
          Subclasses must override implDispose(), not this method, to perform the actual self-disposal.
protected abstract  void implDispose()
          Called by dispose() before the disposed flag is set, when it is time for subclasses to dispose themselves.
 boolean isDisposed()
          Typically there is no need to override this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDisposable

public AbstractDisposable()
Method Detail

implDispose

protected abstract void implDispose()
Called by dispose() before the disposed flag is set, when it is time for subclasses to dispose themselves. Implentors should disconnect and/or dispose any relations (while the object is still valid), then null out any external references, and then call super.implDispose() to assure that the super class is disposed of properly.


dispose

public final void dispose()
Subclasses must override implDispose(), not this method, to perform the actual self-disposal. This method first calls isDisposed(), and does nothing if it returns true; otherwise, it checks a busy flag to block mutual disposal, calls implDispose(), then sets the disposed flag.

Specified by:
dispose in interface Disposable

isDisposed

public boolean isDisposed()
Typically there is no need to override this method. The default implementation returns true if the disposed flag has been set true, which only dispose() can do.

Specified by:
isDisposed in interface Disposable
Returns:
True if this object has been disposed.