java.lang.Object
org.rrd4j.core.RrdBackendFactory
org.rrd4j.core.RrdFileBackendFactory
org.rrd4j.core.RrdNioBackendFactory
- All Implemented Interfaces:
Closeable, AutoCloseable
@RrdBackendAnnotation(name="NIO", shouldValidateHeader=true) public class RrdNioBackendFactoryextends RrdFileBackendFactory
Factory class which creates actual
RrdNioBackend objects. This is the default factory since 1.4.0 version.Managing the thread pool
Each RrdNioBackendFactory is optionally backed by a RrdSyncThreadPool, which it uses to sync the memory-mapped files to disk. In order to avoid having these threads live longer than they should, it is recommended that clients create and destroy thread pools at the appropriate time in their application's life time. Failure to manage thread pools appropriately may lead to the thread pool hanging around longer than necessary, which in turn may cause memory leaks.
if sync period is negative, no sync thread will be launched
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThe shared pool that flushes writes to disk.Field Summary
Modifier and TypeFieldDescriptionprivate static ThreadFactoryFactory naming the sync pool's threads.static final intThe core pool size for the sync executor.static final intPeriod in seconds between consecutive synchronizations when sync-mode is set to SYNC_BACKGROUND.private static intWrites between forced syncs, for factories that name none.private static intThreads in the shared sync pool.private final intWrites between forced syncs for this factory's backends.private RrdSyncThreadPoolThe thread pool to pass to newly-created RrdNioBackend instances.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
ConstructorsConstructorDescriptionCreates a new RrdNioBackendFactory with default settings.RrdNioBackendFactory(int syncPeriod) Creates a new RrdNioBackendFactory, using a defaultRrdSyncThreadPool.RrdNioBackendFactory(int syncPeriod, int syncPoolSize) Creates a new RrdNioBackendFactory.RrdNioBackendFactory(int syncPeriod, ScheduledExecutorService syncThreadPool) Creates a new RrdNioBackendFactory.RrdNioBackendFactory(int syncPeriod, RrdSyncThreadPool syncThreadPool) Creates a new RrdNioBackendFactory.Method Summary
Modifier and TypeMethodDescriptionvoidclose()A generic close handle, default implementation does nothing.static intReturns time between two consecutive background synchronizations.static intReturns the number of synchronizing threads.Return the pool that periodically flushes dirty buffers to disk.protected RrdBackend/** /** Opens the backend serving a storage path.static voidsetSyncPeriod(int syncPeriod) Sets time between consecutive background synchronizations.static voidsetSyncPoolSize(int syncPoolSize) Sets the number of synchronizing threads.static voidsetThreadFactory(ThreadFactory factory) Set a custom thread factory for the default sync pool.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, 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.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
DEFAULT_SYNC_PERIOD
public static final int DEFAULT_SYNC_PERIODPeriod in seconds between consecutive synchronizations when sync-mode is set to SYNC_BACKGROUND. By default in-memory cache will be transferred to the disc every 300 seconds (5 minutes). Default value can be changed viasetSyncPeriod(int)method.- See Also:
defaultSyncPeriod
private static int defaultSyncPeriodWrites between forced syncs, for factories that name none.DEFAULT_SYNC_CORE_POOL_SIZE
public static final int DEFAULT_SYNC_CORE_POOL_SIZEThe core pool size for the sync executor. Defaults to 6.- See Also:
defaultSyncPoolSize
private static int defaultSyncPoolSizeThreads in the shared sync pool._threadFactory
Factory naming the sync pool's threads.syncPeriod
private final int syncPeriodWrites between forced syncs for this factory's backends.syncThreadPool
The thread pool to pass to newly-created RrdNioBackend instances.
Constructor Details
RrdNioBackendFactory
public RrdNioBackendFactory()Creates a new RrdNioBackendFactory with default settings.RrdNioBackendFactory
public RrdNioBackendFactory(int syncPeriod) Creates a new RrdNioBackendFactory, using a defaultRrdSyncThreadPool.- Parameters:
syncPeriod- the sync period, in seconds. If negative or 0, sync threads are disabled.
RrdNioBackendFactory
public RrdNioBackendFactory(int syncPeriod, int syncPoolSize) Creates a new RrdNioBackendFactory.- Parameters:
syncPeriod- the sync period, in seconds.syncPoolSize- The number of threads to use to sync the mapped file to disk, if negative or 0, sync threads are disabled.
RrdNioBackendFactory
Creates a new RrdNioBackendFactory.- Parameters:
syncPeriod- the sync period, in seconds.syncThreadPool- If null, disable background sync threads
RrdNioBackendFactory
Creates a new RrdNioBackendFactory.- Parameters:
syncPeriod- the sync period, in seconds.syncThreadPool- If null, disable background sync threads
Method Details
getSyncPeriod
public static int getSyncPeriod()Returns time between two consecutive background synchronizations. If not changed viasetSyncPeriod(int)method call, defaults toDEFAULT_SYNC_PERIOD. SeesetSyncPeriod(int)for more information.- Returns:
- Time in seconds between consecutive background synchronizations.
setSyncPeriod
public static void setSyncPeriod(int syncPeriod) Sets time between consecutive background synchronizations. If negative, it will disabling syncing for all NIO backend factory.- Parameters:
syncPeriod- Time in seconds between consecutive background synchronizations.
getSyncPoolSize
public static int getSyncPoolSize()Returns the number of synchronizing threads. If not changed viasetSyncPoolSize(int)method call, defaults toDEFAULT_SYNC_CORE_POOL_SIZE. SeesetSyncPoolSize(int)for more information.- Returns:
- Number of synchronizing threads.
setSyncPoolSize
public static void setSyncPoolSize(int syncPoolSize) Sets the number of synchronizing threads. It must be set before the first use of this factory. It will not have any effect afterward.- Parameters:
syncPoolSize- Number of synchronizing threads.
open
/** /** Opens the backend serving a storage path.Creates RrdNioBackend object for the given file path.
- Specified by:
openin classRrdBackendFactory- 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
getSyncThreadPool
Return the pool that periodically flushes dirty buffers to disk.- Returns:
- The
RrdSyncThreadPoolor null if syncing is disabled
close
public void close()Description copied from class:RrdBackendFactoryA generic close handle, default implementation does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classRrdBackendFactory
setThreadFactory
Set a custom thread factory for the default sync pool. Must be called before the first use of the factory, otherwise the default thread naming is used.- Parameters:
factory- may be null to reset to default