iglu.util
Class FileObjectPager

java.lang.Object
  |
  +--iglu.util.FileObjectPager
All Implemented Interfaces:
ObjectPager

public class FileObjectPager
extends java.lang.Object
implements ObjectPager

A file back cache which uses a least-recently-used algorithm for swapping objects out to disk. All objects put in the cache must be serializable. The cache file is erased when the JVM terminates (assuming it terminates normally).


Field Summary
(package private)  java.util.LinkedList accesses
           
(package private)  java.util.HashMap diskLocations
           
(package private)  java.util.LinkedList freeSpace
           
(package private)  java.util.LinkedList loaded
           
(package private)  int nextId
           
(package private)  int numInRam
           
(package private)  int numReads
           
(package private)  int numWrites
           
(package private)  java.io.RandomAccessFile raf
           
 
Constructor Summary
FileObjectPager(java.io.RandomAccessFile raf, int numInRam)
           
FileObjectPager(java.lang.String fileName, int numInRam)
          Create a new FileObjectPager.
 
Method Summary
 void compress()
           
 void delete(java.lang.Object id)
          remove object associated with id from the repository
 java.util.Iterator iterator()
          iterate over the ids in the pager
private  java.lang.Object loadFromDisk(java.lang.Object id)
           
static void main(java.lang.String[] argv)
           
 java.lang.Object retrieve(java.lang.Object id)
          Retrieve and object based on it's id
 void setReclaimSpace(boolean reclaim)
           
 java.lang.String status()
           
 java.lang.Object store(java.lang.Object o)
          Store an object, and get back an id for the object
 void update(java.lang.Object o, java.lang.Object id)
          Associate object o with id
private  void writeLastObject()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

raf

java.io.RandomAccessFile raf

loaded

java.util.LinkedList loaded

accesses

java.util.LinkedList accesses

diskLocations

java.util.HashMap diskLocations

freeSpace

java.util.LinkedList freeSpace

numInRam

int numInRam

nextId

int nextId

numWrites

int numWrites

numReads

int numReads
Constructor Detail

FileObjectPager

public FileObjectPager(java.lang.String fileName,
                       int numInRam)
Create a new FileObjectPager.

Parameters:
fileName - The name of the file to use for the cache.
numInRam - The max number of items to keep in main memory at once.

FileObjectPager

public FileObjectPager(java.io.RandomAccessFile raf,
                       int numInRam)
Method Detail

setReclaimSpace

public void setReclaimSpace(boolean reclaim)

compress

public void compress()

store

public java.lang.Object store(java.lang.Object o)
Description copied from interface: ObjectPager
Store an object, and get back an id for the object

Specified by:
store in interface ObjectPager

update

public void update(java.lang.Object o,
                   java.lang.Object id)
Description copied from interface: ObjectPager
Associate object o with id

Specified by:
update in interface ObjectPager

retrieve

public java.lang.Object retrieve(java.lang.Object id)
Description copied from interface: ObjectPager
Retrieve and object based on it's id

Specified by:
retrieve in interface ObjectPager

delete

public void delete(java.lang.Object id)
Description copied from interface: ObjectPager
remove object associated with id from the repository

Specified by:
delete in interface ObjectPager

writeLastObject

private void writeLastObject()

loadFromDisk

private java.lang.Object loadFromDisk(java.lang.Object id)

status

public java.lang.String status()

iterator

public java.util.Iterator iterator()
Description copied from interface: ObjectPager
iterate over the ids in the pager

Specified by:
iterator in interface ObjectPager

main

public static void main(java.lang.String[] argv)