java.lang.Object
org.rrd4j.core.RrdPrimitive<U>
- Type Parameters:
U- The type of RrdUpdater this primitive belongs to
- Direct Known Subclasses:
RrdDouble, RrdDoubleArray, RrdDoubleMatrix, RrdEnum, RrdInt, RrdLong, RrdString
Abstract base class for all RRD primitive data types.
This class provides the foundation for storing different types of primitive data (int, long, double, string) in RRD files. It handles the low-level operations of reading and writing bytes to the backend storage, with support for caching and different data type sizes.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RrdBackendWhere the value is read and written.private final intSize of the value on disk, in bytes.private final booleanFalse to read every value from the backend.private final longOffset of the value within the backend.(package private) static final intType identifier for double RRD primitives.(package private) static final intType identifier for integer RRD primitives.(package private) static final intType identifier for long RRD primitives.(package private) static final int[]Array containing the size in bytes for each RRD primitive type.(package private) static final intType identifier for string RRD primitives.(package private) static final intMaximum length of string values stored in RRD primitives.Constructor Summary
ConstructorsConstructorDescriptionRrdPrimitive(RrdUpdater<U> updater, int type, boolean isConstant) Allocate a single-slot primitive in the updater's backend storage.RrdPrimitive(RrdUpdater<U> updater, int type, int count, boolean isConstant) Allocate a primitive array of the given length in the updater's backend storage.Method Summary
All MethodsModifier and TypeMethodDescription(package private) final booleanChecks if caching is allowed for this primitive.(package private) final byte[]Raw byte array from backend storage.(package private) final doubleReads the double value from backend storage.(package private) final doublereadDouble(int index) Position in the primitive array.(package private) final double[]readDouble(int index, int count) Starting position in the primitive array.protected final <E extends Enum<E>>
EDeserialize an enum value from backend storage.(package private) final intreadInt()Reads the int value from backend storage.(package private) final longreadLong()Reads the long value from backend storage.(package private) final StringReads the string value from backend storage.(package private) final voidwriteBytes(byte[] b) Byte array to write to backend storage.(package private) final voidwriteDouble(double value) Double value to write to backend storage.(package private) final voidwriteDouble(int index, double value) Position in the primitive array.(package private) final voidwriteDouble(int index, double[] values) Starting position in the primitive array.(package private) final voidwriteDouble(int index, double value, int count) Starting position in the primitive array.protected final <E extends Enum<E>>
voidwriteEnum(E value) Serialize an enum value to backend storage.(package private) final voidwriteInt(int value) Int value to write to backend storage.(package private) final voidwriteLong(long value) Long value to write to backend storage.(package private) final voidwriteString(String value) String value to write to backend storage.
Field Details
STRING_LENGTH
static final int STRING_LENGTHMaximum length of string values stored in RRD primitives.- See Also:
RRD_INT
RRD_LONG
RRD_DOUBLE
RRD_STRING
RRD_PRIM_SIZES
static final int[] RRD_PRIM_SIZESArray containing the size in bytes for each RRD primitive type. Index corresponds to the type constants (RRD_INT, RRD_LONG, RRD_DOUBLE, RRD_STRING).backend
Where the value is read and written.byteCount
private final int byteCountSize of the value on disk, in bytes.pointer
private final long pointerOffset of the value within the backend.cachingAllowed
private final boolean cachingAllowedFalse to read every value from the backend.
Constructor Details
RrdPrimitive
RrdPrimitive(RrdUpdater<U> updater, int type, boolean isConstant) Allocate a single-slot primitive in the updater's backend storage.- Parameters:
updater- the updater whose allocator and backend back this primitivetype- one of the RRD_INT, RRD_LONG, RRD_DOUBLE or RRD_STRING constants, selecting the slot sizeisConstant- true if the value never changes, which permits caching
RrdPrimitive
RrdPrimitive(RrdUpdater<U> updater, int type, int count, boolean isConstant) Allocate a primitive array of the given length in the updater's backend storage.- Parameters:
updater- the updater whose allocator and backend back this primitivetype- one of the RRD_INT, RRD_LONG, RRD_DOUBLE or RRD_STRING constants, selecting the slot sizecount- the number of consecutive slots to allocateisConstant- true if the value never changes, which permits caching
Method Details
readBytes
Raw byte array from backend storage.- Returns:
- the byteCount bytes stored at this primitive's pointer
- Throws:
IOException- if the backend storage cannot be read
writeBytes
Byte array to write to backend storage.- Parameters:
b- byte array to write to backend storage- Throws:
IOException- if the backend storage cannot be written
readInt
Reads the int value from backend storage.- Returns:
- the value stored at this primitive's pointer
- Throws:
IOException- if the backend storage cannot be read
writeInt
Int value to write to backend storage.- Parameters:
value- int value to write to backend storage- Throws:
IOException- if the backend storage cannot be written
readLong
Reads the long value from backend storage.- Returns:
- the value stored at this primitive's pointer
- Throws:
IOException- if the backend storage cannot be read
writeLong
Long value to write to backend storage.- Parameters:
value- long value to write to backend storage- Throws:
IOException- if the backend storage cannot be written
readDouble
Reads the double value from backend storage.- Returns:
- the value stored at this primitive's pointer
- Throws:
IOException- if the backend storage cannot be read
readDouble
Position in the primitive array.- Parameters:
index- position in the primitive array- Returns:
- double value at the given array index
- Throws:
IOException- if the backend storage cannot be read
readDouble
Starting position in the primitive array.- Parameters:
index- starting position in the primitive arraycount- number of consecutive doubles to read- Returns:
- array of double values
- Throws:
IOException- if the backend storage cannot be read
writeDouble
Double value to write to backend storage.- Parameters:
value- double value to write to backend storage- Throws:
IOException- if the backend storage cannot be written
writeDouble
Position in the primitive array.- Parameters:
index- position in the primitive arrayvalue- double value to write- Throws:
IOException- if the backend storage cannot be written
writeDouble
Starting position in the primitive array.- Parameters:
index- starting position in the primitive arrayvalue- double value to writecount- number of consecutive slots to fill- Throws:
IOException- if the backend storage cannot be written
writeDouble
Starting position in the primitive array.- Parameters:
index- starting position in the primitive arrayvalues- array of doubles to write- Throws:
IOException- if the backend storage cannot be written
readString
Reads the string value from backend storage.- Returns:
- the value stored at this primitive's pointer
- Throws:
IOException- if the backend storage cannot be read
writeString
String value to write to backend storage.- Parameters:
value- string value to write to backend storage- Throws:
IOException- if the backend storage cannot be written
readEnum
Deserialize an enum value from backend storage.- Type Parameters:
E- enum type- Parameters:
clazz- enum class to deserialize- Returns:
- the enum value, or null if the stored value is empty
- Throws:
IOException- if the backend storage cannot be read
writeEnum
Serialize an enum value to backend storage.- Type Parameters:
E- the enum type- Parameters:
value- the value to store as its enum constant name- Throws:
IOException- if the backend storage cannot be written
isCachingAllowed
final boolean isCachingAllowed()Checks if caching is allowed for this primitive.- Returns:
- true if caching is allowed, false otherwise