java.lang.Object
org.rrd4j.core.RrdBackendFactory
org.rrd4j.core.RrdFileBackendFactory
org.rrd4j.core.RrdRandomAccessFileBackendFactory
org.rrd4j.core.RrdSafeFileBackendFactory
- All Implemented Interfaces:
Closeable, AutoCloseable
@RrdBackendAnnotation(name="SAFE", shouldValidateHeader=true, cachingAllowed=false) public class RrdSafeFileBackendFactoryextends RrdRandomAccessFileBackendFactory
Factory class which creates actual
RrdSafeFileBackend objects.Because of locking, each RrdDb can be open only once even from within the JVM. So usage of the RrdDbPool is mandatory with this backend.
Field Summary
Modifier and TypeFieldDescriptionprivate static longPause between lock attempts, in ms.private static longHow long a lock is retried, in ms.static final longDefault time between two consecutive file locking attempts.static final longDefault time (in milliseconds) this backend will wait for a file lock.private final longRetry period this factory hands to its backends.private final longWait time this factory hands to its backends.Fields inherited from class RrdBackendFactory
cachingAllowed, DEFAULTFACTORY, name, scheme, validateHeaderModifier and TypeFieldDescriptionprotected final booleanWhether this factory's backends may cache data in memory.static final StringDefault backend factory name.protected final StringStorage name this factory reports to RrdDb.protected final StringURI scheme this factory's storage URIs start with.protected final booleanWhether opened files must carry the RRD header.Constructor Summary
ConstructorsConstructorDescriptionGenerate a factory using the default system wide lock settingsRrdSafeFileBackendFactory(long lockWaitTime, long lockRetryPeriod) Generate a factory with custom lock settingsMethod Summary
Modifier and TypeMethodDescriptionstatic longReturns time between two consecutive file locking attempts.static longReturns time this backend will wait for a file lock.protected RrdBackendOpens the backend serving a storage path.static voidsetLockRetryPeriod(long lockRetryPeriod) Sets time between two consecutive file locking attempts.static voidsetLockWaitTime(long lockWaitTime) Sets time this backend will wait for a file lock.Methods inherited from class RrdFileBackendFactory
canStore, exists, getCanonicalUri, getPath, getUriModifier and TypeMethodDescriptionbooleanTests whether this factory recognises a storage URI.protected booleanDetermines if a storage with the given path already exists.getCanonicalUri(URI uri) Ensure that an URI is returned in a non-ambiguous way.Extract the local path from an URI.Transform an path in a valid URI for this backend.Methods inherited from class RrdBackendFactory
addActiveFactories, buildGenericUri, checkClosing, close, exists, findFactory, getActiveFactories, getBackend, getBackend, getDefaultFactory, getName, getRootUri, getScheme, resolve, setActiveFactories, shouldValidateHeader, shouldValidateHeaderModifier and TypeMethodDescriptionstatic voidaddActiveFactories(RrdBackendFactory... newFactories) Add factories to the list of active factories, i.e.static URIbuildGenericUri(String rrdpath) Try to detect an URI from a path.voidCheck that all phantom reference are indeed safely closed.voidclose()A generic close handle, default implementation does nothing.protected booleanDetermines if a storage with the given URI already exists.static RrdBackendFactoryfindFactory(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> Return the current active factories as a stream.(package private) RrdBackendgetBackend(RrdDb rrdDb, String path, boolean readOnly) Creates RrdBackend object for the given storage path.(package private) RrdBackendgetBackend(RrdDb rrdDb, URI uri, boolean readOnly) Creates RrdBackend object for the given storage path.static RrdBackendFactoryReturns the default backend factory.getName()Returns the name (primary ID) for the factory.protected URIBuilds the root URI for this factory's scheme.The URI scheme that selects this backend, used to build every RRD URI the factory hands out.protected URITry to match an URI against a root URI using a few rules: scheme must match if they are given.static voidsetActiveFactories(RrdBackendFactory... newFactories) Set the list of active factories, i.e.protected booleanshouldValidateHeader(String path) Determines if the header should be validated.protected booleanshouldValidateHeader(URI uri) Determines if the header should be validated.
Field Details
LOCK_WAIT_TIME
public static final long LOCK_WAIT_TIMEDefault time (in milliseconds) this backend will wait for a file lock.- See Also:
defaultLockWaitTime
private static long defaultLockWaitTimeHow long a lock is retried, in ms.LOCK_RETRY_PERIOD
public static final long LOCK_RETRY_PERIODDefault time between two consecutive file locking attempts.- See Also:
defaultLockRetryPeriod
private static long defaultLockRetryPeriodPause between lock attempts, in ms.lockWaitTime
private final long lockWaitTimeWait time this factory hands to its backends.lockRetryPeriod
private final long lockRetryPeriodRetry period this factory hands to its backends.
Constructor Details
RrdSafeFileBackendFactory
public RrdSafeFileBackendFactory()Generate a factory using the default system wide lock settingsRrdSafeFileBackendFactory
public RrdSafeFileBackendFactory(long lockWaitTime, long lockRetryPeriod) Generate a factory with custom lock settings- Parameters:
lockWaitTime- wait time in mslockRetryPeriod- retry period in ms
Method Details
open
Opens the backend serving a storage path.Creates RrdFileBackend object for the given file path.
Creates RrdSafeFileBackend object for the given file path.
- Overrides:
openin classRrdRandomAccessFileBackendFactory- Parameters:
path- the storage path, relative to this factory's root URIreadOnly- true to open the storage for reading only, false to allow writes- Returns:
- the backend that performs all I/O for the given storage path
- Throws:
IOException- if the storage cannot be opened
getLockWaitTime
public static long getLockWaitTime()Returns time this backend will wait for a file lock.- Returns:
- Time (in milliseconds) this backend will wait for a file lock.
setLockWaitTime
public static void setLockWaitTime(long lockWaitTime) Sets time this backend will wait for a file lock.- Parameters:
lockWaitTime- Maximum lock wait time (in milliseconds)
getLockRetryPeriod
public static long getLockRetryPeriod()Returns time between two consecutive file locking attempts.- Returns:
- Time (im milliseconds) between two consecutive file locking attempts.
setLockRetryPeriod
public static void setLockRetryPeriod(long lockRetryPeriod) Sets time between two consecutive file locking attempts.- Parameters:
lockRetryPeriod- time (in milliseconds) between two consecutive file locking attempts.