org.sdnplatform.sync.internal.store
Class InMemoryStorageEngine<K,V>

java.lang.Object
  extended by org.sdnplatform.sync.internal.store.InMemoryStorageEngine<K,V>
All Implemented Interfaces:
IStorageEngine<K,V>, IStore<K,V>

public class InMemoryStorageEngine<K,V>
extends java.lang.Object
implements IStorageEngine<K,V>

A simple non-persistent, in-memory store.


Field Summary
protected  int tombstoneDeletion
          Interval in milliseconds before tombstones will be cleared.
 
Constructor Summary
InMemoryStorageEngine(java.lang.String name)
           
InMemoryStorageEngine(java.lang.String name, java.util.concurrent.ConcurrentMap<K,java.util.List<Versioned<V>>> map)
           
 
Method Summary
 void cleanupTask()
          Perform any periodic cleanup tasks that might need to be performed.
 void close()
          Close the store.
 boolean containsKey(K key)
          Check whether the given key is present in the store
 boolean doput(K key, Versioned<V> value)
           
 IClosableIterator<java.util.Map.Entry<K,java.util.List<Versioned<V>>>> entries()
          Get an iterator over pairs of entries in the store.
 java.util.List<Versioned<V>> get(K key)
          Get the value associated with the given key
 java.lang.String getName()
           
 java.util.List<IVersion> getVersions(K key)
          Get a list of the versions associated with the given key
 boolean isPersistent()
          Returns true if the underlying data store is persistent
 IClosableIterator<K> keys()
          Get an iterator over keys in the store.
 void put(K key, Versioned<V> value)
          Associate the value with the key and version in this store
 java.util.List<Versioned<V>> remove(K key)
          Atomically remove the key and return the value that was mapped to it, if any
 void setTombstoneInterval(int interval)
          Set the interval after which tombstones will be cleaned up.
 int size()
          Get the number of keys currently in the store
 java.lang.String toString()
           
protected  java.lang.String toString(int size)
           
 void truncate()
          Truncate all entries in the store.
 boolean writeSyncValue(K key, java.lang.Iterable<Versioned<V>> values)
          Write the given versioned values into the given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

tombstoneDeletion

protected int tombstoneDeletion
Interval in milliseconds before tombstones will be cleared.

Constructor Detail

InMemoryStorageEngine

public InMemoryStorageEngine(java.lang.String name)

InMemoryStorageEngine

public InMemoryStorageEngine(java.lang.String name,
                             java.util.concurrent.ConcurrentMap<K,java.util.List<Versioned<V>>> map)
Method Detail

close

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

Specified by:
close in interface IStore<K,V>

getVersions

public java.util.List<IVersion> getVersions(K 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<K,V>
Parameters:
key - the key
Returns:
the list of IVersion objects
Throws:
SyncException

get

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

Specified by:
get in interface IStore<K,V>
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

put

public void put(K key,
                Versioned<V> 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<K,V>
Parameters:
key - The key to use
value - The value to store and its version.
Throws:
SyncException

doput

public boolean doput(K key,
                     Versioned<V> value)
              throws SyncException
Throws:
SyncException

entries

public IClosableIterator<java.util.Map.Entry<K,java.util.List<Versioned<V>>>> 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<K,V>
Specified by:
entries in interface IStore<K,V>
Returns:
An iterator over the entries in this StorageEngine.

keys

public IClosableIterator<K> 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<K,V>
Returns:
An iterator over the keys in this StorageEngine.

truncate

public void truncate()
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<K,V>

getName

public java.lang.String getName()
Specified by:
getName in interface IStore<K,V>
Returns:
The name of the store.

writeSyncValue

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

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

cleanupTask

public void cleanupTask()
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<K,V>

isPersistent

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

Specified by:
isPersistent in interface IStorageEngine<K,V>
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<K,V>
Parameters:
interval - the interval in milliseconds

size

public int size()
Get the number of keys currently in the store

Returns:

remove

public java.util.List<Versioned<V>> remove(K key)
Atomically remove the key and return the value that was mapped to it, if any

Parameters:
key - the key to remove
Returns:
the mapped values

containsKey

public boolean containsKey(K key)
Check whether the given key is present in the store

Parameters:
key - the key
Returns:
true if the key is present

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

protected java.lang.String toString(int size)