public abstract class RrdBackend extends Object
RrdDb object) is backed with a single RrdBackend object which performs actual I/O
operations on the underlying storage. Rrd4j supports multiple backends out of the box. E.g.:
RrdRandomAccessFileBackend: objects of this class are created from
the RrdRandomAccessFileBackendFactory class. This was the default
backend used in all Rrd4j releases prior to 1.4.0. It uses java.io.* package and
RandomAccessFile class to store RRD data in files on the disk.
RrdNioBackend: objects of this class are created from the RrdNioBackendFactory class. The backend uses java.io.* and java.nio.*
classes (mapped ByteBuffer) to store RRD data in files on the disk. This backend is fast,
very fast, but consumes a lot of memory (borrowed not from the JVM but from the underlying
operating system directly). This is the default backend used in Rrd4j since 1.4.0
release.
RrdMemoryBackend: objects of this class are created from the RrdMemoryBackendFactory class. This backend stores all data in memory. Once
JVM exits, all data gets lost. The backend is extremely fast and memory hungry.
To create your own backend in order to provide some custom type of RRD storage, you should do the following:
RrdBackendFactory to
find out how to do this.
| Modifier and Type | Field and Description |
|---|---|
protected static ByteOrder |
BYTEORDER
All
ByteBuffer usage should use this standard order. |
| Modifier | Constructor and Description |
|---|---|
protected |
RrdBackend(String path)
Creates backend for a RRD storage with the given path.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
close()
Closes the underlying backend.
|
(package private) void |
done(RrdBackendFactory factory,
PhantomReference<RrdDb> ref) |
protected CharBuffer |
getCharBuffer(long offset,
int size)
Extract a CharBuffer from the backend, used by readString
|
RrdBackendFactory |
getFactory() |
abstract long |
getLength()
Returns the number of RRD bytes in the underlying storage.
|
String |
getPath()
Returns path to the storage.
|
URI |
getUri()
Return the URI associated to this backend, using the factory to generate it from the path.
|
protected boolean |
isCachingAllowed()
This method suggests the caching policy to the Rrd4j frontend (high-level) classes.
|
(package private) static boolean |
isInstanceCreated()
Checks if a backend instance has been created.
|
protected abstract void |
read(long offset,
byte[] b)
Reads an array of bytes from the underlying storage starting from the given storage offset.
|
byte[] |
readAll()
Reads all RRD bytes from the underlying storage.
|
protected double |
readDouble(long offset)
Reads a double value from the underlying storage at the given offset.
|
protected double[] |
readDouble(long offset,
int count)
Reads an array of double values from the underlying storage at the given offset.
|
protected int |
readInt(long offset)
Reads an integer value from the underlying storage at the given offset.
|
protected long |
readLong(long offset)
Reads a long value from the underlying storage at the given offset.
|
protected short |
readShort(long offset)
Reads a short value from the underlying storage at the given offset.
|
protected String |
readString(long offset)
Reads a string from the underlying storage at the given offset.
|
protected void |
rrdClose()
Closes the underlying backend.
|
protected abstract void |
setLength(long length)
Sets the number of bytes in the underlying RRD storage.
|
protected abstract void |
write(long offset,
byte[] b)
Writes an array of bytes to the underlying storage starting from the given storage offset.
|
protected void |
writeDouble(long offset,
double value)
Writes a double value to the underlying storage at the given offset.
|
protected void |
writeDouble(long offset,
double[] values)
Writes an array of double values to the underlying storage at the given offset.
|
protected void |
writeDouble(long offset,
double value,
int count)
Writes multiple copies of a double value to the underlying storage at the given offset.
|
protected void |
writeInt(long offset,
int value)
Writes an integer value to the underlying storage at the given offset.
|
protected void |
writeLong(long offset,
long value)
Writes a long value to the underlying storage at the given offset.
|
protected void |
writeShort(long offset,
short value)
Writes a short value to the underlying storage at the given offset.
|
protected void |
writeString(long offset,
String value)
Writes a string to the underlying storage at the given offset.
|
protected void |
writeString(long offset,
String value,
int length)
Writes a string to the underlying storage at the given offset with a fixed length.
|
protected static final ByteOrder BYTEORDER
ByteBuffer usage should use this standard order.protected RrdBackend(String path)
path - String identifying RRD storage. For files on the disk, this argument should
represent file path. Other storage types might interpret this argument differently.protected abstract void close()
throws IOException
IOException - Thrown in case of I/O errorvoid done(RrdBackendFactory factory, PhantomReference<RrdDb> ref)
factory - the factory to setprotected CharBuffer getCharBuffer(long offset, int size) throws IOException
offset - the offset in the rrdsize - the size of the buffer, in characterIOException - if the read failspublic RrdBackendFactory getFactory()
public abstract long getLength()
throws IOException
IOException - Thrown in case of I/O error.public String getPath()
public URI getUri()
protected boolean isCachingAllowed()
true is returned, frontend classes will cache frequently used parts of a RRD file in
memory to improve performance. If false is returned, high level classes will
never cache RRD file sections in memory.true if file caching is enabled, false otherwise. By
default, the method returns true but it can be overridden in subclasses.static boolean isInstanceCreated()
protected abstract void read(long offset,
byte[] b)
throws IOException
offset - Storage offset.b - Array which receives bytes from the underlying storageIOException - Thrown in case of I/O errorpublic final byte[] readAll()
throws IOException
IOException - Thrown in case of I/O errorprotected double readDouble(long offset)
throws IOException
offset - Storage offset.IOException - Thrown in case of I/O error.protected double[] readDouble(long offset,
int count)
throws IOException
offset - Storage offset.count - Number of double values to read.IOException - Thrown in case of I/O error.protected int readInt(long offset)
throws IOException
offset - Storage offset.IOException - Thrown in case of I/O error.protected long readLong(long offset)
throws IOException
offset - Storage offset.IOException - Thrown in case of I/O error.protected short readShort(long offset)
throws IOException
offset - Storage offset.IOException - Thrown in case of I/O error.protected final String readString(long offset) throws IOException
offset - Storage offset.IOException - Thrown in case of I/O error.protected void rrdClose()
throws IOException
RrdDb#close() when it's closed. All subclass
must keep calling it.IOException - Thrown in case of I/O errorprotected abstract void setLength(long length)
throws IOException
length - Length of the underlying RRD storage in bytes.IOException - Thrown in case of I/O error.protected abstract void write(long offset,
byte[] b)
throws IOException
offset - Storage offset.b - Array of bytes that should be copied to the underlying storageIOException - Thrown in case of I/O errorprotected void writeDouble(long offset,
double value)
throws IOException
offset - Storage offset.value - Double value to write.IOException - Thrown in case of I/O error.protected void writeDouble(long offset,
double[] values)
throws IOException
offset - Storage offset.values - Array of double values to write.IOException - Thrown in case of I/O error.protected void writeDouble(long offset,
double value,
int count)
throws IOException
offset - Storage offset.value - Double value to write.count - Number of times to write the value.IOException - Thrown in case of I/O error.protected void writeInt(long offset,
int value)
throws IOException
offset - Storage offset.value - Integer value to write.IOException - Thrown in case of I/O error.protected void writeLong(long offset,
long value)
throws IOException
offset - Storage offset.value - Long value to write.IOException - Thrown in case of I/O error.protected void writeShort(long offset,
short value)
throws IOException
offset - Storage offset.value - Short value to write.IOException - Thrown in case of I/O error.protected final void writeString(long offset,
String value)
throws IOException
offset - Storage offset.value - String value to write.IOException - Thrown in case of I/O error.protected void writeString(long offset,
String value,
int length)
throws IOException
offset - Storage offset.value - String value to write.length - Fixed length for the string storage.IOException - Thrown in case of I/O error.