Package org.rapidcontext.core.storage
Class RootStorage
java.lang.Object
org.rapidcontext.core.storage.StorableObject
org.rapidcontext.core.storage.Storage
org.rapidcontext.core.storage.MemoryStorage
org.rapidcontext.core.storage.RootStorage
- All Implemented Interfaces:
Comparable<Storage>
- Direct Known Subclasses:
AppStorage
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Path
The storage path for public web files.static final Path
The storage path to the JAR library files.static final Path
The storage path for mounted storages.Fields inherited from class org.rapidcontext.core.storage.Storage
EXT_ALL, EXT_JSON, EXT_PROPERTIES, EXT_XML, EXT_YAML, KEY_MOUNT_OVERLAY_PATH, KEY_MOUNT_OVERLAY_PRIO, KEY_MOUNT_PATH, KEY_MOUNT_TIME, KEY_READWRITE, PATH_STORAGEINFO
Fields inherited from class org.rapidcontext.core.storage.StorableObject
dict, KEY_ACTIVATED_TIME, KEY_CLASSNAME, KEY_ID, KEY_TYPE, PREFIX_COMPUTED, PREFIX_HIDDEN
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
cacheClean
(boolean force) Cleans up (inactive) cached objects.static boolean
isBinaryPath
(Path path) Checks if a path corresponds to a known binary file path.static boolean
isObjectPath
(Path path) Checks if a path corresponds to a non-root and non-binary path.Loads an object from the specified location.Searches for an object at the specified location and returns metadata about the object if found.void
Mounts a storage to a unique path.Returns a stream of all mounted storages found under a path.void
Remounts an already mounted storage to enable/disable read-write, caching and root overlay options.void
Removes an object or an index at the specified location.void
Stores an object at the specified location.void
Unmounts a storage from the specified path.void
Unmounts and destroys all mounted storages.Methods inherited from class org.rapidcontext.core.storage.MemoryStorage
destroy, isStorable, serialize
Methods inherited from class org.rapidcontext.core.storage.Storage
compareTo, isReadWrite, load, localPath, mountOverlayPath, mountOverlayPrio, mountTime, objectName, objectPath, path, query, serialize, serializedPath, setMountInfo, unserialize
Methods inherited from class org.rapidcontext.core.storage.StorableObject
activate, activatedTime, id, init, isActive, isModified, passivate, sterilize, toString, type
-
Field Details
-
PATH_FILES
The storage path for public web files. -
PATH_LIB
The storage path to the JAR library files. -
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
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
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
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
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 mountpath
- 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 pathreadWrite
- the read write flagcache
- the storage cache path, or nulloverlay
- the root overlay pathprio
- the root overlay search priority (higher numbers are searched before lower numbers)- Throws:
StorageException
- if the storage couldn't be remounted
-
unmount
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
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 classMemoryStorage
- Parameters:
path
- the storage location- Returns:
- the metadata for the object, or null if not found
-
load
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 classMemoryStorage
- Parameters:
path
- the storage location- Returns:
- the data read, or null if not found
-
store
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 classMemoryStorage
- Parameters:
path
- the storage locationdata
- the data to store- Throws:
StorageException
- if the data couldn't be written
-
remove
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 classMemoryStorage
- 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
-