Package org.rapidcontext.core.type
Class Metrics
java.lang.Object
org.rapidcontext.core.storage.StorableObject
org.rapidcontext.core.type.Metrics
A metrics set for tracking resource usage.
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The dictionary key for the map of data points.static final String
The dictionary key for the last updated timestamp.static final Path
The metrics object storage path.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 TypeMethodDescriptionstatic Metrics
findOrCreate
(Storage storage, String id) Finds or creates a metrics set in the storage.protected void
init()
Initializes this object after loading it from a storage.protected boolean
Checks if this object has been modified since initialized from storage.protected void
Discards the modified flag for this object.void
Reports usage for a specified key.Returns a serialized representation of this object.stream()
Returns a stream of all resource usage metrics.Methods inherited from class org.rapidcontext.core.storage.StorableObject
activate, activatedTime, destroy, id, isActive, path, sterilize, toString, type
-
Field Details
-
PATH
The metrics object storage path. -
KEY_UPDATED
The dictionary key for the last updated timestamp.- See Also:
-
KEY_DATA
The dictionary key for the map of data points.- See Also:
-
-
Constructor Details
-
Metrics
Creates a new metrics set from a serialized representation.- Parameters:
id
- the object identifiertype
- the object type namedict
- the serialized representation
-
-
Method Details
-
findOrCreate
Finds or creates a metrics set in the storage.- Parameters:
storage
- the storage to search inid
- the metrics identifier- Returns:
- the metrics set found or newly created
- Throws:
StorageException
- if a new metrics set couldn't be stored
-
init
protected void init()Initializes this object after loading it from a storage.- Overrides:
init
in classStorableObject
-
isModified
protected boolean isModified()Checks if this object has been modified since initialized from storage. This method is used to allow "dirty" objects to be written back to persistent storage before being evicted from the in-memory cache. By default this method always returns false.- Overrides:
isModified
in classStorableObject
- Returns:
- true if the object has been modified, or false otherwise
-
passivate
protected void passivate()Discards the modified flag for this object.- Overrides:
passivate
in classStorableObject
-
stream
Returns a stream of all resource usage metrics.- Returns:
- the metrics entry stream
-
report
Reports usage for a specified key.- Parameters:
key
- the object identifier or other key to tracknow
- the timestamp (in millis) for the usage timevalue
- the usage count to add, or zero (0) for noneduration
- the duration (in millis), or zero (0) to skipsuccess
- the success flagerror
- the optional error message
-
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
-