Backends
RRD4J uses backend objects to store actual bytes for RRD database.
Each Round Robin Database object (RrdDb
object) is backed with a single RrdBackend
object which performs actual I/O operations on the underlying storage. The RrdBackend
object is itself not created directly but through factories, that are object instanciated from RrdBackendFactory
derivated classes.
RRD backend are registered and managed through the static methods RrdBackendFactory.setActiveFactories(RrdBackendFactory...)
and RrdBackendFactory.addActiveFactories(RrdBackendFactory...)
. It defined a ordered list of used factories.
When a RRD database is created without the factory argument and the path is given as simple string, or through the RrrDbPool
, it use the first factory specified with RrdBackendFactory.setActiveFactories(RrdBackendFactory...)
. But each factories can identify RrdDb using URI. So when a RrdDb is identify by an URI, each active factory is tried against this URI and the first one that accept this URI will handle it. It allows to have different of the same backend with different configuration. For more details, see the javadoc.
Factory classes are used to create concrete RrdBackend
implementations. Each factory creates unlimited number of specific backend objects. Rrd4j supports six different backend types (backend factories) out of the box:
-
FILE
: objects of this class are created from theRrdFileBackendFactory
class. This was the default backend used in all Rrd4j releases before 1.4.0 release. It usesjava.io.*
package andRandomAccessFile
class to store RRD data in files on the disk. URI scheme isfile
. -
SAFE
: objects of this class are created from theRrdSafeFileBackendFactory
class. It usesjava.io.*
package andRandomAccessFile
class to store RRD data in files on the disk. This backend is safe: it locks the underlying RRD file during update/fetch operations, and caches only static parts of a RRD file in memory. Therefore, this backend is safe to be used when RRD files should be shared between several JVMs at the same time. URI scheme isfile
. -
NIO
: objects of this class are created from theRrdNioBackendFactory
class. The backend usesjava.io.*
andjava.nio.*
classes (mappedByteBuffer
) to store RRD data in files on the disk. This is the default backend since 1.4.0 release. It can be quite heavy on memory, because of the memory mapping of files. URI scheme isfile
. -
MEMORY
: objects of this class are created from theRrdMemoryBackendFactory
class. This backend stores all data in memory. Once JVM exits, all data gets lost. The backend is extremely fast and memory hungry. URI scheme ismemory
. -
BERKELEY
: objects of this class are created from theRrdBerkeleyDbBackendFactory
class. It stores RRD data to ordinary disk files using Oracle Berkeley DB Java Edition. URI scheme isberkeley
. -
MONGODB
: objects of this class are created from theRrdMongoDBBackendFactory
class. It stores data in aDBCollection
from MongoDB. URI scheme ismongodb
.
Each backend factory is identified by the scheme in the URI it can handle. Constructors are provided in the RrdDb
class to create RrdDb
objects (RRD databases) backed with a specific backend.
Any implementation of RrdBackend
can be used directly when creating or opening a Rrdb. It's not mandatory to register it, unless if access by name is needed, like:
RrdBackendFactory factory = new CustomFactory(...);
RrdDb db = new RrdDb(path, factory);