java.lang.Object
org.rrd4j.core.RrdBackend
org.rrd4j.core.ByteBufferBackend
- Direct Known Subclasses:
RrdByteArrayBackend, RrdMemoryBackend, RrdNioBackend
A backend that store and provides access to data using a
ByteBuffer, using java internal methods for long, integer and others types.Field Summary
FieldsModifier and TypeFieldDescriptionprivate ByteBufferThe file contents held in memory.private booleanTrue while the buffer holds changes not yet written.Fields inherited from class RrdBackend
BYTEORDERModifier and TypeFieldDescriptionprotected static final ByteOrderAllByteBufferusage should use this standard order.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedByteBufferBackend(String path) Constructs a ByteBufferBackend with the given file path.Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckOffsetAndByteBuffer(long offset) Ensure that the conversion from long offset to integer offset will not overflowprotected voidclose()Closes the underlying backend.protected CharBuffergetCharBuffer(long offset, int size) Extract a CharBuffer from the backend, used by readStringprotected booleanisDirty()Check whether the buffer has been modified since the last sync.protected voidread(long offset, byte[] b) Reads a number of bytes from the RRD file on the diskdoublereadDouble(long offset) Reads a double value from the underlying storage at the given offset.double[]readDouble(long offset, int count) Reads an array of double values from the underlying storage at the given offset.protected intreadInt(long offset) Reads an integer value from the underlying storage at the given offset.protected longreadLong(long offset) Reads a long value from the underlying storage at the given offset.protected shortreadShort(long offset) Reads a short value from the underlying storage at the given offset.protected voidrrdClose()Closes the underlying backend.protected voidsetByteBuffer(ByteBuffer byteBuffer) Set the byte buffer to use for backing storage.protected voidwrite(long offset, byte[] b) Writes bytes to the underlying RRD file on the diskprotected voidwriteDouble(long offset, double value) Writes a double value to the underlying storage at the given offset.protected voidwriteDouble(long offset, double[] values) Writes an array of double values to the underlying storage at the given offset.protected voidwriteDouble(long offset, double value, int count) Writes multiple copies of a double value to the underlying storage at the given offset.protected voidwriteInt(long offset, int value) Writes an integer value to the underlying storage at the given offset.protected voidwriteLong(long offset, long value) Writes a long value to the underlying storage at the given offset.protected voidwriteShort(long offset, short value) Writes a short value to the underlying storage at the given offset.protected voidwriteString(long offset, String value, int length) Writes a string to the underlying storage at the given offset with a fixed length.Methods inherited from class RrdBackend
done, getFactory, getLength, getPath, getUri, isCachingAllowed, isInstanceCreated, readAll, readString, setLength, writeStringModifier and TypeMethodDescription(package private) voiddone(RrdBackendFactory factory, PhantomReference<RrdDb> ref) Set the factory and reference for this backend.Get the factory for this backend.abstract longReturns the number of RRD bytes in the underlying storage.getPath()Returns path to the storage.getUri()Return the URI associated to this backend, using the factory to generate it from the path.protected booleanThis method suggests the caching policy to the Rrd4j frontend (high-level) classes.(package private) static booleanChecks if a backend instance has been created.final byte[]readAll()Reads all RRD bytes from the underlying storage.protected final StringreadString(long offset) Reads a string from the underlying storage at the given offset.protected abstract voidsetLength(long length) Sets the number of bytes in the underlying RRD storage.protected final voidwriteString(long offset, String value) Writes a string to the underlying storage at the given offset.
Field Details
dirty
private volatile boolean dirtyTrue while the buffer holds changes not yet written.byteBuffer
The file contents held in memory.
Constructor Details
ByteBufferBackend
Constructs a ByteBufferBackend with the given file path.- Parameters:
path- the file path
Method Details
setByteBuffer
Set the byte buffer to use for backing storage.- Parameters:
byteBuffer- the byte buffer to set
write
Writes bytes to the underlying RRD file on the disk- Specified by:
writein classRrdBackend- Parameters:
offset- Starting file offsetb- Bytes to be written.- Throws:
IOException- if the backend is read-onlyIllegalArgumentException- if offset is bigger that the possible mapping position (2GiB).
writeShort
Description copied from class:RrdBackendWrites a short value to the underlying storage at the given offset.- Overrides:
writeShortin classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.value- Short value to write.- Throws:
IOException- Thrown in case of I/O error.
writeInt
Description copied from class:RrdBackendWrites an integer value to the underlying storage at the given offset.- Overrides:
writeIntin classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.value- Integer value to write.- Throws:
IOException- Thrown in case of I/O error.
writeLong
Description copied from class:RrdBackendWrites a long value to the underlying storage at the given offset.- Overrides:
writeLongin classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.value- Long value to write.- Throws:
IOException- Thrown in case of I/O error.
writeDouble
Description copied from class:RrdBackendWrites a double value to the underlying storage at the given offset.- Overrides:
writeDoublein classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.value- Double value to write.- Throws:
IOException- Thrown in case of I/O error.
writeDouble
Description copied from class:RrdBackendWrites multiple copies of a double value to the underlying storage at the given offset.- Overrides:
writeDoublein classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.value- Double value to write.count- Number of times to write the value.- Throws:
IOException- Thrown in case of I/O error.
writeDouble
Description copied from class:RrdBackendWrites an array of double values to the underlying storage at the given offset.- Overrides:
writeDoublein classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.values- Array of double values to write.- Throws:
IOException- Thrown in case of I/O error.
writeString
Description copied from class:RrdBackendWrites a string to the underlying storage at the given offset with a fixed length.- Overrides:
writeStringin classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.value- String value to write.length- Fixed length for the string storage.- Throws:
IOException- Thrown in case of I/O error.
read
Reads a number of bytes from the RRD file on the disk- Specified by:
readin classRrdBackend- Parameters:
offset- Starting file offsetb- Buffer which receives bytes read from the file.- Throws:
IOException- Thrown in case of I/O error.IllegalArgumentException- if offset is bigger that the possible mapping position (2GiB).
readShort
Description copied from class:RrdBackendReads a short value from the underlying storage at the given offset.- Overrides:
readShortin classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.- Returns:
- The short value read from storage.
- Throws:
IOException- Thrown in case of I/O error.
readInt
Description copied from class:RrdBackendReads an integer value from the underlying storage at the given offset.- Overrides:
readIntin classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.- Returns:
- The integer value read from storage.
- Throws:
IOException- Thrown in case of I/O error.
readLong
Description copied from class:RrdBackendReads a long value from the underlying storage at the given offset.- Overrides:
readLongin classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.- Returns:
- The long value read from storage.
- Throws:
IOException- Thrown in case of I/O error.
readDouble
Description copied from class:RrdBackendReads a double value from the underlying storage at the given offset.- Overrides:
readDoublein classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.- Returns:
- The double value read from storage.
- Throws:
IOException- Thrown in case of I/O error.
readDouble
Description copied from class:RrdBackendReads an array of double values from the underlying storage at the given offset.- Overrides:
readDoublein classRrdBackend- Parameters:
offset- Byte offset into the RRD storage.count- Number of double values to read.- Returns:
- Array of double values read from storage.
- Throws:
IOException- Thrown in case of I/O error.
getCharBuffer
Description copied from class:RrdBackendExtract a CharBuffer from the backend, used by readString- Overrides:
getCharBufferin classRrdBackend- Parameters:
offset- the offset in the rrdsize- the size of the buffer, in character- Returns:
- a new CharBuffer
- Throws:
RrdException
close
Description copied from class:RrdBackendCloses the underlying backend. Used internally, should not be called from external code.- Specified by:
closein classRrdBackend- Throws:
IOException- Thrown in case of I/O error
checkOffsetAndByteBuffer
Ensure that the conversion from long offset to integer offset will not overflow- Parameters:
offset- the position in the file, from 0 to Integer.MAX_VALUE- Throws:
RrdException- if the backing buffer is null (empty rrd)IllegalArgumentException- if the offset is negative or too large
isDirty
protected boolean isDirty()Check whether the buffer has been modified since the last sync.- Returns:
- true if the buffer has been modified since last sync
rrdClose
Description copied from class:RrdBackendCloses the underlying backend. Call byRrdDb#close()when it's closed. All subclass must keep calling it.- Overrides:
rrdClosein classRrdBackend- Throws:
IOException- Thrown in case of I/O error