org.xmlecho.palomar.cache
Class SmartCache

java.lang.Object
  extended byorg.xmlecho.palomar.cache.AbstractCache
      extended byorg.xmlecho.palomar.cache.SmartCache
All Implemented Interfaces:
Cache, org.xmlecho.palomar.cron.Job, org.xmlecho.palomar.cron.Refreshable

public class SmartCache
extends AbstractCache

Class holds the objects for a specific type.

SmartCache - Smart enough to identify how to store the object( either memory or disk) (TBD: Can spawn a thread(may be CacheProxy which) wakes up periodically and cleans the cache.


Field Summary
protected  Policy[] cachePolicies
          The policies that can be assigned to a cache.
 
Fields inherited from class org.xmlecho.palomar.cache.AbstractCache
_type, lastRefreshTime, myProperties, refreshFrequency
 
Constructor Summary
SmartCache()
          Default constructor
SmartCache(java.lang.String tag)
          Constructor with a tag identifier.
 
Method Summary
 void clear()
          removes all objects from the cache
 void clearCache()
          Deprecated.  
 java.lang.Object get(java.lang.String keyParam)
          Method for getting an object from cache.
 int getCapacity()
           
 java.lang.String getDefaultCacheStorageType()
           
 Holder getFirst()
          get first element in linked list
protected  Holder getHolder(java.lang.String keyParam)
          Returns Holder object given a key
 Holder getLast()
          get last element in linked list
 java.util.Properties getProperties()
          Return the characteristics of a specific implementation of IrisCache
 java.lang.Runnable getRunnable()
           
 java.util.Map getSpecificCache()
           
 void invalidate(java.lang.String objectKey)
          receive notification of update event
 void printCache()
          Convinience method for testing.
 void put(java.lang.String keyParam, java.lang.Object specificObject)
          Method for updating the cache with an object.
 void put(java.lang.String keyParam, Policy[] policies, java.lang.Object specificObject)
          Method for updating the cache with an object.
 java.lang.Object putMutable(java.lang.String objectKey, java.lang.Object mutableObject)
          Cache an object we're going to write some output to
 java.lang.Object putMutable(java.lang.String irisKey, Policy[] policies, java.lang.Object specificObject)
           
 void refresh()
          SmartCache specific implementation of refreshing its cache.
 void remove(java.lang.String objectKey)
          Remove an object from the cache.
 void setDefaultCacheStorageType(java.lang.String storageType)
           
 void setDefaultPolicies(Policy[] cachePolicies)
          Setting the default policies for the entire objects in this cache.
 void setFirst(Holder first)
          keep track of first element in linked list
 void setLast(Holder last)
          keep track of last element in linked list
 void setProperties(java.lang.String type, java.util.Properties initialProperties)
          Method sets the characteristics of this particular instance.
 java.lang.String toString()
           
 boolean willWantRefresh()
          from Refreshable
 
Methods inherited from class org.xmlecho.palomar.cache.AbstractCache
getCacheDir, getCronExpr, getJobGroupName, getJobName, getKeys, getMaxCacheSize, getNextRefreshTime, getObjects, getRefreshFreq, getRefreshInterval, getType, isEmpty, isTimeToRefresh, runJob, setMaxCacheSize, setRefreshFreq, setRefreshTime, setType, shouldNotify, trimProperties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cachePolicies

protected Policy[] cachePolicies
The policies that can be assigned to a cache.

Constructor Detail

SmartCache

public SmartCache()
Default constructor


SmartCache

public SmartCache(java.lang.String tag)
Constructor with a tag identifier.

Parameters:
tag - the identifier specifying the type of this instance
Method Detail

setProperties

public void setProperties(java.lang.String type,
                          java.util.Properties initialProperties)
Method sets the characteristics of this particular instance. Method should be called after instantiating an object of this class.

Parameters:
type - the specific type
initialProperties - the characteristics of the specific type

getProperties

public java.util.Properties getProperties()
Description copied from interface: Cache
Return the characteristics of a specific implementation of IrisCache

Specified by:
getProperties in interface Cache
Overrides:
getProperties in class AbstractCache

get

public java.lang.Object get(java.lang.String keyParam)
Method for getting an object from cache.

Parameters:
keyParam - the string representation of the key
Returns:
the cached Object, or null if not found

getHolder

protected Holder getHolder(java.lang.String keyParam)
Returns Holder object given a key

Parameters:
keyParam - string representation of key
Returns:
the object's holder

putMutable

public java.lang.Object putMutable(java.lang.String objectKey,
                                   java.lang.Object mutableObject)
                            throws java.lang.Exception
Cache an object we're going to write some output to

Throws:
java.lang.Exception

put

public void put(java.lang.String keyParam,
                java.lang.Object specificObject)
         throws java.lang.Exception
Method for updating the cache with an object. Gets the default policies to be attached with that particular object.

Parameters:
keyParam - the key identifier of an object.
specificObject - the object to be cached.
Throws:
java.lang.Exception

put

public void put(java.lang.String keyParam,
                Policy[] policies,
                java.lang.Object specificObject)
         throws java.lang.Exception
Method for updating the cache with an object. Creates ObjectHolder with the input parameters.

Parameters:
keyParam - the key identifier of an object.
policies - the Policy objects to be attached to an object that has to be cached
specificObject - the object to be cached.
Throws:
java.lang.Exception

putMutable

public java.lang.Object putMutable(java.lang.String irisKey,
                                   Policy[] policies,
                                   java.lang.Object specificObject)
                            throws java.lang.Exception
Throws:
java.lang.Exception

setDefaultCacheStorageType

public void setDefaultCacheStorageType(java.lang.String storageType)

getDefaultCacheStorageType

public java.lang.String getDefaultCacheStorageType()

getCapacity

public int getCapacity()
Returns:
the max number of objects the cache will store

getSpecificCache

public java.util.Map getSpecificCache()

setDefaultPolicies

public void setDefaultPolicies(Policy[] cachePolicies)
Setting the default policies for the entire objects in this cache.


setFirst

public void setFirst(Holder first)
keep track of first element in linked list


setLast

public void setLast(Holder last)
keep track of last element in linked list


getFirst

public Holder getFirst()
get first element in linked list


getLast

public Holder getLast()
get last element in linked list


willWantRefresh

public boolean willWantRefresh()
from Refreshable


refresh

public void refresh()
             throws java.lang.Exception
SmartCache specific implementation of refreshing its cache.

Throws:
java.lang.Exception

getRunnable

public java.lang.Runnable getRunnable()

invalidate

public void invalidate(java.lang.String objectKey)
receive notification of update event


remove

public void remove(java.lang.String objectKey)
            throws java.lang.Exception
Remove an object from the cache. Does nothing if the object isn't found

Parameters:
objectKey - the identifier used when storing the object
Throws:
java.lang.Exception

clear

public void clear()
removes all objects from the cache


clearCache

public void clearCache()
Deprecated.  

Method for clearing a particular type of cache.


printCache

public void printCache()
Convinience method for testing.


toString

public java.lang.String toString()