org.openstreetmap.osmosis.core.lifecycle
Class ReleasableContainer

java.lang.Object
  extended by org.openstreetmap.osmosis.core.lifecycle.ReleasableContainer
All Implemented Interfaces:
Releasable

public class ReleasableContainer
extends java.lang.Object
implements Releasable

A container for releasable objects that must be freed. This implementation simplifies the creation of many releasable objects that must succeed or fail as a group. As each is created they are added to this container, and after they're all created successfully they can be cleared from this container.

Author:
Brett Henderson

Constructor Summary
ReleasableContainer()
          Creates a new instance.
 
Method Summary
<T extends Releasable>
T
add(T object)
          Adds a new object to be managed.
 void clear()
          Removes all objects.
 void release()
          Performs resource cleanup tasks such as closing files, or database connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReleasableContainer

public ReleasableContainer()
Creates a new instance.

Method Detail

add

public <T extends Releasable> T add(T object)
Adds a new object to be managed. The object is returned to allow method chaining.

Type Parameters:
T - The type of object being stored.
Parameters:
object - The object to be stored.
Returns:
The object that was stored.

clear

public void clear()
Removes all objects. They will no longer be released.


release

public void release()
Performs resource cleanup tasks such as closing files, or database connections. This must be called after all processing is complete and may be called multiple times. Implementations must call release on any nested Releasable objects. It should be called within a finally block to ensure it is called in exception scenarios.

Specified by:
release in interface Releasable