|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkrati.sos.SerializableObjectStore<K,V>
K
- Key (serializable object)V
- Value (serializable object)public class SerializableObjectStore<K,V>
A key-value store for serializable objects. The store requires that both key and value be serializable objects. This class is not thread-safe by design. It is expected that the conditions below hold within one JVM.
1. There is one and only one instance of SerializableObjectStore for a given data store. 2. There is one and only one thread is calling put and delete methods at any given time.It is expected that this class is used in the case of multiple readers and single writer.
Field Summary | |
---|---|
protected ObjectSerializer<K> |
_keySerializer
|
protected DataStore<byte[],byte[]> |
_store
|
protected ObjectSerializer<V> |
_valSerializer
|
Constructor Summary | |
---|---|
SerializableObjectStore(DataStore<byte[],byte[]> store,
ObjectSerializer<K> keySerializer,
ObjectSerializer<V> valSerializer)
Constructs a key-value store for serializable objects. |
Method Summary | |
---|---|
void |
clear()
Clears this object store by removing all the persisted data permanently. |
boolean |
delete(K key)
Deletes an object from the store based on its key. |
V |
get(K key)
Gets an object based on its key from the store. |
byte[] |
getBytes(byte[] keyBytes)
Gets an object in the form of byte array from the store. |
byte[] |
getBytes(K key)
Gets an object in the form of byte array from the store. |
protected DataStore<byte[],byte[]> |
getContentStore()
|
ObjectSerializer<K> |
getKeySerializer()
|
ObjectSerializer<V> |
getValueSerializer()
|
Iterator<Map.Entry<K,V>> |
iterator()
|
Iterator<K> |
keyIterator()
|
void |
persist()
Persists this object store. |
boolean |
put(K key,
V value)
Puts an serializable object into the store. |
void |
sync()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final DataStore<byte[],byte[]> _store
protected final ObjectSerializer<K> _keySerializer
protected final ObjectSerializer<V> _valSerializer
Constructor Detail |
---|
public SerializableObjectStore(DataStore<byte[],byte[]> store, ObjectSerializer<K> keySerializer, ObjectSerializer<V> valSerializer)
store
- the underlying data store for serializable objects.keySerializer
- the object serializer to serialize/de-serialize keys.valSerializer
- the object serializer to serialize/de-serialize values.Method Detail |
---|
protected DataStore<byte[],byte[]> getContentStore()
public ObjectSerializer<K> getKeySerializer()
public ObjectSerializer<V> getValueSerializer()
public V get(K key)
get
in interface DataStore<K,V>
key
- the retrieving key for a serializable object in the store.
public byte[] getBytes(K key)
getBytes
in interface ObjectStore<K,V>
key
- the retrieving key.
public byte[] getBytes(byte[] keyBytes)
getBytes
in interface ObjectStore<K,V>
key
- the retrieving key in raw bytes.
public boolean put(K key, V value) throws Exception
put
in interface DataStore<K,V>
key
- the object key.value
- the serializable object.
Exception
public boolean delete(K key) throws Exception
delete
in interface DataStore<K,V>
key
- the object key.
Exception
public void sync() throws IOException
sync
in interface DataStore<K,V>
IOException
public void persist() throws IOException
persist
in interface DataStore<K,V>
IOException
public void clear() throws IOException
clear
in interface DataStore<K,V>
IOException
public Iterator<K> keyIterator()
keyIterator
in interface DataStore<K,V>
public Iterator<Map.Entry<K,V>> iterator()
iterator
in interface Iterable<Map.Entry<K,V>>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |