|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Spool
An unwindable spool of holds. It models the 'closure' of an object, and the unwinding of its state. As an object takes hold of resources that later need to be released, it may formally model them Holds, and wind them onto a spool. The spool unwinds later, at closure, and releases the holds.
An example is listener registration. This is state that often needs to be unwound, in order to prevent memory leaks. Using a spool, both registration and unregistration may be coded together in line. For example:
registry.addListener( C.this ); spool.add( new Hold() { public void release() { registry.removeListener( C.this ); } });
The life cycle of spools follows two common patterns. In one, a spool is created internally by the object, and later unwound by it (in a public close() method, for example) In the other pattern, a spool is passed to the object by a contruction parameter, and later unwound by its creator (effectively destroying the object, and any others that had wound themselves onto it). The latter is the more common pattern; but textbender's codebase is full of examples of both.
Field Summary | |
---|---|
static Catcher0<Hold> |
catcher0
A common instance of a null catcher. |
Method Summary | |
---|---|
boolean |
add(Hold hold)
Adds the hold to the spool, or releases it immediately. |
boolean |
isUnwinding()
Returns true if the spool is unwinding (or unwound). |
boolean |
unwind()
Commences to unwind this spool. |
boolean |
unwind(Catcher<Hold> catcher)
Commences to unwind this spool, removing and releasing each of its holds. |
Methods inherited from interface java.util.Collection |
---|
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
Field Detail |
---|
static final Catcher0<Hold> catcher0
Method Detail |
---|
boolean add(Hold hold)
add
in interface Collection<Hold>
IllegalStateException
- if this contract cannot be met
(e.g. if the spool runs out of space, and no other unchecked exception applies)boolean isUnwinding()
boolean unwind()
boolean unwind(Catcher<Hold> catcher)
catcher
- for any errors or exceptions that occur
during unwinding
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |