biz.hammurapi.cache
Class MemoryCache

java.lang.Object
  extended by biz.hammurapi.cache.AbstractProducer
      extended by biz.hammurapi.cache.MemoryCache
All Implemented Interfaces:
Cache, Producer, Component
Direct Known Subclasses:
AppendableMemoryCache

public class MemoryCache
extends AbstractProducer
implements Cache, Component

Memory sensitive cache. Uses soft references to cache objects.

Version:
$Revision: 1.7 $
Author:
Pavel Vlasov

Field Summary
protected  java.util.Map cache
           
static long CLEANUP_INTERVAL
          Default cache cleanup interval.
protected  Producer producer
           
protected  java.util.Map reverseCache
           
 
Constructor Summary
MemoryCache(Producer producer, Cache fallBack, MeasurementCategory measurementCategory)
          Constructs cache with default cleanup interval (1 minute).
MemoryCache(Producer producer, Cache fallBack, MeasurementCategory measurementCategory, java.util.Timer timer, long cleanupInterval)
          Constructs cache with default cleanup interval (1 minute).
 
Method Summary
 void clear()
          Removes all cache entries
protected  void finalize()
           
 Entry get(java.lang.Object key)
           
 boolean isActive()
           
 java.util.Set keySet()
           
 void put(java.lang.Object key, java.lang.Object value, long time, long expirationTime)
          Puts entry to cache
 void remove(Acceptor acceptor)
          Removes keys accepted by acceptor
 void remove(java.lang.Object key)
          Removes entry with specified key
 void setOwner(java.lang.Object owner)
          Plugs the component into container and naming bus.
 void start()
          Creates timer if neccessary, creates cleanup task and schedules it.
 void stop()
          Invoked by container when component is not needed anymore.
 
Methods inherited from class biz.hammurapi.cache.AbstractProducer
addCache, onRemove
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface biz.hammurapi.cache.Producer
addCache
 

Field Detail

cache

protected java.util.Map cache

reverseCache

protected java.util.Map reverseCache

producer

protected Producer producer

CLEANUP_INTERVAL

public static final long CLEANUP_INTERVAL
Default cache cleanup interval.

See Also:
Constant Field Values
Constructor Detail

MemoryCache

public MemoryCache(Producer producer,
                   Cache fallBack,
                   MeasurementCategory measurementCategory)
Constructs cache with default cleanup interval (1 minute).

Parameters:
producer - Producer
fallBack - Fallback cache
measurementCategory - Measurement category to report cache statistics

MemoryCache

public MemoryCache(Producer producer,
                   Cache fallBack,
                   MeasurementCategory measurementCategory,
                   java.util.Timer timer,
                   long cleanupInterval)
Constructs cache with default cleanup interval (1 minute).

Parameters:
producer - Producer
fallBack - Fallback cache
measurementCategory - Measurement category to report cache statistics
cleanupInterval - Interval between removals of expired entries.
timer - Timer which will invoke cleanup tasks, if it is null then a new timer is created internally. Use this parameter to share timers between multiple caches in order to reduce number of threads in the application.
Method Detail

put

public void put(java.lang.Object key,
                java.lang.Object value,
                long time,
                long expirationTime)
Description copied from interface: Cache
Puts entry to cache

Specified by:
put in interface Cache
Parameters:
key - Key
value - Value
time - Timestamp (last modified)
expirationTime - Expiration time

get

public Entry get(java.lang.Object key)
Specified by:
get in interface Producer

clear

public void clear()
Description copied from interface: Cache
Removes all cache entries

Specified by:
clear in interface Cache

remove

public void remove(java.lang.Object key)
Description copied from interface: Cache
Removes entry with specified key

Specified by:
remove in interface Cache

remove

public void remove(Acceptor acceptor)
Description copied from interface: Cache
Removes keys accepted by acceptor

Specified by:
remove in interface Cache

stop

public void stop()
Description copied from interface: Component
Invoked by container when component is not needed anymore. Component shall perform cleanup in this method.

Specified by:
stop in interface Component

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

keySet

public java.util.Set keySet()
Specified by:
keySet in interface Producer
Returns:
all keys, null or empty collection if entire key set is not known

isActive

public boolean isActive()
Specified by:
isActive in interface Cache
Returns:
true if not shut down

start

public void start()
           throws ConfigurationException
Creates timer if neccessary, creates cleanup task and schedules it.

Specified by:
start in interface Component
Throws:
ConfigurationException

setOwner

public void setOwner(java.lang.Object owner)
Description copied from interface: Component
Plugs the component into container and naming bus.

Specified by:
setOwner in interface Component


Copyright © 2003 Hammurapi Group. All Rights Reserved.