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

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

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

Provides a store for objects that can be located by a long identifier.

Author:
Brett Henderson

Constructor Summary
IndexedObjectStore(ObjectSerializationFactory serializationFactory, java.io.File objectStorageFile, java.io.File indexStorageFile)
          Creates a new instance.
IndexedObjectStore(ObjectSerializationFactory serializationFactory, java.lang.String tmpFilePrefix)
          Creates a new instance.
 
Method Summary
 void add(long id, T data)
          Adds the specified object to the store.
 void complete()
          Ensures that all information is fully persisted.
 IndexedObjectStoreReader<T> createReader()
          Creates a new reader capable of accessing 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

IndexedObjectStore

public IndexedObjectStore(ObjectSerializationFactory serializationFactory,
                          java.lang.String tmpFilePrefix)
Creates a new instance.

Parameters:
serializationFactory - The factory defining the object serialisation implementation.
tmpFilePrefix - The prefix of the storage file.

IndexedObjectStore

public IndexedObjectStore(ObjectSerializationFactory serializationFactory,
                          java.io.File objectStorageFile,
                          java.io.File indexStorageFile)
Creates a new instance.

Parameters:
serializationFactory - The factory defining the object serialisation implementation.
objectStorageFile - The storage file to use for objects.
indexStorageFile - The storage file to use for the index.
Method Detail

add

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

Parameters:
id - The identifier allowing the object to be retrieved.
data - The object to be added.

createReader

public IndexedObjectStoreReader<T> createReader()
Creates a new reader capable of accessing the contents of this store. The reader must be explicitly released when no longer required. Readers must be released prior to this store.

Returns:
A store reader.

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