All Packages  This Package  Class Hierarchy  Class Search  Index

Class edu.utah.janos.antsr.core.NodeCache
java.lang.Object
   |
   +----edu.utah.janos.antsr.core.NodeCache

  Summary

public class  NodeCache
     extends java.lang.Object
     implements java.lang.Runnable
{
          // Fields 6
     private int elementCount;
     private NodeCache.NCElement[] hash;
     private boolean keepCollecting;
     private final LinkedList lru;
     private long minTime;
     private final Node owner;

          // Constructors 1
     public NodeCache(Node, int);

          // Methods 15
     private synchronized void clean();
     void collect();
     private synchronized NodeCache.NCElement find(Object);
     public final synchronized Object get(int);
     public final synchronized Object get(Object);
     public final synchronized Object get(long);
     private final int hashBucket(int);
     public final synchronized Object put(int, Object, int);
     public final synchronized Object put(Object, Object, int);
     public final synchronized Object put(long, Object, int);
     public synchronized boolean refresh(Object, int);
     public synchronized Object remove(Object);
     public void run();
     void stopCollecting();
     public String toString();

          // Inner Classes 2
     private final class NodeCache.NCElement
     public abstract static class NodeCache.EventHandler
}

Node cache of managed soft-state.

Combines hashtable and doubly linked list to implement fixed size table with LRU replacement. all public entry points are synchronized. a background gc thread cleans entries that have expired.

XXX the background GC thread is probably unnecessary since this is only per-flow state. At the least, the background thread should be configurable by the flow (e.g., its collection parameters).

XXX should this class be final? Should more methods be marked final? (e.g., get)

This differs from the original version in that it does not have a maximum time limit or a maximum number of cached items, both of which are unneeded because of other resource limits.

Author:
David Wetherall


  Cross Reference

Returned By:
Node.getCache()





  Fields

· owner

Summary  |  Top
   private final Node owner

Reference to whichever node owns this cache


· hash

Summary  |  Top
   private NodeCache.NCElement[] hash

Hash table for quick access to the NCElements


· lru

Summary  |  Top
   private final LinkedList lru

Doubly linked list for tracking the least recently used elements in case we want to kill them before their times have expired


· elementCount

Summary  |  Top
   private int elementCount

Tracks the number of elements;


· minTime

Summary  |  Top
   private long minTime

The minimum expiration time of the current set of elments. This value is relative and is used as a timeout for java.lang.Object.wait()


· keepCollecting

Summary  |  Top
   private boolean keepCollecting

Tell the gc to continue collecting


  Constructors

· NodeCache

Summary  |  Top

   public NodeCache(Node owner, 
                    int size) 

Construct a new NodeCache. Fires up the thread associated with this object.

XXX this probably shouldn't be public.

Parameter Description
owner The Node that owns this NodeCache instance
size The size of the hash table
duration Maximum allowable expiration time for an association



  Methods

· hashBucket

Summary  |  Top
   private final int hashBucket(int hcode) 

Get the bucket for a specific hash code

Parameter Description
hcode A hash code, most likely produced by java.lang.Object.hashCode()



· find

Summary  |  Top
   private synchronized NodeCache.NCElement find(Object key) 

Find the NCElement with the given key. The NCElement will also be moved to the front of the LRU, and hash table lists.

Parameter Description
key The key to match on

Returns:
The NCElement matching the given key


· get

Summary  |  Top
   public final synchronized Object get(Object key) 

Return the value paired with a certain key

Parameter Description
key The key to search for

Returns:
The value associated with the key


· put

Summary  |  Top
   public final synchronized Object put(Object key, 
                                        Object value, 
                                        int time) 

Add a key/value pair to the cache with a given expiration time. If the key is already present in the cache then it will be replaced with the parameters and the old value returned.

Parameter Description
key The key for identifying the value
value The value to be tracked
time The expiration time for this association

Returns:
Old value from a prior association, if it existed


· refresh

Summary  |  Top
   public synchronized boolean refresh(Object key, 
                                       int time) 



· remove

Summary  |  Top
   public synchronized Object remove(Object key) 

Remove an association from the cache.

Parameter Description
key Key for the association to remove

Returns:
The value from the association


· get

Summary  |  Top
   public final synchronized Object get(int i) 

Overloaded get method for integer keys.



· put

Summary  |  Top
   public final synchronized Object put(int i, 
                                        Object value, 
                                        int time) 

Overloaded put method for integer keys.



· get

Summary  |  Top
   public final synchronized Object get(long l) 

Overloaded get method for long keys.



· put

Summary  |  Top
   public final synchronized Object put(long l, 
                                        Object value, 
                                        int time) 

Overloaded put method for long keys.



· clean

Summary  |  Top
   private synchronized void clean() 

Scans the list of associations and garbage collects based on expiration dates.



· run

Summary  |  Top
   public void run() 

Run forever, collecting expired objects.

Implements:
run in interface Runnable


· collect

Summary  |  Top
   void collect() 

Start the collection thread

Parameter Description
max The maximum number of elements allowed



· stopCollecting

Summary  |  Top
   void stopCollecting() 


· toString

Summary  |  Top
   public String toString() 
Overrides:
toString in class Object


All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.7