Class Metrics

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

    • PATH

      public static final Path PATH
      The metrics object storage path.

      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.
      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.
      storage - the storage to search in
      id - the metrics identifier
      the metrics set found or newly created
      StorageException - if a new metrics set couldn't be stored
    • init

      protected void init()
      Initializes this object after loading it from a storage.
      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.
      isModified in class StorableObject
      true if the object has been modified, or false otherwise
    • passivate

      protected void passivate()
      Discards the modified flag for this object.
      passivate in class StorableObject
    • stream

      public Stream<Map.Entry<String,MovingUsage>> stream()
      Returns a stream of all resource usage metrics.
      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.
      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.
      serialize in class StorableObject
      the serialized representation of this object