Package org.jrobin.core
Class Robin
- java.lang.Object
-
- org.jrobin.core.Robin
-
- All Implemented Interfaces:
RrdUpdater
public class Robin extends Object implements RrdUpdater
Class to represent archive values for a single datasource. Robin class is the heart of the so-called "round robin database" concept. Basically, each Robin object is a fixed length array of double values. Each double value reperesents consolidated, archived value for the specific timestamp. When the underlying array of double values gets completely filled, new values will replace the oldest ones.Robin object does not hold values in memory - such object could be quite large. Instead of it, Robin reads them from the backend I/O only when necessary.
- Author:
- Sasa Markovic
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
bulkStore(double newValue, int bulkCount)
void
copyStateTo(RrdUpdater other)
Copies object's internal state to another Robin object.(package private) String
dump()
void
filterValues(double minValue, double maxValue)
Filters values stored in this archive based on the given boundary.Archive
getParent()
Returns the Archive object to which this Robin object belongs.RrdAllocator
getRrdAllocator()
Required to implement RrdUpdater interface.RrdBackend
getRrdBackend()
Returns the underlying storage (backend) object which actually performs all I/O operations.int
getSize()
Returns the size of the underlying array of archived values.double
getValue(int index)
Returns the i-th value from the Robin archive.double[]
getValues()
Fetches all archived values.(package private) double[]
getValues(int index, int count)
void
setValue(int index, double value)
Sets the i-th value in the Robin archive.void
setValues(double newValue)
(Re)sets all values in this archive to the same value.void
setValues(double[] newValues)
Updates archived values in bulk.(package private) void
store(double newValue)
(package private) void
update(double[] newValues)
-
-
-
Constructor Detail
-
Robin
Robin(Archive parentArc, int rows, boolean shouldInitialize) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getValues
public double[] getValues() throws IOException
Fetches all archived values.- Returns:
- Array of double archive values, starting from the oldest one.
- Throws:
IOException
- Thrown in case of I/O specific error.
-
store
void store(double newValue) throws IOException
- Throws:
IOException
-
bulkStore
void bulkStore(double newValue, int bulkCount) throws IOException
- Throws:
IOException
-
update
void update(double[] newValues) throws IOException
- Throws:
IOException
-
setValues
public void setValues(double[] newValues) throws IOException, RrdException
Updates archived values in bulk.- Parameters:
newValues
- Array of double values to be stored in the archive- Throws:
IOException
- Thrown in case of I/O errorRrdException
- Thrown if the length of the input array is different from the length of this archive
-
setValues
public void setValues(double newValue) throws IOException
(Re)sets all values in this archive to the same value.- Parameters:
newValue
- New value- Throws:
IOException
- Thrown in case of I/O error
-
dump
String dump() throws IOException
- Throws:
IOException
-
getValue
public double getValue(int index) throws IOException
Returns the i-th value from the Robin archive.- Parameters:
index
- Value index- Returns:
- Value stored in the i-th position (the oldest value has zero index)
- Throws:
IOException
- Thrown in case of I/O specific error.
-
setValue
public void setValue(int index, double value) throws IOException
Sets the i-th value in the Robin archive.- Parameters:
index
- index in the archive (the oldest value has zero index)value
- value to be stored- Throws:
IOException
- Thrown in case of I/O specific error.
-
getValues
double[] getValues(int index, int count) throws IOException
- Throws:
IOException
-
getParent
public Archive getParent()
Returns the Archive object to which this Robin object belongs.- Returns:
- Parent Archive object
-
getSize
public int getSize()
Returns the size of the underlying array of archived values.- Returns:
- Number of stored values
-
copyStateTo
public void copyStateTo(RrdUpdater other) throws IOException, RrdException
Copies object's internal state to another Robin object.- Specified by:
copyStateTo
in interfaceRrdUpdater
- Parameters:
other
- New Robin object to copy state to- Throws:
IOException
- Thrown in case of I/O errorRrdException
- Thrown if supplied argument is not a Robin object
-
filterValues
public void filterValues(double minValue, double maxValue) throws IOException
Filters values stored in this archive based on the given boundary. Archived values found to be outside of[minValue, maxValue]
interval (inclusive) will be silently replaced withNaN
.- Parameters:
minValue
- lower boundarymaxValue
- upper boundary- Throws:
IOException
- Thrown in case of I/O error
-
getRrdBackend
public RrdBackend getRrdBackend()
Returns the underlying storage (backend) object which actually performs all I/O operations.- Specified by:
getRrdBackend
in interfaceRrdUpdater
- Returns:
- I/O backend object
-
getRrdAllocator
public RrdAllocator getRrdAllocator()
Required to implement RrdUpdater interface. You should never call this method directly.- Specified by:
getRrdAllocator
in interfaceRrdUpdater
- Returns:
- Allocator object
-
-