krati.sos
Class ObjectCacheAgent<T>

java.lang.Object
  extended by krati.sos.ObjectCacheAgent<T>
Type Parameters:
T - Object to be cached.
All Implemented Interfaces:
Persistable, ObjectCache<T>

public class ObjectCacheAgent<T>
extends Object
implements ObjectCache<T>

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

    get(int objectId)
      + get object from the underlying store
      + Call the outbound handler on the object
      + return the object
  
    set(int objectId, T object, long scn)
      + Call the inbound handler on the value object
      + delegate operation set to the underlying store
 
 

Author:
jwu

Field Summary
protected  ObjectCache<T> _cache
           
protected  ObjectHandler<T> _inboundHandler
           
protected  ObjectHandler<T> _outboundHandler
           
 
Constructor Summary
ObjectCacheAgent(ObjectCache<T> cache, ObjectHandler<T> inboundHandler, ObjectHandler<T> outboundHandler)
           
 
Method Summary
 void clear()
          Clears this object cache by removing all the persisted data permanently.
 boolean delete(int objectId, long scn)
          Deletes an object based on a user-specified object Id.
 T get(int objectId)
          Gets an object based on a user-specified object Id.
 byte[] getBytes(int objectId)
          Gets an object in raw bytes based on a user-specified object Id.
 long getHWMark()
          Gets the high water mark.
 ObjectHandler<T> getInboundHandler()
           
 long getLWMark()
          Gets the low water mark.
 ObjectCache<T> getObjectCache()
           
 int getObjectIdCount()
           
 int getObjectIdStart()
           
 ObjectHandler<T> getOutboundHandler()
           
 void persist()
          Persists this object cache.
 void saveHWMark(long endOfPeriod)
          Save the high water mark.
 boolean set(int objectId, T object, long scn)
          Sets an object at a user-specified object Id.
 void sync()
          Force all updates from memory buffer and redo log files to synchronize with the underlying persistent file in blocking mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_cache

protected ObjectCache<T> _cache

_inboundHandler

protected ObjectHandler<T> _inboundHandler

_outboundHandler

protected ObjectHandler<T> _outboundHandler
Constructor Detail

ObjectCacheAgent

public ObjectCacheAgent(ObjectCache<T> cache,
                        ObjectHandler<T> inboundHandler,
                        ObjectHandler<T> outboundHandler)
Method Detail

getObjectCache

public ObjectCache<T> getObjectCache()

getInboundHandler

public ObjectHandler<T> getInboundHandler()

getOutboundHandler

public ObjectHandler<T> getOutboundHandler()

getObjectIdCount

public int getObjectIdCount()
Specified by:
getObjectIdCount in interface ObjectCache<T>
Returns:
the total number of objects in the cache.

getObjectIdStart

public int getObjectIdStart()
Specified by:
getObjectIdStart in interface ObjectCache<T>
Returns:
the start of ObjectId(s) allowed by the cache.

delete

public boolean delete(int objectId,
                      long scn)
               throws Exception
Description copied from interface: ObjectCache
Deletes an object based on a user-specified object Id.

Specified by:
delete in interface ObjectCache<T>
Parameters:
objectId - the object Id.
scn - the global scn (equivalent to a time stamp).
Throws:
Exception

set

public boolean set(int objectId,
                   T object,
                   long scn)
            throws Exception
Description copied from interface: ObjectCache
Sets an object at a user-specified object Id.

Specified by:
set in interface ObjectCache<T>
Parameters:
objectId - the object Id.
object - the object to put into the cache.
scn - the global scn (equivalent to a time stamp).
Throws:
Exception

get

public T get(int objectId)
Description copied from interface: ObjectCache
Gets an object based on a user-specified object Id.

Specified by:
get in interface ObjectCache<T>
Parameters:
objectId - the Id of an object to be retrieved from the cache.
Returns:
an object associated with the given objectId.

sync

public void sync()
          throws IOException
Description copied from interface: Persistable
Force all updates from memory buffer and redo log files to synchronize with the underlying persistent file in blocking mode.

Specified by:
sync in interface Persistable
Throws:
IOException

persist

public void persist()
             throws IOException
Description copied from interface: ObjectCache
Persists this object cache.

Specified by:
persist in interface Persistable
Specified by:
persist in interface ObjectCache<T>
Throws:
IOException

clear

public void clear()
           throws IOException
Description copied from interface: ObjectCache
Clears this object cache by removing all the persisted data permanently.

Specified by:
clear in interface ObjectCache<T>
Throws:
IOException

getHWMark

public long getHWMark()
Description copied from interface: Persistable
Gets the high water mark.

Specified by:
getHWMark in interface Persistable

getLWMark

public long getLWMark()
Description copied from interface: Persistable
Gets the low water mark.

Specified by:
getLWMark in interface Persistable

saveHWMark

public void saveHWMark(long endOfPeriod)
                throws Exception
Description copied from interface: Persistable
Save the high water mark.

Specified by:
saveHWMark in interface Persistable
Throws:
Exception

getBytes

public byte[] getBytes(int objectId)
Description copied from interface: ObjectCache
Gets an object in raw bytes based on a user-specified object Id.

Specified by:
getBytes in interface ObjectCache<T>
Parameters:
objectId - the Id of an object to be retrieved from the cache.
Returns:
an object in raw bytes according to the given object Id.


Copyright © 2011. All Rights Reserved.