Class RootStorage

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

public class RootStorage extends MemoryStorage
The root storage that provides a unified view of other storages. This class provides a number of unique storage services:
  • Mounting -- Sub-storages can be mounted on a "storage/..." subpath, providing a global namespace for objects. Storage paths are automatically converted to local paths for all storage operations.
  • Unification -- Mounted storages can also be overlaid or unified with the root path, providing a storage view where objects from all storages are mixed. The mount order defines which object names take priority, in case several objects have the same paths.
  • Object Initialization -- Dictionary objects will be inspected upon retrieval from a mounted and unified path (i.e. not when retrieved directly from the storage). If a matching type handler or class can be located, the corresponding object will be created, initialized and cached for future references.
Version:
1.0
  • Field Details

    • PATH_FILES

      public static final Path PATH_FILES
      The storage path for public web files.
    • PATH_LIB

      public static final Path PATH_LIB
      The storage path to the JAR library files.
    • PATH_STORAGE

      public static final Path PATH_STORAGE
      The storage path for mounted storages.
  • Constructor Details

    • RootStorage

      public RootStorage(boolean readWrite)
      Creates a new root storage.
      Parameters:
      readWrite - the read write flag
  • Method Details

    • isBinaryPath

      public static boolean isBinaryPath(Path path)
      Checks if a path corresponds to a known binary file path.
      Parameters:
      path - the path to check
      Returns:
      true if the path is known to contain only files, or false otherwise
    • isObjectPath

      public static boolean isObjectPath(Path path)
      Checks if a path corresponds to a non-root and non-binary path. Note that index paths are still considered object paths by this method.
      Parameters:
      path - the path to check
      Returns:
      true if the path is known to contain objects, or false otherwise
    • mounts

      public Stream<Storage> mounts(Path path)
      Returns a stream of all mounted storages found under a path.
      Parameters:
      path - the base path to check
      Returns:
      the stream of mounted storages
    • mount

      public void mount(Storage storage, Path path) throws StorageException
      Mounts a storage to a unique path. The path may not collide with a previously mounted storage, such that it would hide or be hidden by the other storage. Overlapping parent indices will be merged automatically. The storage will be added as read-only and must be remounted to enable writes, root overlays or caches.
      Parameters:
      storage - the storage to mount
      path - the storage mount path
      Throws:
      StorageException - if the storage couldn't be mounted
    • remount

      public void remount(Path path, boolean readWrite, Path cache, Path overlay, int prio) throws StorageException
      Remounts an already mounted storage to enable/disable read-write, caching and root overlay options. The storage or its mount path are not modified, only the mount options.
      Parameters:
      path - the storage mount path
      readWrite - the read write flag
      cache - the storage cache path, or null
      overlay - the root overlay path
      prio - the root overlay search priority (higher numbers are searched before lower numbers)
      Throws:
      StorageException - if the storage couldn't be remounted
    • unmount

      public void unmount(Path path) throws StorageException
      Unmounts a storage from the specified path. The path must have previously been used to mount a storage, which will also be destroyed by this operation.
      Parameters:
      path - the mount path
      Throws:
      StorageException - if the storage couldn't be unmounted
    • unmountAll

      public void unmountAll()
      Unmounts and destroys all mounted storages.
    • 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.
      Overrides:
      lookup in class MemoryStorage
      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.
      Overrides:
      load in class MemoryStorage
      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.
      Overrides:
      store in class MemoryStorage
      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.
      Overrides:
      remove in class MemoryStorage
      Parameters:
      path - the storage location
      Throws:
      StorageException - if the data couldn't be removed
    • cacheClean

      public void cacheClean(boolean force)
      Cleans up (inactive) cached objects. Cached objects will be stored (if modified), passivated and finally evicted from cache if no longer active (or if force flag set). This method is called regularly from a background job.
      Parameters:
      force - the force removal flag