org.vrspace.neurogrid
Class MapDB

java.lang.Object
  extended byorg.vrspace.neurogrid.DBAdapter
      extended byorg.vrspace.neurogrid.MapDB
All Implemented Interfaces:
LoadListener, java.lang.Runnable

public class MapDB
extends DBAdapter
implements LoadListener, java.lang.Runnable


Field Summary
protected  boolean active
           
protected  SoftCache cache
           
static long getCnt
           
static long hitCnt
           
protected  int mode
           
static long putCnt
           
protected  Queue q
           
static int QUEUED
           
static long reloadCnt
           
 long sleep
          sleep time, millis
protected  Store store
           
static int SYNC
           
 
Fields inherited from class org.vrspace.neurogrid.DBAdapter
instance
 
Constructor Summary
MapDB()
           
 
Method Summary
 int count(java.lang.Class what)
          Returns number of stored instances of this class.
 void delete(NGObject obj)
          Delete obj
 NGObject get(java.lang.Class what, long id)
          Called from DBRef when SoftReference.get() returns null, that is - when gc expired the object
 NGObject get(java.lang.Class what, NGObject value)
          Utility method
protected  java.util.TreeSet getTable(java.lang.Class what)
          Returns table used to store what
 void init(Store store)
          Initializes this DBAdapter
 java.util.Iterator iterator(java.lang.Class what)
          Returns the iterator on all instances of a class
 void loaded(NGObject obj)
          Stores an object to a reference map
 void put(NGObject obj)
          Stores the object
 void run()
          Writer thread run() impl.
 void setMode(int mode)
          Set new write mode: SYNC or QUEUED
 long size()
          Returns total swap size
protected  void startWriter()
          Creates and starts writer thread with maximum priority
protected  void stopWriter()
          Interrupts and stops writer thread if any, flushes queue
protected  void store(NGObject obj)
          Stores obj to current store
 java.util.SortedSet subSet(java.lang.Class what, java.lang.Object start, java.lang.Object end)
          Retrieves a subset of a class
 
Methods inherited from class org.vrspace.neurogrid.DBAdapter
getInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected SoftCache cache

store

protected Store store

active

protected boolean active

QUEUED

public static final int QUEUED
See Also:
Constant Field Values

SYNC

public static final int SYNC
See Also:
Constant Field Values

mode

protected int mode

q

protected Queue q

sleep

public long sleep
sleep time, millis


putCnt

public static long putCnt

getCnt

public static long getCnt

reloadCnt

public static long reloadCnt

hitCnt

public static long hitCnt
Constructor Detail

MapDB

public MapDB()
Method Detail

init

public void init(Store store)
          throws java.lang.Exception
Initializes this DBAdapter

Specified by:
init in class DBAdapter
Throws:
java.lang.Exception
See Also:
Store

startWriter

protected void startWriter()
Creates and starts writer thread with maximum priority


stopWriter

protected void stopWriter()
Interrupts and stops writer thread if any, flushes queue


run

public void run()
Writer thread run() impl. Calls flush() every sleep ms

Specified by:
run in interface java.lang.Runnable

put

public void put(NGObject obj)
         throws java.lang.Exception
Stores the object

Specified by:
put in class DBAdapter
Throws:
java.lang.Exception

delete

public void delete(NGObject obj)
            throws java.lang.Exception
Delete obj

Specified by:
delete in class DBAdapter
Throws:
java.lang.Exception

getTable

protected java.util.TreeSet getTable(java.lang.Class what)
Returns table used to store what


loaded

public void loaded(NGObject obj)
Stores an object to a reference map

Specified by:
loaded in interface LoadListener

store

protected void store(NGObject obj)
Stores obj to current store


count

public int count(java.lang.Class what)
Returns number of stored instances of this class.

Specified by:
count in class DBAdapter

size

public long size()
Returns total swap size

Specified by:
size in class DBAdapter

iterator

public java.util.Iterator iterator(java.lang.Class what)
Returns the iterator on all instances of a class

Specified by:
iterator in class DBAdapter

subSet

public java.util.SortedSet subSet(java.lang.Class what,
                                  java.lang.Object start,
                                  java.lang.Object end)
Retrieves a subset of a class

Specified by:
subSet in class DBAdapter

get

public NGObject get(java.lang.Class what,
                    NGObject value)
Utility method

Specified by:
get in class DBAdapter

get

public NGObject get(java.lang.Class what,
                    long id)
Called from DBRef when SoftReference.get() returns null, that is - when gc expired the object

Specified by:
get in class DBAdapter

setMode

public void setMode(int mode)
Set new write mode: SYNC or QUEUED