org.ov4j.cache
Class CacheHandler

java.lang.Object
  extended by org.ov4j.cache.CacheHandler

public class CacheHandler
extends java.lang.Object

This class will handle caching results of calls.

Author:
smolloy

Field Summary
protected static java.lang.String CACHE_AUTHOR
          Author used when caching.
protected static int CACHE_VERSION_ROLLOVER
          Number of versions to keep in history.
protected static java.lang.String ERROR_COMMENT
          Comment for error.
protected static java.lang.String NORMAL_COMMENT
          Comment on normal cache.
protected static java.lang.String TIMEOUT_COMMENT
          Comment for timeouts
 
Constructor Summary
CacheHandler(IContainer<ClassComparable,CachedResultId> cont)
          Constructor.
 
Method Summary
 boolean addListener(ICacheHandlerListener listener)
          Register listener for notifications.
protected  void addNCommit(CachedResultId id, Version<ClassComparable> result)
          Add result to cache.
 Version<ClassComparable> cachedCall(java.lang.reflect.Method theMethod, java.lang.Object instance, java.lang.Object... args)
          Perform a cached call, will wait for a period of time before returning the result from the cache if it exists.
 void clear()
          Clear the cache.
 void close()
          Close the cache.
protected  void commit(CachedResultId id, Version<ClassComparable> result)
          Commit the result in cache.
 long getDelayedCacheTimeout()
           
 long getTimeout()
           
 int getVersionRollover()
           
protected  Version<ClassComparable> latest(CachedResultId id)
          Fetch latest result for the given ID.
 boolean removeListener(ICacheHandlerListener listener)
          Unregister listener for notifications.
 void setDelayedCacheTimeout(long delayedCacheTimeout)
           
 void setTimeout(long timeout)
           
 void setVersionRollover(int versionRollover)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_AUTHOR

protected static final java.lang.String CACHE_AUTHOR
Author used when caching.


NORMAL_COMMENT

protected static final java.lang.String NORMAL_COMMENT
Comment on normal cache.


TIMEOUT_COMMENT

protected static final java.lang.String TIMEOUT_COMMENT
Comment for timeouts


ERROR_COMMENT

protected static final java.lang.String ERROR_COMMENT
Comment for error.


CACHE_VERSION_ROLLOVER

protected static final int CACHE_VERSION_ROLLOVER
Number of versions to keep in history.

Constructor Detail

CacheHandler

public CacheHandler(IContainer<ClassComparable,CachedResultId> cont)
Constructor.

Parameters:
cont - Container to used for storing data.
Method Detail

addListener

public boolean addListener(ICacheHandlerListener listener)
Register listener for notifications.

Parameters:
listener - Listener to be added.
Returns:
Whether or not the listener was added.

addNCommit

protected void addNCommit(CachedResultId id,
                          Version<ClassComparable> result)
                   throws java.io.IOException
Add result to cache.

Parameters:
id - ID to use for storing result.
result - Result to be stored.
Throws:
java.io.IOException

cachedCall

public Version<ClassComparable> cachedCall(java.lang.reflect.Method theMethod,
                                           java.lang.Object instance,
                                           java.lang.Object... args)
Perform a cached call, will wait for a period of time before returning the result from the cache if it exists. After that period, a background thread will wait another period of time to see if the call makes it and if the cache can be updated.

Parameters:
theMethod - Method to be called.
instance - Object on which the method should be called.
args - Arguments to pass to the method call.
Returns:
The result of the call.

clear

public void clear()
Clear the cache.


close

public void close()
Close the cache.


commit

protected void commit(CachedResultId id,
                      Version<ClassComparable> result)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException,
                      java.lang.ClassNotFoundException,
                      java.io.IOException
Commit the result in cache.

Parameters:
id - ID to used for storing result.
result - Result to be stored.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.io.IOException

getDelayedCacheTimeout

public long getDelayedCacheTimeout()
Returns:
Returns the delayedCacheTimeout.

getTimeout

public long getTimeout()
Returns:
Returns the timeout.

getVersionRollover

public int getVersionRollover()
Returns:
The version rollover.

latest

protected Version<ClassComparable> latest(CachedResultId id)
Fetch latest result for the given ID.

Parameters:
id - ID to be fetched.
Returns:
The latest result for the given ID.

removeListener

public boolean removeListener(ICacheHandlerListener listener)
Unregister listener for notifications.

Parameters:
listener - Listener to be removed.
Returns:
Whether or not the listener was found and removed.

setDelayedCacheTimeout

public void setDelayedCacheTimeout(long delayedCacheTimeout)
Parameters:
delayedCacheTimeout - The delayedCacheTimeout to set.

setTimeout

public void setTimeout(long timeout)
Parameters:
timeout - The timeout to set.

setVersionRollover

public void setVersionRollover(int versionRollover)
Parameters:
versionRollover - The version rollover to set.


Copyright © 2004-2007 Steve Molloy. All Rights Reserved.