org.javaWebGen.util
Class CacheManager

java.lang.Object
  extended by org.javaWebGen.util.CacheManager

public class CacheManager
extends java.lang.Object

Experimental and not well tested. Be very careful if you turn on cluster mode! Class provides a Simple Object cache. For keeping objects for reuse in memory instead of always creating a new object. Each object type is kept in their own repository generally by class name. EXAMPLE. CacheManager cache = CacheManager.getInstance().add("1", Integer.class, New Integer(1) ); the object will be stored in the reposition for object of class Integer with 1 as it's key

Version:
$Revision: 1.2 $

Field Summary
static long DEFAULT_EXPIRE_TIME
          default time that an object will live in the cache *
static char DELIM
          used to build UDP DataPackets *
 
Method Summary
 void add(java.lang.Object key, java.lang.Class ctype, java.lang.Object o)
          Add an Object to the cache.
 void change(java.lang.Object key, java.lang.Class type, java.lang.Object o)
          return an object from the pool
protected  void cleanUp()
          check to see if any objects need to be removed
 void clear()
          removes all object from the cache
 void delete(java.lang.Object key, java.lang.Class type)
          removes an object from cache
protected  void finalize()
          this method simply notifies the background thread to stop running
 java.lang.Object get(java.lang.Object key, java.lang.Class type)
          get an object from the cache returns null if empty
static CacheManager getCacheManager()
           
static CacheManager getCacheManager(int time)
          returns a new CacheMananager
static CacheManager getInstance()
          Get a configured CacheManager instance configured with a properties file
 int getSize()
          The number of total Object(s) in Cache
 boolean isCached(java.lang.Object key, java.lang.Class type)
          is this object cached?
protected  void remove(java.lang.Object key, java.lang.Class type)
          remove a Object from the cache
protected  void remove(java.lang.Object key, java.lang.String type)
          removes an Object from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXPIRE_TIME

public static final long DEFAULT_EXPIRE_TIME
default time that an object will live in the cache *

See Also:
Constant Field Values

DELIM

public static final char DELIM
used to build UDP DataPackets *

See Also:
Constant Field Values
Method Detail

getInstance

public static CacheManager getInstance()
Get a configured CacheManager instance configured with a properties file

Returns:
the current instance of the Cache Manager

getCacheManager

public static CacheManager getCacheManager()
Returns:
a new CacheMananager

getCacheManager

public static CacheManager getCacheManager(int time)
returns a new CacheMananager

Parameters:
time - expire time
Returns:
a new CacheMananager

remove

protected void remove(java.lang.Object key,
                      java.lang.Class type)
remove a Object from the cache

Parameters:
key -
type - class being removed from the cache

remove

protected void remove(java.lang.Object key,
                      java.lang.String type)
removes an Object from the cache. NOTE used by CacheListener to remove objects.

Parameters:
key - name of the class type being removed from the
type - name of the class type being removed from the cache(IE result of Class.getName() )
See Also:
CacheListener

getSize

public int getSize()
The number of total Object(s) in Cache

Returns:
number of Object Cached

add

public void add(java.lang.Object key,
                java.lang.Class ctype,
                java.lang.Object o)
Add an Object to the cache. objects are stored internally in a repository(HashMap) by Class type this allows the cache to cache multiple types of objects(classes)

Parameters:
key - name
ctype - object type(class) being added
o - object being added

get

public java.lang.Object get(java.lang.Object key,
                            java.lang.Class type)
get an object from the cache returns null if empty

Parameters:
key - name
type - class type
Returns:
an object from the cache null if empty

isCached

public boolean isCached(java.lang.Object key,
                        java.lang.Class type)
is this object cached?

Parameters:
key -
type - class of object

change

public void change(java.lang.Object key,
                   java.lang.Class type,
                   java.lang.Object o)
return an object from the pool

Parameters:
key - to store object under
type - class of object being stored
o - object from pool

delete

public void delete(java.lang.Object key,
                   java.lang.Class type)
removes an object from cache

Parameters:
key - of object
type - of object

clear

public void clear()
removes all object from the cache


cleanUp

protected void cleanUp()
check to see if any objects need to be removed


finalize

protected void finalize()
                 throws java.lang.Throwable
this method simply notifies the background thread to stop running

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable


Copyright(C) 2003-2006 Kevin Scott - All Rights Reserved.