org.openstreetmap.osmosis.core.store
Class ChunkedObjectStore<T extends Storeable>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.store.ChunkedObjectStore<T>
Type Parameters:
T - The class type to be stored.
All Implemented Interfaces:
Completable, Releasable

public class ChunkedObjectStore<T extends Storeable>
extends java.lang.Object
implements Completable

Adds indexed chunking capabilities to a basic object store allowing groups of objects to be written and retrieved later by their chunk index. The number of objects and the size of the index is limited only by disk space.

This store is only suitable for single-threaded use because it does not provide per-thread readers.

Author:
Brett Henderson

Constructor Summary
ChunkedObjectStore(ObjectSerializationFactory serializationFactory, java.lang.String storageFilePrefix, java.lang.String indexFilePrefix, boolean useCompression)
          Creates a new instance.
 
Method Summary
 void add(T data)
          Adds the specified object to the store.
 void closeChunk()
          Stops the current writing operation and begins a new one saving the current position against a new interval index.
 void complete()
          Ensures that all information is fully persisted.
 long getChunkCount()
          Returns the number of chunks managed by this store.
 ReleasableIterator<T> iterate(long chunk)
          Provides access to the contents of this store.
 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

ChunkedObjectStore

public ChunkedObjectStore(ObjectSerializationFactory serializationFactory,
                          java.lang.String storageFilePrefix,
                          java.lang.String indexFilePrefix,
                          boolean useCompression)
Creates a new instance.

Parameters:
serializationFactory - The factory defining the object serialisation implementation.
storageFilePrefix - The prefix of the storage file name.
indexFilePrefix - The prefix of the index file name.
useCompression - If true, the storage file will be compressed.
Method Detail

add

public void add(T data)
Adds the specified object to the store.

Parameters:
data - The object to be added.

closeChunk

public void closeChunk()
Stops the current writing operation and begins a new one saving the current position against a new interval index.


getChunkCount

public long getChunkCount()
Returns the number of chunks managed by this store. This count will include the in progress chunk if one exists.

Returns:
The number of chunks.

iterate

public ReleasableIterator<T> iterate(long chunk)
Provides access to the contents of this store.

Parameters:
chunk - The chunk to read objects from.
Returns:
An iterator providing access to contents of the store.

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