Class MemoryStorage

All Implemented Interfaces:
Comparable<Storage>
Direct Known Subclasses:
RootStorage

public class MemoryStorage extends Storage
A persistent data storage and retrieval handler based on an in-memory hash table. Naturally, this is not really persistent in case of server shutdown, so should normally be used only for run-time objects that need to be available. An advantage of the memory storage compared to other implementations is that no object serialization is performed, so any type of objects may be stored and retrieved.
Version:
1.0
  • Constructor Details

    • MemoryStorage

      public MemoryStorage(String id, boolean readWrite, boolean storageInfo)
      Creates a new memory storage.
      Parameters:
      id - the storage identifier
      readWrite - the read write flag
      storageInfo - the show storage info flag
  • Method Details

    • isStorable

      public boolean isStorable(Object obj)
      Checks if the specified object is supported in this storage.
      Parameters:
      obj - the object instance to check
      Returns:
      true if the object is supported, or false otherwise
    • destroy

      public void destroy()
      Destroys this storage. Note that the objects in the storage will NOT be destroyed by this method.
      Overrides:
      destroy in class StorableObject
    • lookup

      public Metadata lookup(Path path)
      Searches for an object at the specified location and returns metadata about the object if found. The path may locate either an index or a specific object.
      Specified by:
      lookup in class Storage
      Parameters:
      path - the storage location
      Returns:
      the metadata for the object, or null if not found
    • load

      public Object load(Path path)
      Loads an object from the specified location. The path may locate either an index or a specific object. In case of an index, the data returned is an index dictionary listing of all objects in it.
      Specified by:
      load in class Storage
      Parameters:
      path - the storage location
      Returns:
      the data read, or null if not found
    • store

      public void store(Path path, Object data) throws StorageException
      Stores an object at the specified location. The path must locate a particular object or file, since direct manipulation of indices is not supported. Any previous data at the specified path will be overwritten or removed.
      Specified by:
      store in class Storage
      Parameters:
      path - the storage location
      data - the data to store
      Throws:
      StorageException - if the data couldn't be written
    • remove

      public void remove(Path path) throws StorageException
      Removes an object or an index at the specified location. If the path refers to an index, all contained objects and indices will be removed recursively.
      Specified by:
      remove in class Storage
      Parameters:
      path - the storage location
      Throws:
      StorageException - if the data couldn't be removed
    • serialize

      public Dict serialize()
      Returns a serialized representation of this object. Used when persisting to permanent storage or when accessing the object from outside pure Java. Returns a shallow copy of the contained dictionary.
      Overrides:
      serialize in class StorableObject
      Returns:
      the serialized representation of this object