Class FileHashtable

java.lang.Object
com.nt.udc.util.FileHashtable

public class FileHashtable extends Object
This class handles the key -> disk based Object mappings, where the disk-based Object is handled with an ObjectStorageFile class. For the most part, use this class as you would a Hashtable class, except note that your Object will be saved to disk immediately. Therefore, it may be slower than an memory-based Hashtable, but the data will be saved.
  • Field Details

    • offsetTable

      protected HashMap offsetTable
    • objStorage

      protected ObjectStorageFile objStorage
    • objStorageList

      protected HashMap objStorageList
    • deadPartitionList

      protected ArrayList deadPartitionList
    • keyFactory

      protected Factory keyFactory
    • allowCompress

      protected boolean allowCompress
  • Constructor Details

    • FileHashtable

      public FileHashtable(ObjectStorageFile storage, Factory keyFact) throws IOException
      Create a new file-based table.
      Parameters:
      storage - Handles the actual Object storage to disk.
      keyFact - Factory class, used to build Object keys when using a previously created table.
      Throws:
      IOException
    • FileHashtable

      public FileHashtable(ArrayList storageFileList, Factory keyFact) throws IOException
      Throws:
      IOException
  • Method Details

    • addPartition

      public void addPartition(ObjectStorageFile newStorage, int index) throws IOException
      Throws:
      IOException
    • get

      public Object get(Object key) throws IOException
      Retrieve an Object with the given key.
      Parameters:
      key - Object key to retrieve the value with.
      Returns:
      Object value that was stored in the table.
      Throws:
      IOException
    • put

      public Object put(Object key, Object value, int index) throws IOException
      Throws:
      IOException
    • put

      public Object put(Object key, Object value) throws IOException
      Puts an Object value in the table using the Object key.
      Parameters:
      key - Key to index into the table.
      value - Value to put in the table.
      Returns:
      Value that was placed in the table.
      Throws:
      IOException
    • pauseTableCompression

      public void pauseTableCompression()
      Pause the table compression.
    • remove

      public Object remove(Object key) throws IOException
      Removes an Object from the table.
      Parameters:
      key - Object key, used to find the Object in the table.
      Returns:
      Object value at the key.
      Throws:
      IOException
    • removeDelayedNARParsing

      public Object removeDelayedNARParsing(Object key) throws IOException
      This method is for exclusive use by MTAggrDispatcher ONLY, because this method must return NAR instead of an arbitrary Object. A clone of remove(), but this one calls ObjectStorageFile.getDelayedParsing() instead. and manually
      Parameters:
      key -
      Returns:
      THE TYPE IS IMPORTANT!!! It's either type com.nt.common.util.ByteArray (which then needs parsing from ObjectStorageFile.objectFromBytes()), or type whatever it was originally. (There's gotta be a better way, but I can't figure out how to bypass the "useMemHash" thing.
      Throws:
      IOException
    • removeDeadPartitions

      protected void removeDeadPartitions() throws IOException
      Throws:
      IOException
    • resumeTableCompression

      public void resumeTableCompression() throws IOException
      Compresses the ObjectStorageFile's file, and resets the offset table.
      Throws:
      IOException
    • compressTable

      public void compressTable() throws NullPointerException, IOException
      Compresses the ObjectStorageFile's file, and resets the offset table.
      Throws:
      NullPointerException
      IOException
    • close

      public void close() throws IOException
      Closes the file table.
      Throws:
      IOException
    • open

      public void open() throws IOException
      Opens the file table.
      Throws:
      IOException
    • clear

      public void clear() throws UnsupportedOperationException
      This method is not supported.
      Throws:
      UnsupportedOperationException
    • containsKey

      public boolean containsKey(Object key)
      Returns whether this table contains the given key.
      Parameters:
      key - Key to find.
      Returns:
      true, if this table contains the key
    • containsValue

      public boolean containsValue(Object value) throws IOException
      Returns whether this table contains the given value.
      Parameters:
      value - Value to find.
      Returns:
      true, if this table contains the value
      Throws:
      IOException
    • keySet

      public Set keySet() throws UnsupportedOperationException
      Returns the keys of this table as a Set interface. !! Currently UNSUPPORTED !!
      Returns:
      Keys of the table, as a Set interface.
      Throws:
      UnsupportedOperationException
    • size

      public int size()
      Returns the number of Objects in the table.
      Returns:
      Number of Objects in the table.
    • isEmpty

      public boolean isEmpty()
      Returns whether the table is empty.
      Returns:
      true, if the table is empty
    • toString

      public String toString()
      Returns the table, in displayable format.
      Overrides:
      toString in class Object
      Returns:
      Table, in String format.
    • entrySet

      public Set entrySet() throws UnsupportedOperationException
      Returns the entries in Map.Entry form. !! Currently UNSUPPORTED !!
      Returns:
      set of Map.Entry objects
      Throws:
      UnsupportedOperationException
    • equals

      public boolean equals(Object o)
      Returns whether this table is equal to the given Object.
      Overrides:
      equals in class Object
      Parameters:
      o - Object to test for equality
      Returns:
      true, if this table is equal to the given Object
    • hashCode

      public int hashCode() throws UnsupportedOperationException
      Returns the hash code for this table. !! Currently UNSUPPORTED !!
      Overrides:
      hashCode in class Object
      Returns:
      hash code value for this table
      Throws:
      UnsupportedOperationException
    • putAll

      public void putAll(Map t) throws UnsupportedOperationException
      Puts all of the elements of the given Map into this table. !! Currently UNSUPPORTED !!
      Parameters:
      t - holds elements to enter into this table
      Throws:
      UnsupportedOperationException
    • values

      public Collection values() throws UnsupportedOperationException
      Returns all the values in the table as a Collection interface. !! Currently UNSUPPORTED !!
      Returns:
      Values, in a Collection interface.
      Throws:
      UnsupportedOperationException
    • keys

      public Enumeration keys()
      Returns the keys of the table.
      Returns:
      keys, as an Enumeration