public abstract class RrdBackendFactory extends Object implements Closeable
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:
RrdRandomAccessFileBackend
: objects of this class are created from the
RrdRandomAccessFileBackendFactory
class. This was the default backend used in all
Rrd4j 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 the
RrdSafeFileBackendFactory
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 the
RrdNioBackendFactory
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 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.
Each backend factory used to be identified by its name
. Constructors
are provided in the RrdDb
class to create RrdDb objects (RRD databases)
backed with a specific backend.
A more generic management was added in version 3.2 that allows multiple instances of a backend to be used. Each backend can
manage custom URL. They are tried in the declared order by the setActiveFactories(RrdBackendFactory...)
or
addFactories(RrdBackendFactory...)
and the method canStore(URI)
return true when it can manage the given
URI. Using setActiveFactories(RrdBackendFactory...)
with new created instance is the preferred way to manage factories, as
it provides a much precise control of creation and end of life of factories.
Since 3.4, using only setActiveFactories(RrdBackendFactory...)
and addActiveFactories(RrdBackendFactory...)
will not register any
named backend at all. getDefaultFactory()
will return the first active factory. All methods using named backend and the registry of factory were deprecated.
For default implementation, the path is separated in a root URI prefix and the path components. The root URI can be used to identify different name spaces or just be `/`.
See javadoc for RrdBackend
to find out how to create your custom backends.
Modifier and Type | Field and Description |
---|---|
protected boolean |
cachingAllowed |
static String |
DEFAULTFACTORY
The default factory type.
|
protected String |
name |
protected String |
scheme |
protected boolean |
validateHeader |
Modifier | Constructor and Description |
---|---|
protected |
RrdBackendFactory() |
Modifier and Type | Method and Description |
---|---|
static void |
addActiveFactories(RrdBackendFactory... newFactories)
Add factories to the list of active factories, i.e.
|
static void |
addFactories(RrdBackendFactory... newFactories)
Deprecated.
Uses
addActiveFactories(RrdBackendFactory...) instead. |
static URI |
buildGenericUri(String rrdpath)
Try to detect an URI from a path.
|
boolean |
canStore(URI uri) |
void |
checkClosing()
Check that all phantom reference are indeed safely closed.
|
void |
close()
A generic close handle, default implementation does nothing.
|
protected abstract boolean |
exists(String path)
Determines if a storage with the given path already exists.
|
protected boolean |
exists(URI uri)
Determines if a storage with the given URI already exists.
|
static RrdBackendFactory |
findFactory(URI uri)
For a given URI, try to find a factory that can manage it in the list of active factories.
|
static java.util.stream.Stream<RrdBackendFactory> |
getActiveFactories()
Return the current active factories as a stream.
|
(package private) RrdBackend |
getBackend(RrdDb rrdDb,
String path,
boolean readOnly)
Creates RrdBackend object for the given storage path.
|
(package private) RrdBackend |
getBackend(RrdDb rrdDb,
URI uri,
boolean readOnly)
Creates RrdBackend object for the given storage path.
|
URI |
getCanonicalUri(URI uri)
Ensure that an URI is returned in a non-ambiguous way.
|
static RrdBackendFactory |
getDefaultFactory()
Returns the default backend factory.
|
static RrdBackendFactory |
getFactory(String name)
Deprecated.
Uses active factory instead
|
String |
getName()
Returns the name (primary ID) for the factory.
|
String |
getPath(URI uri)
Extract the local path from an URI.
|
protected URI |
getRootUri() |
String |
getScheme() |
URI |
getUri(String path)
Transform an path in a valid URI for this backend.
|
protected abstract RrdBackend |
open(String path,
boolean readOnly) |
static void |
registerAndSetAsDefaultFactory(RrdBackendFactory factory)
Deprecated.
Uses
setActiveFactories(RrdBackendFactory...) instead. |
static void |
registerFactory(RrdBackendFactory factory)
Deprecated.
Uses active factory instead
|
protected URI |
resolve(URI rootUri,
URI uri,
boolean relative)
Try to match an URI against a root URI using a few rules:
scheme must match if they are given.
|
static void |
setActiveFactories(RrdBackendFactory... newFactories)
Set the list of active factories, i.e.
|
static void |
setDefaultFactory(String factoryName)
Deprecated.
Uses active factory instead
|
protected boolean |
shouldValidateHeader(String path)
Determines if the header should be validated.
|
protected boolean |
shouldValidateHeader(URI uri)
Determines if the header should be validated.
|
public static final String DEFAULTFACTORY
protected final String name
protected final boolean cachingAllowed
protected final String scheme
protected final boolean validateHeader
@Deprecated public static RrdBackendFactory getFactory(String name)
name
- Backend factory name. Initially supported names are:
@Deprecated public static void registerFactory(RrdBackendFactory factory)
factory
- Factory to be registered@Deprecated public static void registerAndSetAsDefaultFactory(RrdBackendFactory factory)
setActiveFactories(RrdBackendFactory...)
instead.factory
- Factory to be registered and set as defaultpublic static RrdBackendFactory getDefaultFactory()
RrdDb
objects if no factory is specified in the RrdDb constructor.@Deprecated public static void setDefaultFactory(String factoryName)
It also clear the list of actives factories and set it to the default factory.
factoryName
- Name of the default factory..public static void setActiveFactories(RrdBackendFactory... newFactories)
newFactories
- the new active factories.public static java.util.stream.Stream<RrdBackendFactory> getActiveFactories()
@Deprecated public static void addFactories(RrdBackendFactory... newFactories)
addActiveFactories(RrdBackendFactory...)
instead.newFactories
- active factories to add.public static void addActiveFactories(RrdBackendFactory... newFactories)
newFactories
- active factories to add.public static RrdBackendFactory findFactory(URI uri)
uri
- URI to try.RrdBackendFactory
that can manage that URI.IllegalArgumentException
- when no matching factory is found.public static URI buildGenericUri(String rrdpath)
rrdpath
- a file URI that can be a Windows pathpublic void checkClosing()
public String getScheme()
protected URI getRootUri()
public boolean canStore(URI uri)
protected URI resolve(URI rootUri, URI uri, boolean relative)
rootUri
- the URI to match againsturi
- an URI that the current backend can handle.relative
- if true, return an URI relative to the rootUri
public URI getCanonicalUri(URI uri)
uri
- a valid URI for this backend.public URI getUri(String path)
path
- a path local to the current backend.public String getPath(URI uri)
uri
- The URI to parse.protected abstract RrdBackend open(String path, boolean readOnly) throws IOException
IOException
RrdBackend getBackend(RrdDb rrdDb, String path, boolean readOnly) throws IOException
path
- Storage pathreadOnly
- True, if the storage should be accessed in read/only mode.
False otherwise.IOException
- Thrown in case of I/O error.RrdBackend getBackend(RrdDb rrdDb, URI uri, boolean readOnly) throws IOException
rrdDb
- uri
- Storage urireadOnly
- True, if the storage should be accessed in read/only mode.
False otherwise.IOException
- Thrown in case of I/O error.protected abstract boolean exists(String path) throws IOException
path
- Storage pathIOException
- in case of I/O error.protected boolean exists(URI uri) throws IOException
uri
- Storage URI.IOException
- in case of I/O error.protected boolean shouldValidateHeader(String path)
path
- Storage pathprotected boolean shouldValidateHeader(URI uri)
uri
- Storage URIpublic String getName()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
- if the close fails