Class RrdDbPool
- java.lang.Object
-
- org.rrd4j.core.RrdDbPool
-
public class RrdDbPool extends Object
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 should not be called directly. Use
RrdDb.Builder.usePool()
instead.
-
-
Field Summary
Fields Modifier and Type Field Description static int
INITIAL_CAPACITY
Initial capacity of the pool i.e.
-
Constructor Summary
Constructors Constructor Description RrdDbPool()
Constructor for RrdDbPool.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
getCapacity()
Returns the maximum number of simultaneously open RRD files.static RrdDbPool
getInstance()
Creates a single instance of the class on the first call, or returns already existing one.int
getOpenCount(String path)
Returns the number of usage for a RRD.int
getOpenCount(URI uri)
Returns the number of usage for a RRD.int
getOpenCount(RrdDb rrdDb)
Returns the number of usage for a RRD.int
getOpenFileCount()
Returns the number of open RRD files.String[]
getOpenFiles()
Returns an array of open file path.URI[]
getOpenUri()
Returns an array of open file URI.void
release(RrdDb rrdDb)
Deprecated.a pool remember if it was open directly or from the pool, no need to manage it manually any moreRrdDb
requestRrdDb(String path)
Deprecated.Use theRrdDb.Builder
instead.RrdDb
requestRrdDb(String path, String sourcePath)
Deprecated.Use theRrdDb.Builder
instead.RrdDb
requestRrdDb(URI uri)
Deprecated.Use theRrdDb.Builder
instead.RrdDb
requestRrdDb(URI uri, String sourcePath)
Deprecated.Use theRrdDb.Builder
instead.(package private) RrdDb
requestRrdDb(URI uri, RrdBackendFactory factory)
(package private) RrdDb
requestRrdDb(URI uri, RrdBackendFactory backend, DataImporter importer)
RrdDb
requestRrdDb(RrdDef rrdDef)
Deprecated.Use theRrdDb.Builder
instead.(package private) RrdDb
requestRrdDb(RrdDef rrdDef, RrdBackendFactory backend)
void
setCapacity(int newCapacity)
Sets the maximum number of simultaneously open RRD files.
-
-
-
Field Detail
-
INITIAL_CAPACITY
public static final int INITIAL_CAPACITY
Initial capacity of the pool i.e. maximum number of simultaneously open RRD files. The pool will never open too many RRD files at the same time.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static RrdDbPool getInstance()
Creates 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
- Throws:
RuntimeException
- Thrown if the default RRD backend is not derived from theRrdFileBackendFactory
-
getOpenFileCount
public int getOpenFileCount()
Returns the number of open RRD files.- Returns:
- Number of currently open RRD files held in the pool.
-
getOpenUri
public URI[] getOpenUri()
Returns an array of open file URI.- Returns:
- Array with
URI
to open RRD files held in the pool.
-
getOpenFiles
public String[] getOpenFiles()
Returns an array of open file path.- Returns:
- Array with canonical path to open RRD files held in the pool.
-
release
@Deprecated public void release(RrdDb rrdDb) throws IOException
Deprecated.a pool remember if it was open directly or from the 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 file will be closed.- Parameters:
rrdDb
- RrdDb reference to be returned to the pool- Throws:
IOException
- Thrown in case of I/O error
-
requestRrdDb
@Deprecated public RrdDb requestRrdDb(String path) throws IOException
Deprecated.Use theRrdDb.Builder
instead.Requests a RrdDb reference for the given RRD file path.
- If the file is already open, previously returned RrdDb reference will be returned. Its usage count will be incremented by one.
- If the file is not already open and the number of already open RRD files is less than
INITIAL_CAPACITY
, the file will be open and a new RrdDb reference will be returned. If the file is not already open and the number of already open RRD files is equal toINITIAL_CAPACITY
, the method blocks until some RRD file is closed.
The path is transformed internally to URI using the default factory, that is the reference that will be used elsewhere.
- Parameters:
path
- Path to existing RRD file- Returns:
- reference for the give RRD file
- Throws:
IOException
- Thrown in case of I/O error
-
requestRrdDb
@Deprecated public RrdDb requestRrdDb(URI uri) throws IOException
Deprecated.Use theRrdDb.Builder
instead.Requests a RrdDb reference for the given RRD file path.
- If the file is already open, previously returned RrdDb reference will be returned. Its usage count will be incremented by one.
- If the file is not already open and the number of already open RRD files is less than
INITIAL_CAPACITY
, the file will be open and a new RrdDb reference will be returned. If the file is not already open and the number of already open RRD files is equal toINITIAL_CAPACITY
, the method blocks until some RRD file is closed.
- Parameters:
uri
-URI
to existing RRD file- Returns:
- reference for the give RRD file
- Throws:
IOException
- Thrown in case of I/O error
-
requestRrdDb
RrdDb requestRrdDb(URI uri, RrdBackendFactory factory) throws IOException
- Throws:
IOException
-
requestRrdDb
@Deprecated public RrdDb requestRrdDb(RrdDef rrdDef) throws IOException
Deprecated.Use theRrdDb.Builder
instead.Requests a RrdDb reference for the given RRD file definition object.
- If the file with the path specified in the RrdDef object is already open, the method blocks until the file is closed.
- If the file is not already open and the number of already open RRD files is less than
INITIAL_CAPACITY
, a new RRD file will be created and a its RrdDb reference will be returned. If the file is not already open and the number of already open RRD files is equal toINITIAL_CAPACITY
, the method blocks until some RRD file is closed.
- 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
-
requestRrdDb
RrdDb requestRrdDb(RrdDef rrdDef, RrdBackendFactory backend) throws IOException
- Throws:
IOException
-
requestRrdDb
@Deprecated public RrdDb requestRrdDb(String path, String sourcePath) throws IOException
Deprecated.Use theRrdDb.Builder
instead.Requests a RrdDb reference for the given path. The file will be created from external data (from XML dump or RRDTool's binary RRD file).
- If the file with the path specified is already open, the method blocks until the file is closed.
- If the file is not already open and the number of already open RRD files is less than
INITIAL_CAPACITY
, a new RRD file will be created and a its RrdDb reference will be returned. If the file is not already open and the number of already open RRD files is equal toINITIAL_CAPACITY
, the method blocks until some RRD file is closed.
The path is transformed internally to URI using the default factory, that is the reference that will be used elsewhere.
- Parameters:
path
- Path to RRD file which should be createdsourcePath
- Path to external data which is to be converted to Rrd4j's native RRD file format- Returns:
- Reference to the newly created RRD file
- Throws:
IOException
- Thrown in case of I/O error
-
requestRrdDb
@Deprecated public RrdDb requestRrdDb(URI uri, String sourcePath) throws IOException
Deprecated.Use theRrdDb.Builder
instead.Requests a RrdDb reference for the given path. The file will be created from external data (from XML dump or RRDTool's binary RRD file).
- If the file with the path specified is already open, the method blocks until the file is closed.
- If the file is not already open and the number of already open RRD files is less than
INITIAL_CAPACITY
, a new RRD file will be created and a its RrdDb reference will be returned. If the file is not already open and the number of already open RRD files is equal toINITIAL_CAPACITY
, the method blocks until some RRD file is closed.
The path is transformed internally to URI using the default factory, that is the reference that will be used elsewhere.
- Parameters:
uri
- Path to RRD file which should be createdsourcePath
- Path to external data which is to be converted to Rrd4j's native RRD file format- Returns:
- Reference to the newly created RRD file
- Throws:
IOException
- Thrown in case of I/O error
-
requestRrdDb
RrdDb requestRrdDb(URI uri, RrdBackendFactory backend, DataImporter importer) throws IOException
- Throws:
IOException
-
setCapacity
public void setCapacity(int newCapacity)
Sets the maximum number of simultaneously open RRD files.- Parameters:
newCapacity
- Maximum number of simultaneously open RRD files.
-
getCapacity
public int getCapacity()
Returns the maximum number of simultaneously open RRD files.- Returns:
- maximum number of simultaneously open RRD files
-
getOpenCount
public int getOpenCount(RrdDb rrdDb) throws IOException
Returns 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:
IOException
- if any.
-
getOpenCount
public int getOpenCount(String path) throws IOException
Returns the number of usage for a RRD.- Parameters:
path
- RRD's path for which informations is needed.- Returns:
- the number of request for this file
- Throws:
IOException
- if any.
-
getOpenCount
public int getOpenCount(URI uri) throws IOException
Returns the number of usage for a RRD.- Parameters:
uri
- RRD's uri for which informations is needed.- Returns:
- the number of request for this file
- Throws:
IOException
- if any.
-
-