Class Average
java.lang.Object
org.jgroups.util.Average
- All Implemented Interfaces:
Streamable
- Direct Known Subclasses:
AverageMinMax
Maintains an approximation of an average of positive (>= 0) values in a window and adding new values at random
indices.
This class is lock-less, at the expense of incorrect reads and writes (by multiple threads), but the noise of these errors should be negligible. Note that a bigger capacity (window size) reduces this noise.
This class is lock-less, at the expense of incorrect reads and writes (by multiple threads), but the noise of these errors should be negligible. Note that a bigger capacity (window size) reduces this noise.
- Since:
- 3.4, 5.4
- Author:
- Bela Ban
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected intprotected static final intprotected long[]protected TimeUnit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Average>
Tadd(long num) doubleaverage()Returns the average of all valid samples divided by the number of valid samplesintcapacity()voidclear()intcount()Returns the number of valid samples (>= 0)doublebooleanisEmpty()Returns true if there are no valid samples (>= 0), false otherwise<T extends Average>
Tmerge(T other) Merges this average with another onevoidRead the state of the current object (including superclasses) from instream Note that the input stream must not be closedtoString()longtotal()Returns the total of all valid (>= 0) valuesunit()<T extends Average>
TvoidwriteTo(DataOutput out) Write the entire state of the current object (including superclasses) to outstream.
-
Field Details
-
samples
protected long[] samples -
unit
-
all_filled
protected volatile boolean all_filled -
cap
protected int cap -
DEFAULT_CAPACITY
protected static final int DEFAULT_CAPACITY- See Also:
-
-
Constructor Details
-
Average
public Average() -
Average
public Average(int capacity)
-
-
Method Details
-
capacity
public int capacity() -
unit
-
unit
-
getAverage
public double getAverage() -
add
-
merge
Merges this average with another one -
total
public long total()Returns the total of all valid (>= 0) values -
count
public int count()Returns the number of valid samples (>= 0) -
isEmpty
public boolean isEmpty()Returns true if there are no valid samples (>= 0), false otherwise -
average
public double average()Returns the average of all valid samples divided by the number of valid samples -
clear
public void clear() -
toString
-
toString
-
writeTo
Description copied from interface:StreamableWrite the entire state of the current object (including superclasses) to outstream. Note that the output stream must not be closed- Specified by:
writeToin interfaceStreamable- Throws:
IOException
-
readFrom
Description copied from interface:StreamableRead the state of the current object (including superclasses) from instream Note that the input stream must not be closed- Specified by:
readFromin interfaceStreamable- Throws:
IOException
-