org.fjank.jcache
Class CacheImpl

java.lang.Object
  extended by org.fjank.jcache.CacheImpl
All Implemented Interfaces:
Cache

public final class CacheImpl
extends Object
implements Cache

Contains several usefull methods for configuring, administering and monitoring the Cache. Is final to avoid subclassing to further lock down the singleton pattern.

Author:
Frank Karlstrøm

Method Summary
 void close()
          will mark the cache as "not ready" and shutdown the cache.
 void destroyRegion(Object name)
          Will invalidate all objects in the named region and the named region.
 void flush()
          will mark all objects in the cache, both disk and memory, as invalid, forcing objects to be reloaded.
 void flushDisk()
          wll mark all objects in the cache as invalid, forcing objects to be reloaded.
 void flushMemory()
          will mark all objects in the cache as invalid, forcing objects to be reloaded.
 CacheAttributes getAttributes()
          returns the current attributes of the cache including the cache version number, wether the cache is local or distributed, the maximum number of objects in the cache, the disk cache location, and the disk cache size.
static CacheImpl getCache(boolean init)
          Gets an instance of the Cache class.
 DistributionEngine getDistributionEngine()
           
 org.fjank.jcache.JCacheExecutorPool getExecPool()
           
 ReferenceQueue getReferenceQueue()
          gets the ReferenceQueue.
 CacheRegion getRegion()
          Gets the default region in this cache.,
 CacheRegion getRegion(Object name)
          Gets the named region in this cache.,
 float getVersion()
          returns the current version of the cache.
 void init(CacheAttributes attributes)
          initializes the cache, allocates space for metadata and starts the service threads.
 boolean isDistributed()
          returns true if the cache is currently in distributed mode, that it is distributing updates and invalidates within the site, false if all cache actions are local only.
 boolean isReady()
          returns true if the cache has been initialized and not closed, false otherwise.
 Enumeration listCacheObjects()
          will return an Enumeration of CacheObjectInfo objects describing the objects in all regions in the cache.
 Enumeration listCacheObjects(String region)
          will return an Enumeration of CacheObjectInfo objects describing the objects in the specified in the cache.
 void open()
          will create a CacheAttributes object based on the values in a Java properties file, then call the method init.
 void open(String configFile)
          will create a CacheAttributes object based on the values in a Java properties file, then call the method init.
 void setLogSeverity(int severity)
          sets the log severity of the cache system.
 String toString()
          returns a String representation of this Cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getCache

public static CacheImpl getCache(boolean init)
Gets an instance of the Cache class. Is synchronized to avoid several Threads to create multiple instances of this class wich MUST be a singleton.

Parameters:
init - a boolean inication wether to actually performe the initialization or not
Returns:
A Cache instance global for this JVM.
Throws:
CacheNotAvailableException - if the Cache is not available.

getRegion

public CacheRegion getRegion()
Gets the default region in this cache.,

Returns:
the default region in this cache.

getRegion

public CacheRegion getRegion(Object name)
Gets the named region in this cache.,

Parameters:
name - the name of the region to get.
Returns:
the named region.

destroyRegion

public void destroyRegion(Object name)
Will invalidate all objects in the named region and the named region.

Parameters:
name - the name of the region to destroy.
See Also:
#destroy()

init

public void init(CacheAttributes attributes)
          throws CacheNotAvailableException
initializes the cache, allocates space for metadata and starts the service threads. The cache is a process wide service, so it can only be initialized once per process. Subsequent init calls are ignored.

Specified by:
init in interface Cache
Parameters:
attributes2 - contains configuration information to initialize the cache system.
Throws:
CacheNotAvailableException - if the cache is not available.

open

public void open()
          throws CacheNotAvailableException
will create a CacheAttributes object based on the values in a Java properties file, then call the method init. The properties file opened is called jcache.properties If this method is called, the init() method is not neccessary to call.

Specified by:
open in interface Cache
Throws:
CacheNotAvailableException - if the cache is not available.

open

public void open(String configFile)
will create a CacheAttributes object based on the values in a Java properties file, then call the method init. If this method is called, the init() method is not neccessary to call.

Specified by:
open in interface Cache
Parameters:
configFile - the name of the configuration file.
Throws:
CacheNotAvailableException - if the cache is not available.

close

public void close()
will mark the cache as "not ready" and shutdown the cache. Marking the cache as "not ready" will prevent any threads from accessing the Cache during shutdown. If the cache is distributed, close will unregister with the distributed caching system. The method should be called as a part of process termination.

Specified by:
close in interface Cache

flush

public void flush()
           throws CacheException
will mark all objects in the cache, both disk and memory, as invalid, forcing objects to be reloaded. All processes sharing the disk cache are notified when the cache is flushed.

Specified by:
flush in interface Cache
Throws:
CacheException - if an error occurs.

flushMemory

public void flushMemory()
                 throws CacheException
will mark all objects in the cache as invalid, forcing objects to be reloaded. Flushing the memory cache will also invalidate memory objects spooled to disk. Objects that are only cached on disk will not be affected.

Specified by:
flushMemory in interface Cache
Throws:
CacheException - if an error occurs.

flushDisk

public void flushDisk()
               throws CacheException
wll mark all objects in the cache as invalid, forcing objects to be reloaded. Flushing the disk cache will also invalidate memory objects spooled to disk. All processes sharing the disk cache are notified when the cache is flushed.

Specified by:
flushDisk in interface Cache
Throws:
CacheException - if an error occurs.

getVersion

public float getVersion()
returns the current version of the cache.

Specified by:
getVersion in interface Cache
Returns:
the current version of the cache.

isReady

public boolean isReady()
returns true if the cache has been initialized and not closed, false otherwise.

Specified by:
isReady in interface Cache
Returns:
true if the cache has been initialized and not closed, false otherwise.

isDistributed

public boolean isDistributed()
returns true if the cache is currently in distributed mode, that it is distributing updates and invalidates within the site, false if all cache actions are local only.

Specified by:
isDistributed in interface Cache
Returns:
true if the cache is currently in distributed mode, that it is distributing updates and invalidates within the site, false if all cache actions are local only.

listCacheObjects

public Enumeration listCacheObjects()
will return an Enumeration of CacheObjectInfo objects describing the objects in all regions in the cache. CacheObjectInfo will include information such as the object name, the type, what group it is associated with, the reference count, the expiration time if any and object attributes.

Specified by:
listCacheObjects in interface Cache
Returns:
an Enumeration of CacheObjectInfo objects.

listCacheObjects

public Enumeration listCacheObjects(String region)
                             throws RegionNotFoundException
will return an Enumeration of CacheObjectInfo objects describing the objects in the specified in the cache. CacheObjectInfo will include information such as the object name, the type, what group it is associated with, the reference count, the expiration time if any and object attributes.

Specified by:
listCacheObjects in interface Cache
Parameters:
region - the region to get the Enumeration for.
Returns:
an Enumeration of CacheObjectInfo objects.
Throws:
RegionNotFoundException - if the named region os not present in the cache.

getAttributes

public CacheAttributes getAttributes()
returns the current attributes of the cache including the cache version number, wether the cache is local or distributed, the maximum number of objects in the cache, the disk cache location, and the disk cache size.

Specified by:
getAttributes in interface Cache
Returns:
the current attributes of this cache.
Throws:
CacheNotAvailableException - if the cache is not ready.

setLogSeverity

public void setLogSeverity(int severity)
sets the log severity of the cache system. This determines wich messages the cache formats and logs into the log destination. Severity's are defined in the CacheLogger class.

Specified by:
setLogSeverity in interface Cache
Parameters:
severity - the severity level to set

toString

public String toString()
returns a String representation of this Cache.

Overrides:
toString in class Object
Returns:
a String representation of this Cache.

getReferenceQueue

public ReferenceQueue getReferenceQueue()
gets the ReferenceQueue.

Returns:
the ReferenceQueue.

getExecPool

public org.fjank.jcache.JCacheExecutorPool getExecPool()
Returns:

getDistributionEngine

public DistributionEngine getDistributionEngine()


Copyright © 2002-2009 Hosted by SourceForge. All Rights Reserved.