Class Metrics


public class Metrics extends StorableObject
A metrics set for tracking resource usage.
Version:
1.0
  • Field Details

    • PATH

      public static final Path PATH
      The metrics object storage path.
    • KEY_UPDATED

      public static final String KEY_UPDATED
      The dictionary key for the last updated timestamp.
      See Also:
    • KEY_DATA

      public static final String KEY_DATA
      The dictionary key for the map of data points.
      See Also:
  • Constructor Details

    • Metrics

      public Metrics(String id, String type, Dict dict)
      Creates a new metrics set from a serialized representation.
      Parameters:
      id - the object identifier
      type - the object type name
      dict - the serialized representation
  • Method Details

    • findOrCreate

      public static Metrics findOrCreate(Storage storage, String id) throws StorageException
      Finds or creates a metrics set in the storage.
      Parameters:
      storage - the storage to search in
      id - 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 class StorableObject
    • 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 class StorableObject
      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 class StorableObject
    • stream

      public Stream<Map.Entry<String,MovingUsage>> stream()
      Returns a stream of all resource usage metrics.
      Returns:
      the metrics entry stream
    • report

      public void report(String key, long now, int value, long duration, boolean success, String error)
      Reports usage for a specified key.
      Parameters:
      key - the object identifier or other key to track
      now - the timestamp (in millis) for the usage time
      value - the usage count to add, or zero (0) for none
      duration - the duration (in millis), or zero (0) to skip
      success - the success flag
      error - the optional error message
    • 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