org.jboss.jca.adapters.jdbc.util
Class LRUCachePolicy

java.lang.Object
  extended by org.jboss.jca.adapters.jdbc.util.LRUCachePolicy
Direct Known Subclasses:
PreparedStatementCache

public class LRUCachePolicy
extends Object

Implementation of a Least Recently Used cache policy.

Version:
$Revision$
Author:
Stefano Maestri

Nested Class Summary
 class LRUCachePolicy.LRUCacheEntry
          Double linked cell used as entry in the cache list.
 class LRUCachePolicy.LRUList
          Double queued list used to store cache entries.
 
Field Summary
protected  LRUCachePolicy.LRUList lruList
          The linked list used to implement the LRU algorithm
protected  Map map
          The map holding the cached objects
protected  int maxCapacity
          The maximum capacity of this cache
protected  int minCapacity
          The minimum capacity of this cache
 
Constructor Summary
LRUCachePolicy()
          Creates a LRU cache policy object with zero cache capacity.
LRUCachePolicy(int min, int max)
          Creates a LRU cache policy object with the specified minimum and maximum capacity.
 
Method Summary
protected  void ageOut(LRUCachePolicy.LRUCacheEntry entry)
          Callback method called when the cache algorithm ages out of the cache the given entry.
protected  void cacheMiss()
          Callback method called when a cache miss happens.
 void create()
          Initializes the cache, creating all required objects and initializing their values.
protected  LRUCachePolicy.LRUCacheEntry createCacheEntry(Object key, Object value)
          Factory method for cache entries
protected  LRUCachePolicy.LRUList createList()
          Factory method for the linked list used by this cache implementation.
protected  Map createMap()
          Create map holding entries.
 void destroy()
          Destroys the cache that is now unusable.
 void flush()
          flush
 Object get(Object key)
          get method
 void insert(Object key, Object o)
          insert
 Object peek(Object key)
          peek
 void remove(Object key)
          remove
 int size()
          size
 void start()
          Starts this cache that is now ready to be used.
 void stop()
          Stops this cache thus flush()ing all cached objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

protected Map map
The map holding the cached objects


lruList

protected LRUCachePolicy.LRUList lruList
The linked list used to implement the LRU algorithm


maxCapacity

protected int maxCapacity
The maximum capacity of this cache


minCapacity

protected int minCapacity
The minimum capacity of this cache

Constructor Detail

LRUCachePolicy

public LRUCachePolicy()
Creates a LRU cache policy object with zero cache capacity.

See Also:
create()

LRUCachePolicy

public LRUCachePolicy(int min,
                      int max)
Creates a LRU cache policy object with the specified minimum and maximum capacity.

Parameters:
min - min
max - max
See Also:
create()
Method Detail

createMap

protected Map createMap()
Create map holding entries.

Returns:
the map

create

public void create()
Initializes the cache, creating all required objects and initializing their values.

See Also:
start(), destroy()

start

public void start()
Starts this cache that is now ready to be used.

See Also:
create(), stop()

stop

public void stop()
Stops this cache thus flush()ing all cached objects.
After this method is called, a call to start() will restart the cache.

See Also:
start(), destroy()

destroy

public void destroy()
Destroys the cache that is now unusable.
To have it working again it must be re-create()ed and re-start()ed.

See Also:
create()

get

public Object get(Object key)
get method

Parameters:
key - key
Returns:
the value

peek

public Object peek(Object key)
peek

Parameters:
key - the key
Returns:
the value

insert

public void insert(Object key,
                   Object o)
insert

Parameters:
key - the key
o - value

remove

public void remove(Object key)
remove

Parameters:
key - the key

flush

public void flush()
flush


size

public int size()
size

Returns:
the size

createList

protected LRUCachePolicy.LRUList createList()
Factory method for the linked list used by this cache implementation.

Returns:
the lru list

ageOut

protected void ageOut(LRUCachePolicy.LRUCacheEntry entry)
Callback method called when the cache algorithm ages out of the cache the given entry.
The implementation here is removing the given entry from the cache.

Parameters:
entry - entry

cacheMiss

protected void cacheMiss()
Callback method called when a cache miss happens.


createCacheEntry

protected LRUCachePolicy.LRUCacheEntry createCacheEntry(Object key,
                                                        Object value)
Factory method for cache entries

Parameters:
key - key
value - value
Returns:
the entry entry


Copyright © 2008 Red Hat Middleware LLC (http://www.jboss.com/)