Package org.rrd4j.core
Class RrdNioBackendFactory
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 RrdNioBackendFactory
extends 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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic 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.Fields inherited from class org.rrd4j.core.RrdBackendFactory
cachingAllowed, DEFAULTFACTORY, name, scheme, validateHeader -
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.protected RrdBackendCreates RrdNioBackend object for the given file path.static voidsetSyncPeriod(int syncPeriod) Sets time between consecutive background synchronizations.static voidsetSyncPoolSize(int syncPoolSize) Sets the number of synchronizing threads.voidsetSyncThreadPool(ScheduledExecutorService syncThreadPool) Deprecated.Create a custom instance insteadvoidsetSyncThreadPool(RrdSyncThreadPool syncThreadPool) Deprecated.Create a custom instance insteadMethods inherited from class org.rrd4j.core.RrdFileBackendFactory
canStore, exists, getCanonicalUri, getPath, getUriMethods inherited from class org.rrd4j.core.RrdBackendFactory
addActiveFactories, addFactories, buildGenericUri, checkClosing, exists, findFactory, getActiveFactories, getBackend, getBackend, getDefaultFactory, getFactory, getName, getRootUri, getScheme, registerAndSetAsDefaultFactory, registerFactory, resolve, setActiveFactories, setDefaultFactory, shouldValidateHeader, shouldValidateHeader
-
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:
-
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:
-
-
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.
-
setSyncThreadPool
Deprecated.Create a custom instance insteadSetter for the field
syncThreadPool.- Parameters:
syncThreadPool- the RrdSyncThreadPool to use to sync the memory-mapped files.
-
setSyncThreadPool
Deprecated.Create a custom instance insteadSetter for the field
syncThreadPool.- Parameters:
syncThreadPool- the ScheduledExecutorService that will back the RrdSyncThreadPool used to sync the memory-mapped files.
-
open
Creates RrdNioBackend object for the given file path.- Specified by:
openin classRrdBackendFactory- Throws:
IOException
-
getSyncThreadPool
- 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
-