org.sdnplatform.sync.internal.store
Class JavaDBStorageEngine

java.lang.Object
  extended by org.sdnplatform.sync.internal.store.JavaDBStorageEngine
All Implemented Interfaces:
IStorageEngine<ByteArray,byte[]>, IStore<ByteArray,byte[]>

public class JavaDBStorageEngine
extends java.lang.Object
implements IStorageEngine<ByteArray,byte[]>

Persistent storage engine that keeps its data in a JDB database

Author:
readams

Field Summary
protected static org.slf4j.Logger logger
           
 
Constructor Summary
JavaDBStorageEngine(java.lang.String name, javax.sql.ConnectionPoolDataSource dataSource)
          Construct a new storage engine that will use the provided engine as a delegate and provide persistence for its data.
 
Method Summary
 void cleanupTask()
          Perform any periodic cleanup tasks that might need to be performed.
 void close()
          Close the store.
 IClosableIterator<java.util.Map.Entry<ByteArray,java.util.List<Versioned<byte[]>>>> entries()
          Get an iterator over pairs of entries in the store.
 java.util.List<Versioned<byte[]>> get(ByteArray key)
          Get the value associated with the given key
static javax.sql.ConnectionPoolDataSource getDataSource(java.lang.String dbPath, boolean memory)
          Get a connection pool data source for use by Java DB storage engines
 java.lang.String getName()
           
 java.util.List<IVersion> getVersions(ByteArray key)
          Get a list of the versions associated with the given key
 boolean isPersistent()
          Returns true if the underlying data store is persistent
 IClosableIterator<ByteArray> keys()
          Get an iterator over keys in the store.
 void put(ByteArray key, Versioned<byte[]> value)
          Associate the value with the key and version in this store
 void setTombstoneInterval(int interval)
          Set the interval after which tombstones will be cleaned up.
 void truncate()
          Truncate all entries in the store.
 boolean writeSyncValue(ByteArray key, java.lang.Iterable<Versioned<byte[]>> values)
          Write the given versioned values into the given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.slf4j.Logger logger
Constructor Detail

JavaDBStorageEngine

public JavaDBStorageEngine(java.lang.String name,
                           javax.sql.ConnectionPoolDataSource dataSource)
                    throws PersistException
Construct a new storage engine that will use the provided engine as a delegate and provide persistence for its data. Note that the delegate engine must be empty when this object is constructed

Parameters:
delegate - the delegate engine to persist
Throws:
SyncException
PersistException
Method Detail

get

public java.util.List<Versioned<byte[]>> get(ByteArray key)
                                      throws SyncException
Description copied from interface: IStore
Get the value associated with the given key

Specified by:
get in interface IStore<ByteArray,byte[]>
Parameters:
key - The key to check for
Returns:
The value associated with the key or an empty list if no values are found.
Throws:
SyncException

entries

public IClosableIterator<java.util.Map.Entry<ByteArray,java.util.List<Versioned<byte[]>>>> entries()
Description copied from interface: IStorageEngine
Get an iterator over pairs of entries in the store. The key is the first element in the pair and the versioned value is the second element. Note that the iterator need not be threadsafe, and that it must be manually closed after use.

Specified by:
entries in interface IStorageEngine<ByteArray,byte[]>
Specified by:
entries in interface IStore<ByteArray,byte[]>
Returns:
An iterator over the entries in this StorageEngine.

put

public void put(ByteArray key,
                Versioned<byte[]> value)
         throws SyncException
Description copied from interface: IStore
Associate the value with the key and version in this store

Specified by:
put in interface IStore<ByteArray,byte[]>
Parameters:
key - The key to use
value - The value to store and its version.
Throws:
SyncException

keys

public IClosableIterator<ByteArray> keys()
Description copied from interface: IStorageEngine
Get an iterator over keys in the store. Note that the iterator need not be threadsafe, and that it must be manually closed after use.

Specified by:
keys in interface IStorageEngine<ByteArray,byte[]>
Returns:
An iterator over the keys in this StorageEngine.

truncate

public void truncate()
              throws SyncException
Description copied from interface: IStorageEngine
Truncate all entries in the store. Note that this is a purely local operation and all the data will sync back over of it's connected

Specified by:
truncate in interface IStorageEngine<ByteArray,byte[]>
Throws:
SyncException

getName

public java.lang.String getName()
Specified by:
getName in interface IStore<ByteArray,byte[]>
Returns:
The name of the store.

close

public void close()
           throws SyncException
Description copied from interface: IStore
Close the store.

Specified by:
close in interface IStore<ByteArray,byte[]>
Throws:
SyncException - If closing fails.

writeSyncValue

public boolean writeSyncValue(ByteArray key,
                              java.lang.Iterable<Versioned<byte[]>> values)
Description copied from interface: IStorageEngine
Write the given versioned values into the given key.

Specified by:
writeSyncValue in interface IStorageEngine<ByteArray,byte[]>
Parameters:
key - the key
values - the list of versions for that key
Returns:
true if any of the values were new and not obsolete

getVersions

public java.util.List<IVersion> getVersions(ByteArray key)
                                     throws SyncException
Description copied from interface: IStore
Get a list of the versions associated with the given key

Specified by:
getVersions in interface IStore<ByteArray,byte[]>
Parameters:
key - the key
Returns:
the list of IVersion objects
Throws:
SyncException

cleanupTask

public void cleanupTask()
                 throws SyncException
Description copied from interface: IStorageEngine
Perform any periodic cleanup tasks that might need to be performed. This method will be called periodically by the sync manager

Specified by:
cleanupTask in interface IStorageEngine<ByteArray,byte[]>
Throws:
SyncException

isPersistent

public boolean isPersistent()
Description copied from interface: IStorageEngine
Returns true if the underlying data store is persistent

Specified by:
isPersistent in interface IStorageEngine<ByteArray,byte[]>
Returns:
whether the store is persistent

setTombstoneInterval

public void setTombstoneInterval(int interval)
Description copied from interface: IStorageEngine
Set the interval after which tombstones will be cleaned up. This imposes an upper bound on the amount of time that two partitions can be separate before reaching consistency for any given key.

Specified by:
setTombstoneInterval in interface IStorageEngine<ByteArray,byte[]>
Parameters:
interval - the interval in milliseconds

getDataSource

public static javax.sql.ConnectionPoolDataSource getDataSource(java.lang.String dbPath,
                                                               boolean memory)
Get a connection pool data source for use by Java DB storage engines

Parameters:
dbPath - The path where the db will be located
memory - whether to actually use a memory database
Returns:
the ConnectionPoolDataSource