ANTS v2.0 API

ants.core
Class NodeCache

java.lang.Object
  |
  +--ants.core.NodeCache

public class NodeCache
extends java.lang.Object
implements java.lang.Runnable

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 per-flow resource limits.

Author:
David Wetherall, Utah Janos Team

Inner Class Summary
static class NodeCache.EventHandler
          Elements of this type in the node cache will receive calls when one of a set of events occurs.
 
Constructor Summary
NodeCache(Node owner, int size)
          Construct a new NodeCache.
 
Method Summary
 java.lang.Object get(int i)
          Overloaded get method for integer keys.
 java.lang.Object get(long l)
          Overloaded get method for long keys.
 java.lang.Object get(java.lang.Object key)
          Return the value paired with a certain key
 java.lang.Object put(int i, java.lang.Object value, int time)
          Overloaded put method for integer keys.
 java.lang.Object put(long l, java.lang.Object value, int time)
          Overloaded put method for long keys.
 java.lang.Object put(java.lang.Object key, java.lang.Object value, int time)
          Add a key/value pair to the cache with a given expiration time.
 boolean refresh(java.lang.Object key, int time)
           
 java.lang.Object remove(java.lang.Object key)
          Remove an association from the cache.
 void run()
          Run forever, collecting expired objects.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeCache

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.

Parameters:
owner - The Node that owns this NodeCache instance
size - The size of the hash table
duration - Maximum allowable expiration time for an association
Method Detail

get

public final java.lang.Object get(java.lang.Object key)
Return the value paired with a certain key
Parameters:
key - The key to search for
Returns:
The value associated with the key

put

public final java.lang.Object put(java.lang.Object key,
                                  java.lang.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.
Parameters:
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

public boolean refresh(java.lang.Object key,
                       int time)

remove

public java.lang.Object remove(java.lang.Object key)
Remove an association from the cache.
Parameters:
key - Key for the association to remove
Returns:
The value from the association

get

public final java.lang.Object get(int i)
Overloaded get method for integer keys.

put

public final java.lang.Object put(int i,
                                  java.lang.Object value,
                                  int time)
Overloaded put method for integer keys.

get

public final java.lang.Object get(long l)
Overloaded get method for long keys.

put

public final java.lang.Object put(long l,
                                  java.lang.Object value,
                                  int time)
Overloaded put method for long keys.

run

public void run()
Run forever, collecting expired objects.
Specified by:
run in interface java.lang.Runnable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

ANTS v2.0 API

This documentation is Copyright (C) 1998-2001 The University of Utah and the University of Washington. All Rights Reserved. See the individual source files for distribution terms.
Documentation, software, and mailing lists for ANTS v2.0 can be found at the Janos Project: http://www.cs.utah.edu/flux/janos/