Package org.jrobin.core
Class RrdBackendFactory
- java.lang.Object
-
- org.jrobin.core.RrdBackendFactory
-
- Direct Known Subclasses:
RrdFileBackendFactory
,RrdJRobin14FileBackendFactory
,RrdMemoryBackendFactory
public abstract class RrdBackendFactory extends Object
Base (abstract) backend factory class which holds references to all concrete backend factories and defines abstract methods which must be implemented in all concrete factory implementations.Factory classes are used to create concrete
RrdBackend
implementations. Each factory creates unlimited number of specific backend objects.JRobin supports four different backend types (backend factories) out of the box:
RrdFileBackend
: objects of this class are created from theRrdFileBackendFactory
class. This was the default backend used in all JRobin releases before 1.4.0 release. It uses java.io.* package and RandomAccessFile class to store RRD data in files on the disk.RrdSafeFileBackend
: objects of this class are created from theRrdSafeFileBackendFactory
class. It uses java.io.* package and RandomAccessFile 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. However, this backend is *slow* since it does not use fast java.nio.* package (it's still based on the RandomAccessFile class).RrdNioBackend
: objects of this class are created from theRrdNioBackendFactory
class. The backend uses java.io.* and java.nio.* classes (mapped ByteBuffer) to store RRD data in files on the disk. This is the default backend since 1.4.0 release.RrdMemoryBackend
: 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.
Each backend factory is identifed by its
name
. Constructors are provided in theRrdDb
class to create RrdDb objects (RRD databases) backed with a specific backend.See javadoc for
RrdBackend
to find out how to create your custom backends.
-
-
Constructor Summary
Constructors Constructor Description RrdBackendFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
exists(String path)
Method to determine if a storage with the given path already exists.static RrdBackendFactory
getDefaultFactory()
Returns the defaul backend factory.static RrdBackendFactory
getFactory(String name)
Returns backend factory for the given backend factory name.abstract String
getFactoryName()
Returns the name (primary ID) for the factory.static boolean
isInstanceCreated()
Whether or not the RRD backend has created an instance yet.protected abstract RrdBackend
open(String path, boolean readOnly)
Creates RrdBackend object for the given storage path.static void
registerAndSetAsDefaultFactory(RrdBackendFactory factory)
Registers new (custom) backend factory within the JRobin framework and sets this factory as the default.static void
registerFactory(RrdBackendFactory factory)
Registers new (custom) backend factory within the JRobin framework.static void
setDefaultFactory(String factoryName)
Replaces the default backend factory with a new one.String
toString()
-
-
-
Method Detail
-
getFactory
public static RrdBackendFactory getFactory(String name) throws RrdException
Returns backend factory for the given backend factory name.- Parameters:
name
- Backend factory name. Initially supported names are:- FILE: Default factory which creates backends based on the java.io.* package. RRD data is stored in files on the disk
- SAFE: Default factory which creates backends based on the java.io.* package. RRD data is stored in files on the disk. This backend is "safe". Being safe means that RRD files can be safely shared between several JVM's.
- NIO: Factory which creates backends based on the java.nio.* package. RRD data is stored in files on the disk
- MEMORY: Factory which creates memory-oriented backends. RRD data is stored in memory, it gets lost as soon as JVM exits.
- Returns:
- Backend factory for the given factory name
- Throws:
RrdException
- Thrown if no factory with the given name is available.
-
registerFactory
public static void registerFactory(RrdBackendFactory factory) throws RrdException
Registers new (custom) backend factory within the JRobin framework.- Parameters:
factory
- Factory to be registered- Throws:
RrdException
- Thrown if the name of the specified factory is already used.
-
registerAndSetAsDefaultFactory
public static void registerAndSetAsDefaultFactory(RrdBackendFactory factory) throws RrdException
Registers new (custom) backend factory within the JRobin framework and sets this factory as the default.- Parameters:
factory
- Factory to be registered and set as default- Throws:
RrdException
- Thrown if the name of the specified factory is already used.
-
getDefaultFactory
public static RrdBackendFactory getDefaultFactory()
Returns the defaul backend factory. This factory is used to constructRrdDb
objects if no factory is specified in the RrdDb constructor.- Returns:
- Default backend factory.
-
setDefaultFactory
public static void setDefaultFactory(String factoryName) throws RrdException
Replaces the default backend factory with a new one. This method must be called before the first RRD gets created.- Parameters:
factoryName
- Name of the default factory. Out of the box, JRobin supports four different RRD backends: "FILE" (java.io.* based), "SAFE" (java.io.* based - use this backend if RRD files may be accessed from several JVMs at the same time), "NIO" (java.nio.* based) and "MEMORY" (byte[] based).- Throws:
RrdException
- Thrown if invalid factory name is supplied or not called before the first RRD is created.
-
isInstanceCreated
public static boolean isInstanceCreated()
Whether or not the RRD backend has created an instance yet.- Returns:
- True if the backend instance is created, false if not.
-
open
protected abstract RrdBackend open(String path, boolean readOnly) throws IOException
Creates RrdBackend object for the given storage path.- Parameters:
path
- Storage pathreadOnly
- True, if the storage should be accessed in read/only mode. False otherwise.- Returns:
- Backend object which handles all I/O operations for the given storage path
- Throws:
IOException
- Thrown in case of I/O error.
-
exists
protected abstract boolean exists(String path) throws IOException
Method to determine if a storage with the given path already exists.- Parameters:
path
- Storage path- Returns:
- True, if such storage exists, false otherwise.
- Throws:
IOException
- Thrown in case of I/O error.
-
getFactoryName
public abstract String getFactoryName()
Returns the name (primary ID) for the factory.- Returns:
- Name of the factory.
-
-