Package org.rapidcontext.core.storage
Class MemoryStorage
java.lang.Object
org.rapidcontext.core.storage.StorableObject
org.rapidcontext.core.storage.Storage
org.rapidcontext.core.storage.MemoryStorage
- All Implemented Interfaces:
Comparable<Storage>
- Direct Known Subclasses:
RootStorage
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
-
Field Summary
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
ConstructorDescriptionMemoryStorage
(String id, boolean readWrite, boolean storageInfo) Creates a new memory storage. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Destroys this storage.boolean
isStorable
(Object obj) Checks if the specified object is supported in this storage.Loads an object from the specified location.Searches for an object at the specified location and returns metadata about the object if found.void
Removes an object or an index at the specified location.Returns a serialized representation of this object.void
Stores an object at the specified location.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
-
Constructor Details
-
MemoryStorage
Creates a new memory storage.- Parameters:
id
- the storage identifierreadWrite
- the read write flagstorageInfo
- the show storage info flag
-
-
Method Details
-
isStorable
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 classStorableObject
-
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. -
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. -
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.- Specified by:
store
in classStorage
- 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.- Specified by:
remove
in classStorage
- Parameters:
path
- the storage location- Throws:
StorageException
- if the data couldn't be removed
-
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 classStorableObject
- Returns:
- the serialized representation of this object
-