ants
Class NodeCache

java.lang.Object
  |
  +--ants.NodeCache
Direct Known Subclasses:
AutoNodeCache

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.


Field Summary
static int READEXCLUSIVE
           
static int READSHARED
           
static int WRITEEXCLUSIVE
           
static int WRITESHARED
           
 
Constructor Summary
NodeCache(Node owner, int capacity, int duration)
           
 
Method Summary
 void clean()
          clean the cache of expired objects
 java.lang.Object get(byte[] protocol, java.lang.Object key)
          get another protocols's object from the cache
 java.lang.Object get(java.lang.Object key)
          get an object from the cache by its key
 int getAccess(java.lang.Object key)
          get the access flags of an object in the cache by its key
static void main(java.lang.String[] args)
          lots of gratuitous testing
 java.lang.Object put(java.lang.Object key, java.lang.Object value, int time)
          put an object in the cache by key, with duration and default access
 java.lang.Object put(java.lang.Object key, java.lang.Object value, int time, int access)
          put an object in the cache by key, with duration and access
 java.lang.Object remove(java.lang.Object key)
          remove an object from the cache by its key
 void run()
           
 boolean setAccess(java.lang.Object key, int access)
          set the access flags of an object in the cache by its key
 java.lang.String toString()
          mainly for testing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

READSHARED

public static final int READSHARED

READEXCLUSIVE

public static final int READEXCLUSIVE

WRITESHARED

public static final int WRITESHARED

WRITEEXCLUSIVE

public static final int WRITEEXCLUSIVE
Constructor Detail

NodeCache

public NodeCache(Node owner,
                 int capacity,
                 int duration)
Method Detail

getAccess

public int getAccess(java.lang.Object key)
get the access flags of an object in the cache by its key

setAccess

public boolean setAccess(java.lang.Object key,
                         int access)
set the access flags of an object in the cache by its key

get

public java.lang.Object get(java.lang.Object key)
get an object from the cache by its key

get

public java.lang.Object get(byte[] protocol,
                            java.lang.Object key)
get another protocols's object from the cache

put

public final java.lang.Object put(java.lang.Object key,
                                  java.lang.Object value,
                                  int time)
put an object in the cache by key, with duration and default access

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value,
                            int time,
                            int access)
put an object in the cache by key, with duration and access

remove

public java.lang.Object remove(java.lang.Object key)
remove an object from the cache by its key

clean

public void clean()
clean the cache of expired objects

toString

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

run

public void run()
Specified by:
run in interface java.lang.Runnable

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
lots of gratuitous testing