Class JPPFStatistics

java.lang.Object
org.jppf.utils.stats.JPPFStatistics
All Implemented Interfaces:
Serializable, Iterable<JPPFSnapshot>

public class JPPFStatistics extends Object implements Serializable, Iterable<JPPFSnapshot>
Instances of this class hold statistics snapshots. To create and add a new snapshot, createSnapshot(String) should be called first, before any call to one of the addXXX() methods, in order to respect thread safety.
Author:
Laurent Cohen
See Also:
  • Field Details

    • NOOP_FILTER

      public static final JPPFStatistics.Filter NOOP_FILTER
      A filter which accepts all snapshots.
  • Constructor Details

    • JPPFStatistics

      public JPPFStatistics()
      Default constructor.
  • Method Details

    • getSnapshot

      public JPPFSnapshot getSnapshot(String label)
      Get a snapshot specified by its label.
      Parameters:
      label - the label of the snapshot to look up.
      Returns:
      a JPPFSnapshot instance, or null if none could be found with the specified label.
    • createSnapshot

      public JPPFSnapshot createSnapshot(String label)
      Create a snapshot with the specified label if it doesn't exist. If a snapshot with this label already exists, it is returned.
      Parameters:
      label - the label of the snapshot to create.
      Returns:
      a JPPFSnapshot instance representing the newly created snapshot or the exsting one.
    • createSnapshot

      public JPPFSnapshot createSnapshot(boolean cumulative, String label)
      Create a snapshot with the specified label if it doesn't exist. If a snapshot with this label already exists, it is returned.
      Parameters:
      label - the label of the snapshot to create.
      cumulative - determines whether updates are accumulated instead of simply stored as latest value.
      Returns:
      a JPPFSnapshot instance representing the newly created snapshot or the exsting one.
    • createSingleValueSnapshot

      public JPPFSnapshot createSingleValueSnapshot(String label)
      Create a single value snapshot with the specified label if it doesn't exist. If a snapshot with this label already exists, it is returned.
      Parameters:
      label - the label of the snapshot to create.
      Returns:
      a JPPFSnapshot instance representing the newly created snapshot or the exsting one.
    • createSnapshots

      public JPPFSnapshot[] createSnapshots(String... labels)
      Create an array of snapshots with the specified labels, if it doesn't exist. If one of the snapshots already exists, it is returned.
      Parameters:
      labels - the label of the snapshot to create.
      Returns:
      an array of JPPFSnapshot instances representing the newly created or exsting snapshots, in the same order as the input labels.
    • createSnapshots

      public JPPFSnapshot[] createSnapshots(boolean cumulative, String... labels)
      Create an array of snapshots with the specified labels, if they don't exist. If any of the snapshots already exists, it is returned.
      Parameters:
      labels - the label of the snapshot to create.
      cumulative - determines whether updates are accumulated instead of simply stored as latest value.
      Returns:
      an array of JPPFSnapshot instances representing the newly created or exsting snapshots, in the same order as the input labels.
    • createSingleValueSnapshots

      public JPPFSnapshot[] createSingleValueSnapshots(String... labels)
      Create an array of single value snapshots with the specified labels, if they don't exist. If any of the snapshots already exists, it is returned.
      Parameters:
      labels - the label of the snapshot to create.
      Returns:
      an array of JPPFSnapshot instances representing the newly created or exsting snapshots, in the same order as the input labels.
    • removeSnapshot

      public JPPFSnapshot removeSnapshot(String label)
      Remove the snapshot with the specified label. If a snapshot with this label already exists, it is returned.
      Parameters:
      label - the label of the snapshot to create.
      Returns:
      a JPPFSnapshot instance representing the removed snapshot or null if the label is not in the map.
    • addValue

      public JPPFSnapshot addValue(String label, double value)
      Add the specified value to the snapshot with the specified label.
      Parameters:
      label - the label of the snapshot to add the value to.
      value - the accumulated sum of the values to add.
      Returns:
      a reference to the updated JPPFSnapshot object.
      Throws:
      IllegalStateException - if the snapshot does not exist.
    • addValues

      public JPPFSnapshot addValues(String label, double accumulatedValues, long count)
      Add the specified values to the snapshot with the specified label.
      Parameters:
      label - the label of the snapshot to add the values to.
      accumulatedValues - the accumulated sum of the values to add.
      count - the number of values in the accumalated values.
      Returns:
      a reference to the updated JPPFSnapshot object.
      Throws:
      IllegalStateException - if the snapshot does not exist.
    • copy

      public JPPFStatistics copy()
      Build a copy of this stats object.
      Returns:
      a new JPPFStats instance, populated with the current values of the fields in this stats object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • reset

      public void reset()
      Reset all contained snapshots to their initial values.
    • reset

      public void reset(JPPFStatistics.Filter filter)
      Reset all contained snapshots to their initial values.
      Parameters:
      filter - determines which snapshots will be reset.
    • clear

      public void clear()
      Remove all snapshots from this object.
    • getSnapshots

      public Collection<JPPFSnapshot> getSnapshots()
      Get all the snapshots in this object.
      Returns:
      a collection of JPPFSnapshot instances.
    • getSnapshots

      public Collection<JPPFSnapshot> getSnapshots(JPPFStatistics.Filter filter)
      Get the snapshots which satisfy the specified filter.
      Parameters:
      filter - determines which snapshots will be part of the returned collection.
      Returns:
      a collection of JPPFSnapshot instances, possibly empty but never null.
    • addListener

      public void addListener(JPPFStatisticsListener listener)
      Add a listener to the list of listeners. This is equivalent to calling addListener(listener, null).
      Parameters:
      listener - the listener to add.
    • addListener

      public void addListener(JPPFStatisticsListener listener, JPPFStatistics.Filter filter)
      Add a filtered listener to the list of listeners.
      Parameters:
      listener - the listener to add.
      filter - the filter to apply to the listener. If null, then no filter is applied.
    • removeListener

      public void removeListener(JPPFStatisticsListener listener)
      Remove a listener to the list of listeners.
      Parameters:
      listener - the listener to remove.
    • removeListener

      public void removeListener(JPPFStatisticsListener listener, JPPFStatistics.Filter filter)
      Remove a listener to the list of listeners.
      Parameters:
      listener - the listener to remove.
      filter - the filter associated ith the listener to remove.
    • getListeners

      public Set<JPPFStatisticsListener> getListeners()
      Returns:
      the set of listeners registered with this statistics snapshot.
    • clearListeners

      public void clearListeners()
      Clear the listeners registered with this statistics snapshot.
    • iterator

      public Iterator<JPPFSnapshot> iterator()
      Specified by:
      iterator in interface Iterable<JPPFSnapshot>