package textbender.g.hold; // Copyright 2005-2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.util.Collection; import textbender.g.lang.*; /** An unwindable spool of {@linkplain Hold 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 {@linkplain Hold Holds}, * and wind them onto a spool. The spool unwinds later, at closure, * and {@linkplain Hold#release() 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. *
*/ public interface Spool extends Collection