Class RrdDbPool
This class should be used to synchronize access to RRD files in a multithreaded environment. This class should be also used to prevent opening of too many RRD files at the same time (thus avoiding operating system limits).
It can also be used a factory for RrdDb, using a default backend factory.
In case of interruptions, it throws IllegalStateException.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intInitial capacity of the pool i.e.
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor for RrdDbPool.RrdDbPool(RrdBackendFactory defaultFactory) Constructor for RrdDbPool.
- 
Method SummaryModifier and TypeMethodDescriptionintReturns the maximum number of simultaneously open RRD.static RrdDbPoolCreates a single instance of the class on the first call, or returns already existing one.intgetOpenCount(String path) Returns the number of usage for a RRD.intgetOpenCount(URI uri) Returns the number of usage for a RRD.intgetOpenCount(RrdDb rrdDb) Returns the number of usage for a RRD.intReturns the number of open RRD.String[]Returns an array of open RRD.URI[]Returns an array of open RRD URI.java.util.stream.Stream<URI> Returns an stream open RRD.Wait until the pool is empty and return a lock that prevent any additions of new RrdDb references until it's released.voidDeprecated.A RrdDb remember if it was open directly or from a pool, no need to manage it manually any morerequestRrdDb(String path) Requests a RrdDb reference for the given RRD path.requestRrdDb(String path, String sourcePath) Requests a RrdDb reference for the given path.requestRrdDb(URI uri) Requests a RrdDb reference for the given RRD URI.requestRrdDb(URI uri, String sourcePath) Requests a RrdDb reference for the given URI.(package private) RrdDbrequestRrdDb(URI uri, RrdBackendFactory factory) (package private) RrdDbrequestRrdDb(URI uri, RrdBackendFactory factory, DataImporter importer) requestRrdDb(RrdDef rrdDef) Requests a RrdDb reference for the given RRD definition object.(package private) RrdDbrequestRrdDb(RrdDef rrdDef, RrdBackendFactory factory) voidsetCapacity(int newCapacity) Sets the maximum number of simultaneously open RRD.voidsetDefaultFactory(RrdBackendFactory defaultFactory) Deprecated.the pool is no longer a singleton, create a new pool instead of changing it.
- 
Field Details- 
INITIAL_CAPACITYpublic static final int INITIAL_CAPACITYInitial capacity of the pool i.e. maximum number of simultaneously open RRD. The pool will never open too many RRD at the same time.- See Also:
 
 
- 
- 
Constructor Details- 
RrdDbPoolpublic RrdDbPool()Constructor for RrdDbPool. It will use the default backend factory.- Since:
- 3.5
 
- 
RrdDbPoolConstructor for RrdDbPool.- Parameters:
- defaultFactory- the default factory used when given a simple path of a RRD.
- Since:
- 3.6
 
 
- 
- 
Method Details- 
getInstanceCreates a single instance of the class on the first call, or returns already existing one. Uses Initialization On Demand Holder idiom.- Returns:
- Single instance of this class
 
- 
getOpenFileCountpublic int getOpenFileCount()Returns the number of open RRD.- Returns:
- Number of currently open RRD held in the pool.
 
- 
getOpenUriReturns an array of open RRD URI.- Returns:
- Array with URIto open RRD held in the pool.
 
- 
getOpenUriStreamReturns an stream open RRD.- Returns:
- Stream with canonical URI to open RRD path held in the pool.
- Since:
- 3.7
 
- 
getOpenFilesReturns an array of open RRD.- Returns:
- Array with canonical path to open RRD path held in the pool.
 
- 
releaseDeprecated.A RrdDb remember if it was open directly or from a pool, no need to manage it manually any moreReleases RrdDb reference previously obtained from the pool. When a reference is released, its usage count is decremented by one. If usage count drops to zero, the underlying RRD will be closed.- Parameters:
- rrdDb- RrdDb reference to be returned to the pool
- Throws:
- IOException- Thrown in case of I/O error
- IllegalStateException- if the thread was interrupted
 
- 
requestRrdDbRequests a RrdDb reference for the given RRD path. - If the RRD is already open, previously returned RrdDb reference will be returned. Its usage count will be incremented by one.
- If the RRD is not already open and the number of already open RRD is less than
 getCapacity(), it will be opened and a new RrdDb reference will be returned. If the RRD is not already open and the number of already open RRD is equal togetCapacity(), the method blocks until some RRD are closed.
 The path is transformed to an URI using the default factory defined at the creation of the pool. - Parameters:
- path- Path to existing RRD.
- Returns:
- reference for the given RRD.
- Throws:
- IOException- Thrown in case of I/O error
 
- 
requestRrdDbRequests a RrdDb reference for the given RRD URI. - If the RRD is already open, previously returned RrdDb reference will be returned. Its usage count will be incremented by one.
- If the RRD is not already open and the number of already open RRD is less than
 getCapacity(), it will be opened and a new RrdDb reference will be returned. If the RRD is not already open and the number of already open RRD is equal togetCapacity(), the method blocks until some RRD are closed.
 If the default backend factory for the pool can handle this URI, it will be used, or else RrdBackendFactory.findFactory(URI)will be used to find the backend factory used.- Parameters:
- uri-- URIto existing RRD file
- Returns:
- reference for the give RRD file
- Throws:
- IOException- Thrown in case of I/O error
 
- 
requestRrdDb- Throws:
- IOException
 
- 
requestRrdDb- Throws:
- IOException
 
- 
requestRrdDb- Throws:
- IOException
 
- 
requestRrdDbRequests a RrdDb reference for the given RRD definition object. - If the RRD with the path specified in the RrdDef object is already open, the method blocks until the file is closed.
- If the RRD is not already open and the number of already open RRD is less than
 getCapacity(), a new RRD will be created and it's RrdDb reference will be returned. If the RRD is not already open and the number of already open RRD is equal togetCapacity(), the method blocks until some RrdDb references are closed.
 If the factory defined when creating the pool can handle the URI, it will be used, or else RrdBackendFactory.findFactory(URI)will be used.- Parameters:
- rrdDef- Definition of the RRD file to be created.
- Returns:
- Reference to the newly created RRD file.
- Throws:
- IOException- Thrown in case of I/O error
- IllegalStateException- if the thread was interrupted
 
- 
requestRrdDbRequests a RrdDb reference for the given path. The RRD will be created from external data (from XML dump or RRDTool's binary RRD file). - If the RRD with the path specified is already open, the method blocks until the file is closed.
- If the RRD is not already open and the number of already open RRD is less than
 getCapacity(), a new RRD will be created and it's RrdDb reference will be returned. If the RRD is not already open and the number of already open RRD is equal togetCapacity(), the method blocks until some RrdDb references are closed.
 The path is transformed to an URI using the default factory of the pool. - Parameters:
- path- Path to the RRD that should be created.
- sourcePath- Path to external data which is to be converted to Rrd4j's native RRD file format.
- Returns:
- Reference to the newly created RRD.
- Throws:
- IOException- Thrown in case of I/O error
- IllegalStateException- if the thread was interrupted
 
- 
requestRrdDbRequests a RrdDb reference for the given URI. The RRD will be created from external data (from XML dump or RRDTool's binary RRD file). - If the RRD with the URI specified is already open, the method blocks until the file is closed.
- If the RRD is not already open and the number of already open RRD is less than
 getCapacity(), a new RRD will be created and it's RrdDb reference will be returned. If the RRD is not already open and the number of already open RRD is equal togetCapacity(), the method blocks until some RrdDb references are closed.
 RrdBackendFactory.findFactory(URI)will be used to choose the factory.- Parameters:
- uri- URI to the RRD that should be created
- sourcePath- Path to external data which is to be converted to Rrd4j's native RRD file format
- Returns:
- Reference to the newly created RRD
- Throws:
- IOException- Thrown in case of I/O error
- IllegalStateException- if the thread was interrupted
 
- 
setDefaultFactoryDeprecated.the pool is no longer a singleton, create a new pool instead of changing it.Sets the default factory to use when obtaining RrdDb reference from simple path and not URI.- Parameters:
- defaultFactory- The factory to use.
- Throws:
- IllegalStateException- if called while the pool is not empty or the thread was interrupted
- IllegalStateException- if the thread was interrupted
 
- 
setCapacitypublic void setCapacity(int newCapacity) Sets the maximum number of simultaneously open RRD.- Parameters:
- newCapacity- Maximum number of simultaneously open RRD.
- Throws:
- IllegalStateException- if called while the pool is not empty or the thread was interrupted.
 
- 
getCapacitypublic int getCapacity()Returns the maximum number of simultaneously open RRD.- Returns:
- maximum number of simultaneously open RRD
- Throws:
- IllegalStateException- if the thread was interrupted
 
- 
getOpenCountReturns the number of usage for a RRD.- Parameters:
- rrdDb- RrdDb reference for which informations is needed.
- Returns:
- the number of request for this RRD.
- Throws:
- IllegalStateException- if the thread was interrupted
 
- 
getOpenCountReturns the number of usage for a RRD.The path is transformed to an URI using the default factory. - Parameters:
- path- RRD's path for which informations is needed.
- Returns:
- the number of request for this RRD.
- Throws:
- IllegalStateException- if the thread was interrupted
 
- 
getOpenCountReturns the number of usage for a RRD.- Parameters:
- uri- RRD's URI for which informations is needed.
- Returns:
- the number of request for this RRD.
- Throws:
- IllegalStateException- if the thread was interrupted
 
- 
lockEmptyWait until the pool is empty and return a lock that prevent any additions of new RrdDb references until it's released.- Parameters:
- timeout- the time to wait for the write lock
- unit- the time unit of the timeout argument
- Returns:
- a lock to release when operations on this pool are finished.
- Throws:
- InterruptedException- if interrupted whole waiting for the lock
- Since:
- 3.7
 
 
-