org.openstreetmap.osmosis.core.lifecycle
Class CompletableContainer

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

public class CompletableContainer
extends java.lang.Object
implements Completable

A container for completable objects that require complete and release calls to be performed as a unit.

Author:
Brett Henderson

Constructor Summary
CompletableContainer()
          Creates a new instance.
 
Method Summary
<T extends Completable>
T
add(T object)
          Adds a new object to be managed.
 void complete()
          Ensures that all information is fully persisted.
 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

CompletableContainer

public CompletableContainer()
Creates a new instance.

Method Detail

add

public <T extends Completable> 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.

complete

public void complete()
Ensures that all information is fully persisted. This includes database commits, file buffer flushes, etc. Implementations must call complete on any nested Completable objects. Where the releasable method of a Releasable class should be called within a finally block, this method should typically be the final statement within the try block.

Specified by:
complete in interface Completable

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