java.lang.Object
org.rrd4j.core.RrdBackend
org.rrd4j.core.ByteBufferBackend
org.rrd4j.core.RrdNioBackend
- All Implemented Interfaces:
RrdFileBackend
Backend which is used to store RRD data to ordinary disk files using java.nio.* package. This is the default backend engine.
This version buffers all stat files in a single temporary buffer file sequentially, keeping track of each file's offset and length, then flushes all to the mapped file in batch.
Field Summary
Fields inherited from class RrdBackend
BYTEORDERModifier and TypeFieldDescriptionprotected static final ByteOrderAllByteBufferusage should use this standard order.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRrdNioBackend(String path, boolean readOnly, RrdSyncThreadPool threadPool, int syncPeriod) Creates RrdFileBackend object for the given file path, backed by java.nio.* classes.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidbufferStatFile(ByteBuffer data, long targetFileOffset) Buffers one stat file's data into the single temp buffer file sequentially.voidclose()Closes the underlying RRD file.voidFlushes all buffered stat files sequentially from the temp buffer file into their designated positions in the mapped RRD file in one batch operation.Returns canonical path to the file on the disk.longReturns the number of RRD bytes in the underlying storage.protected voidsetLength(long newLength) Sets the number of bytes in the underlying RRD storage.protected voidsync()Override sync to disable unbuffered flush.Methods inherited from class ByteBufferBackend
getCharBuffer, isDirty, read, readDouble, readDouble, readInt, readLong, readShort, rrdClose, setByteBuffer, write, writeDouble, writeDouble, writeDouble, writeInt, writeLong, writeShort, writeStringModifier and TypeMethodDescriptionprotected 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, getPath, getUri, isCachingAllowed, isInstanceCreated, readAll, readString, 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.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 final voidwriteString(long offset, String value) Writes a string to the underlying storage at the given offset.
Constructor Details
RrdNioBackend
protected RrdNioBackend(String path, boolean readOnly, RrdSyncThreadPool threadPool, int syncPeriod) throws IOException Creates RrdFileBackend object for the given file path, backed by java.nio.* classes.- Parameters:
path- Path to a filereadOnly- True, if file should be open in read-only mode. False otherwisethreadPool- Sync thread pool; can be nullsyncPeriod- Sync period in seconds- Throws:
IOException- On I/O error
Method Details
setLength
Sets the number of bytes in the underlying RRD storage. This method is called only once, immediately after a new RRD storage gets created. Sets length of the underlying RRD file. This method is called only once, immediately after new RRD creation.- Specified by:
setLengthin classRrdBackend- Parameters:
newLength- Length of the underlying RRD storage in bytes.- Throws:
IllegalArgumentException- if the length is bigger than the possible mapping position (2GiB).IOException- Thrown in case of I/O error.
close
Closes the underlying RRD file. Also closes and deletes the temporary buffer file used for buffering.- Overrides:
closein classByteBufferBackend- Throws:
IOException- On I/O error
bufferStatFile
Buffers one stat file's data into the single temp buffer file sequentially. This method appends the data to the temp file and records the offset and length, including the target offset in the mapped file where this stat file belongs.- Parameters:
data- ByteBuffer containing the stat file's bytes to buffertargetFileOffset- Position in the mapped RRD file to write this stat file to on flush- Throws:
IOException- If writing to temp file fails
flushBufferedStatFiles
public void flushBufferedStatFiles()Flushes all buffered stat files sequentially from the temp buffer file into their designated positions in the mapped RRD file in one batch operation. After flushing, the temp buffer file and index are cleared for the next batch.sync
protected void sync()Override sync to disable unbuffered flush.getLength
Description copied from class:RrdBackendReturns the number of RRD bytes in the underlying storage.- Specified by:
getLengthin classRrdBackend- Returns:
- Number of RRD bytes in the storage.
- Throws:
IOException- Thrown in case of I/O error.
getCanonicalPath
Description copied from interface:RrdFileBackendReturns canonical path to the file on the disk.- Specified by:
getCanonicalPathin interfaceRrdFileBackend- Returns:
- Canonical file path