org.sdnplatform.sync.internal
Class DefaultStoreClient<K,V>

java.lang.Object
  extended by org.sdnplatform.sync.internal.AbstractStoreClient<K,V>
      extended by org.sdnplatform.sync.internal.DefaultStoreClient<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
IStoreClient<K,V>

public class DefaultStoreClient<K,V>
extends AbstractStoreClient<K,V>

Default implementation of a store client used for accessing a store locally in process.

Author:
readams

Nested Class Summary
protected  class DefaultStoreClient.StoreClientIterator
           
 
Field Summary
protected static org.slf4j.Logger logger
           
 
Constructor Summary
DefaultStoreClient(IStore<K,V> delegate, IInconsistencyResolver<Versioned<V>> resolver, AbstractSyncManager syncManager, java.lang.Class<K> keyClass, com.fasterxml.jackson.core.type.TypeReference<K> keyType)
           
 
Method Summary
 void addStoreListener(IStoreListener<K> listener)
          Add a listener that will be notified about changes to the given store.
protected  Versioned<V> defaultValue(Versioned<V> defaultValue)
           
 IClosableIterator<java.util.Map.Entry<K,Versioned<V>>> entries()
          Get an iterator that will get all the entries in the store.
 Versioned<V> get(K key, Versioned<V> defaultValue)
          Get the versioned value associated with the given key or the defaultValue if no value is associated with the key.
protected  Versioned<V> getItemOrThrow(K key, Versioned<V> defaultValue, java.util.List<Versioned<V>> items)
           
protected  java.util.List<IVersion> getVersions(K key)
          Get the versions for a key
protected  Versioned<V> handleGet(K key, Versioned<V> defaultValue, java.util.List<Versioned<V>> raw)
           
 IVersion put(K key, Versioned<V> versioned)
          Put the given Versioned value into the store for the given key if the version is greater to or concurrent with existing values.
 
Methods inherited from class org.sdnplatform.sync.internal.AbstractStoreClient
delete, delete, get, getValue, getValue, put, putIfNotObsolete
 
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

DefaultStoreClient

public DefaultStoreClient(IStore<K,V> delegate,
                          IInconsistencyResolver<Versioned<V>> resolver,
                          AbstractSyncManager syncManager,
                          java.lang.Class<K> keyClass,
                          com.fasterxml.jackson.core.type.TypeReference<K> keyType)
Method Detail

get

public Versioned<V> get(K key,
                        Versioned<V> defaultValue)
                 throws SyncException
Description copied from interface: IStoreClient
Get the versioned value associated with the given key or the defaultValue if no value is associated with the key.

Parameters:
key - The key for which to fetch the value.
Returns:
The versioned value, or the defaultValue if no value is stored for this key.
Throws:
SyncException

entries

public IClosableIterator<java.util.Map.Entry<K,Versioned<V>>> entries()
                                                               throws SyncException
Description copied from interface: IStoreClient
Get an iterator that will get all the entries in the store. Note that this has the potential to miss any values added while you're iterating through the collection, and it's possible that items will be deleted before you get to the end. Note that you *must* close the IClosableIterator when you are finished with it or there may be resource leaks. An example of how you should use this iterator to ensure that it is closed even if there are exceptions follows: IClosableIterator iter = store.entries(); try { // do your iteration } finally { iter.close(); } Another important caveat is that because IClosableIterator extends Iterator, there is no checked exception declared in Iterator.next(). Because of this, calling Iterator.next() on the iterator returned here may throw a SyncRuntimeException wrapping a SyncException such as might be returned by IStoreClient.get(Object)

Returns:
Throws:
SyncException

put

public IVersion put(K key,
                    Versioned<V> versioned)
             throws SyncException
Description copied from interface: IStoreClient
Put the given Versioned value into the store for the given key if the version is greater to or concurrent with existing values. Throw an ObsoleteVersionException otherwise.

Parameters:
key - The key
versioned - The value and its versioned
Throws:
ObsoleteVersionException
SyncException

addStoreListener

public void addStoreListener(IStoreListener<K> listener)
Description copied from interface: IStoreClient
Add a listener that will be notified about changes to the given store.

Parameters:
listener - the IStoreListener that will receive the notifications

getVersions

protected java.util.List<IVersion> getVersions(K key)
                                        throws SyncException
Description copied from class: AbstractStoreClient
Get the versions for a key

Specified by:
getVersions in class AbstractStoreClient<K,V>
Parameters:
key - the key
Returns:
the versions
Throws:
SyncException

handleGet

protected Versioned<V> handleGet(K key,
                                 Versioned<V> defaultValue,
                                 java.util.List<Versioned<V>> raw)
                          throws InconsistentDataException
Throws:
InconsistentDataException

defaultValue

protected Versioned<V> defaultValue(Versioned<V> defaultValue)

getItemOrThrow

protected Versioned<V> getItemOrThrow(K key,
                                      Versioned<V> defaultValue,
                                      java.util.List<Versioned<V>> items)
                               throws InconsistentDataException
Throws:
InconsistentDataException