|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gumbo.util.AbstractDisposable
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).
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 |
public AbstractDisposable()
Method Detail |
protected abstract void implDispose()
public final void dispose()
dispose
in interface Disposable
public boolean isDisposed()
isDisposed
in interface Disposable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |