edu.harvard.deas.hyperenc.vsat
Class KeyedPageDatabase

java.lang.Object
  extended by java.lang.Thread
      extended by edu.harvard.deas.hyperenc.vsat.KeyedPageDatabase
All Implemented Interfaces:
PageDatabase, Serializable, Runnable

public class KeyedPageDatabase
extends Thread
implements Serializable, PageDatabase

A PageDatabase that implements lookup as described in Section II-B1 of M. Rabin's 2005 paper ("Provably Unbreakable Hyper-Encryption In the Limited Access Model")

When first generated, pages are not associated with a key. When looking up a page, KeyedPageDatabase checks for any pages already associated with the given key. If there is one, and the page is not stale, it returns and then destroys it. Otherwise, it assigns the key to the next available page.

If the database becomes too large (as a result of an abundance of request keys only being used once), the database discards random key-page pairs to free up space.

A KeyedPageDatabase periodically checks if its pages are stale. A page is considered stale if it has been requested once, and some amount of time (the stale page time) has passed before a second request is made. If a page is found to be stale, it is discarded (destroyed). For performance reasons, stale pages might not be detected/destroyed immediately, but it is guaranteed that a stale page will never be returned to a client.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static long DEFAULT_STALE_PAGE_TIME
          The stale page time is the number of milliseconds after which a page that has been requested once is considered stale and discarded.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
KeyedPageDatabase()
           
KeyedPageDatabase(long stalePageTime)
          Creates a new KeyedPageDatabase.
 
Method Summary
 int getMaxPages()
          Returns the maximum number of pages that can be stored in the database.
 int getNumPages()
          Returns the number of pages currently stored in this database that have been requested exactly once.
 byte[] getPage(int key)
          Get a page from the database.
 int getQueueSize()
          Returns the number of pages currently stored in this database that have never been requested.
 long getStalePageTime()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_STALE_PAGE_TIME

public static final long DEFAULT_STALE_PAGE_TIME
The stale page time is the number of milliseconds after which a page that has been requested once is considered stale and discarded. STALE_PAGE_TIME is the stale page time for this PageDatabase; its default value is DEFAULT_STALE_PAGE_TIME.

See Also:
Constant Field Values
Constructor Detail

KeyedPageDatabase

public KeyedPageDatabase(long stalePageTime)
Creates a new KeyedPageDatabase. Generates MAX_NUM_PAGES and inserts them into the database.

Parameters:
stalePageTime - The stale page time for this database.
See Also:
DEFAULT_STALE_PAGE_TIME

KeyedPageDatabase

public KeyedPageDatabase()
Method Detail

getStalePageTime

public long getStalePageTime()
Returns:
The stale page time, in seconds.

getMaxPages

public int getMaxPages()
Returns the maximum number of pages that can be stored in the database. This counts only pages in the map (that is, the maximum number of requested-once pages that this database will keep track of).

Specified by:
getMaxPages in interface PageDatabase
Returns:
maximum number of pages that can be stored in the map

getNumPages

public int getNumPages()
Returns the number of pages currently stored in this database that have been requested exactly once. That is, returns the number of pages in the map.

Specified by:
getNumPages in interface PageDatabase
Returns:
number of pages in the map

getQueueSize

public int getQueueSize()
Returns the number of pages currently stored in this database that have never been requested. That is, returns the number of pages in the queue.


getPage

public byte[] getPage(int key)
Get a page from the database.

Specified by:
getPage in interface PageDatabase
Parameters:
key - The key we are trying to match.
Returns:
The page whose key matched the given key, or if none exists that is not stale, then a new page that has never been served. Returns null if the database is empty.