Package org.jppf.utils.stats
Class JPPFStatistics
java.lang.Object
org.jppf.utils.stats.JPPFStatistics
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA filter interface for snapshots. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JPPFStatistics.FilterA filter which accepts all snapshots. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(JPPFStatisticsListener listener) Add a listener to the list of listeners.voidaddListener(JPPFStatisticsListener listener, JPPFStatistics.Filter filter) Add a filtered listener to the list of listeners.Add the specified value to the snapshot with the specified label.Add the specified values to the snapshot with the specified label.voidclear()Remove all snapshots from this object.voidClear the listeners registered with this statistics snapshot.copy()Build a copy of this stats object.createSingleValueSnapshot(String label) Create a single value snapshot with the specified label if it doesn't exist.createSingleValueSnapshots(String... labels) Create an array of single value snapshots with the specified labels, if they don't exist.createSnapshot(boolean cumulative, String label) Create a snapshot with the specified label if it doesn't exist.createSnapshot(String label) Create a snapshot with the specified label if it doesn't exist.createSnapshots(boolean cumulative, String... labels) Create an array of snapshots with the specified labels, if they don't exist.createSnapshots(String... labels) Create an array of snapshots with the specified labels, if it doesn't exist.getSnapshot(String label) Get a snapshot specified by its label.Get all the snapshots in this object.getSnapshots(JPPFStatistics.Filter filter) Get the snapshots which satisfy the specified filter.iterator()voidremoveListener(JPPFStatisticsListener listener) Remove a listener to the list of listeners.voidremoveListener(JPPFStatisticsListener listener, JPPFStatistics.Filter filter) Remove a listener to the list of listeners.removeSnapshot(String label) Remove the snapshot with the specified label.voidreset()Reset all contained snapshots to their initial values.voidreset(JPPFStatistics.Filter filter) Reset all contained snapshots to their initial values.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
NOOP_FILTER
A filter which accepts all snapshots.
-
-
Constructor Details
-
JPPFStatistics
public JPPFStatistics()Default constructor.
-
-
Method Details
-
getSnapshot
Get a snapshot specified by its label.- Parameters:
label- the label of the snapshot to look up.- Returns:
- a
JPPFSnapshotinstance, ornullif none could be found with the specified label.
-
createSnapshot
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
JPPFSnapshotinstance representing the newly created snapshot or the exsting one.
-
createSnapshot
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
JPPFSnapshotinstance representing the newly created snapshot or the exsting one.
-
createSingleValueSnapshot
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
JPPFSnapshotinstance representing the newly created snapshot or the exsting one.
-
createSnapshots
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
JPPFSnapshotinstances representing the newly created or exsting snapshots, in the same order as the input labels.
-
createSnapshots
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
JPPFSnapshotinstances representing the newly created or exsting snapshots, in the same order as the input labels.
-
createSingleValueSnapshots
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
JPPFSnapshotinstances representing the newly created or exsting snapshots, in the same order as the input labels.
-
removeSnapshot
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
JPPFSnapshotinstance representing the removed snapshot ornullif the label is not in the map.
-
addValue
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
JPPFSnapshotobject. - Throws:
IllegalStateException- if the snapshot does not exist.
-
addValues
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
JPPFSnapshotobject. - Throws:
IllegalStateException- if the snapshot does not exist.
-
copy
Build a copy of this stats object.- Returns:
- a new
JPPFStatsinstance, populated with the current values of the fields in this stats object.
-
toString
-
reset
public void reset()Reset all contained snapshots to their initial values. -
reset
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
Get all the snapshots in this object.- Returns:
- a collection of
JPPFSnapshotinstances.
-
getSnapshots
Get the snapshots which satisfy the specified filter.- Parameters:
filter- determines which snapshots will be part of the returned collection.- Returns:
- a collection of
JPPFSnapshotinstances, possibly empty but never null.
-
addListener
Add a listener to the list of listeners. This is equivalent to callingaddListener(listener, null).- Parameters:
listener- the listener to add.
-
addListener
Add a filtered listener to the list of listeners.- Parameters:
listener- the listener to add.filter- the filter to apply to the listener. Ifnull, then no filter is applied.
-
removeListener
Remove a listener to the list of listeners.- Parameters:
listener- the listener to remove.
-
removeListener
Remove a listener to the list of listeners.- Parameters:
listener- the listener to remove.filter- the filter associated ith the listener to remove.
-
getListeners
- Returns:
- the set of listeners registered with this statistics snapshot.
-
clearListeners
public void clearListeners()Clear the listeners registered with this statistics snapshot. -
iterator
- Specified by:
iteratorin interfaceIterable<JPPFSnapshot>
-