krati.sos
Class ObjectStoreAgent<K,V>

java.lang.Object
  extended by krati.sos.ObjectStoreAgent<K,V>
Type Parameters:
K - Key
V - Value
All Implemented Interfaces:
Iterable<Map.Entry<K,V>>, ObjectStore<K,V>, DataStore<K,V>

public class ObjectStoreAgent<K,V>
extends Object
implements ObjectStore<K,V>

ObjectStoreAgent: An agent that wraps an ObjectStore can have inbound and outbound ObjectHandler(s). The inbound handler is associated with the put method. It is called on an inbound object before the object is passed down to the underlying ObjectStore. The outbound handler is associated with the get method. It is called on an outbound object before the object is returned back to the ObjectStore visitor. Either inbound or outbound handlers does not affect the delete method.

    get(K key)
      + get object from the underlying store
      + Call the outbound handler on the object
      + return the object
  
    put(K key, V value)
      + Call the inbound handler on the value object
      + delegate operation put to the underlying store
 
 

Author:
jwu

Field Summary
protected  ObjectHandler<V> _inboundHandler
           
protected  ObjectHandler<V> _outboundHandler
           
protected  ObjectStore<K,V> _store
           
 
Constructor Summary
ObjectStoreAgent(ObjectStore<K,V> store, ObjectHandler<V> inboundHandler, ObjectHandler<V> outboundHandler)
           
 
Method Summary
 void clear()
          Clears this object store by removing all the persisted data permanently.
 boolean delete(K key)
           
 V get(K key)
           
 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.
 ObjectHandler<V> getInboundHandler()
           
 ObjectStore<K,V> getObjectStore()
           
 ObjectHandler<V> getOutboundHandler()
           
 Iterator<Map.Entry<K,V>> iterator()
           
 Iterator<K> keyIterator()
           
 void persist()
          Persists this object store.
 boolean put(K key, V value)
           
 void sync()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_store

protected ObjectStore<K,V> _store

_inboundHandler

protected ObjectHandler<V> _inboundHandler

_outboundHandler

protected ObjectHandler<V> _outboundHandler
Constructor Detail

ObjectStoreAgent

public ObjectStoreAgent(ObjectStore<K,V> store,
                        ObjectHandler<V> inboundHandler,
                        ObjectHandler<V> outboundHandler)
Method Detail

getObjectStore

public ObjectStore<K,V> getObjectStore()

getInboundHandler

public ObjectHandler<V> getInboundHandler()

getOutboundHandler

public ObjectHandler<V> getOutboundHandler()

delete

public boolean delete(K key)
               throws Exception
Specified by:
delete in interface DataStore<K,V>
Throws:
Exception

get

public V get(K key)
Specified by:
get in interface DataStore<K,V>

put

public boolean put(K key,
                   V value)
            throws Exception
Specified by:
put in interface DataStore<K,V>
Throws:
Exception

sync

public void sync()
          throws IOException
Specified by:
sync in interface DataStore<K,V>
Throws:
IOException

persist

public void persist()
             throws IOException
Persists this object store.

Specified by:
persist in interface DataStore<K,V>
Throws:
IOException

clear

public void clear()
           throws IOException
Clears this object store by removing all the persisted data permanently.

Specified by:
clear in interface DataStore<K,V>
Throws:
IOException

getBytes

public byte[] getBytes(K key)
Description copied from interface: ObjectStore
Gets an object in the form of byte array from the store.

Specified by:
getBytes in interface ObjectStore<K,V>
Parameters:
key - the retrieving key.
Returns:
the retrieved object in raw bytes.

getBytes

public byte[] getBytes(byte[] keyBytes)
Description copied from interface: ObjectStore
Gets an object in the form of byte array from the store.

Specified by:
getBytes in interface ObjectStore<K,V>
Returns:
the retrieved object in raw bytes.

keyIterator

public Iterator<K> keyIterator()
Specified by:
keyIterator in interface DataStore<K,V>

iterator

public Iterator<Map.Entry<K,V>> iterator()
Specified by:
iterator in interface Iterable<Map.Entry<K,V>>


Copyright © 2011. All Rights Reserved.