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.
Modifier and Type | Field and Description |
---|---|
static int |
INITIAL_CAPACITY
Initial capacity of the pool i.e.
|
Constructor and Description |
---|
RrdDbPool()
Constructor for RrdDbPool.
|
RrdDbPool(RrdBackendFactory defaultFactory)
Constructor for RrdDbPool.
|
Modifier and Type | Method and 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(RrdDb rrdDb)
Returns the number of usage for a RRD.
|
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 |
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 db remember if it was open directly or from the pool, no need to manage it manually any more
|
RrdDb |
requestRrdDb(RrdDef rrdDef)
Requests a RrdDb reference for the given RRD file definition object.
|
(package private) RrdDb |
requestRrdDb(RrdDef rrdDef,
RrdBackendFactory backend) |
RrdDb |
requestRrdDb(String path)
Requests a RrdDb reference for the given RRD file path.
|
RrdDb |
requestRrdDb(String path,
String sourcePath)
Requests a RrdDb reference for the given path.
|
RrdDb |
requestRrdDb(URI uri)
Requests a RrdDb reference for the given RRD file path.
|
(package private) RrdDb |
requestRrdDb(URI uri,
RrdBackendFactory factory) |
(package private) RrdDb |
requestRrdDb(URI uri,
RrdBackendFactory backend,
DataImporter importer) |
RrdDb |
requestRrdDb(URI uri,
String sourcePath)
Requests a RrdDb reference for the given path.
|
void |
setCapacity(int newCapacity)
Sets the maximum number of simultaneously open RRD files.
|
void |
setDefaultFactory(RrdBackendFactory defaultFactory)
Sets the default factory to use when obtaining rrdDb from simple path and not URI.
|
public static final int INITIAL_CAPACITY
public RrdDbPool()
public RrdDbPool(RrdBackendFactory defaultFactory)
defaultFactory
- the default factory used when given simple path of a rrdDb.public static RrdDbPool getInstance()
RuntimeException
- Thrown if the default RRD backend is not derived from the RrdFileBackendFactory
public int getOpenFileCount()
public URI[] getOpenUri()
URI
to open RRD files held in the pool.public String[] getOpenFiles()
@Deprecated public void release(RrdDb rrdDb) throws IOException
rrdDb
- RrdDb reference to be returned to the poolIOException
- Thrown in case of I/O errorpublic RrdDb requestRrdDb(String path) throws IOException
Requests a RrdDb reference for the given RRD file path.
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 to
INITIAL_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.
path
- Path to existing RRD fileIOException
- Thrown in case of I/O errorpublic RrdDb requestRrdDb(URI uri) throws IOException
Requests a RrdDb reference for the given RRD file path.
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 to
INITIAL_CAPACITY
, the method blocks until some RRD file is closed.
uri
- URI
to existing RRD fileIOException
- Thrown in case of I/O errorRrdDb requestRrdDb(URI uri, RrdBackendFactory factory) throws IOException
IOException
RrdDb requestRrdDb(RrdDef rrdDef, RrdBackendFactory backend) throws IOException
IOException
RrdDb requestRrdDb(URI uri, RrdBackendFactory backend, DataImporter importer) throws IOException
IOException
public RrdDb requestRrdDb(RrdDef rrdDef) throws IOException
Requests a RrdDb reference for the given RRD file definition object.
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 to
INITIAL_CAPACITY
, the method blocks until some RRD file is closed.
rrdDef
- Definition of the RRD file to be createdIOException
- Thrown in case of I/O errorpublic RrdDb requestRrdDb(String path, String sourcePath) throws IOException
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).
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 to
INITIAL_CAPACITY
, the method blocks until some RRD file is closed.
The path is transformed internally to an URI using the default factory of the pool.
path
- Path to RRD file which should be createdsourcePath
- Path to external data which is to be converted to Rrd4j's native RRD file formatIOException
- Thrown in case of I/O errorpublic RrdDb requestRrdDb(URI uri, String sourcePath) throws IOException
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).
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 to
INITIAL_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.
uri
- Path to RRD file which should be createdsourcePath
- Path to external data which is to be converted to Rrd4j's native RRD file formatIOException
- Thrown in case of I/O errorpublic void setDefaultFactory(RrdBackendFactory defaultFactory)
defaultFactory
- The factory to used.IllegalStateException
- if done will the pool is not empty or the thread was interrupted.public void setCapacity(int newCapacity)
newCapacity
- Maximum number of simultaneously open RRD files.IllegalStateException
- if done will the pool is not empty or the thread was interrupted.public int getCapacity()
public int getOpenCount(RrdDb rrdDb) throws IOException
rrdDb
- RrdDb reference for which informations is needed.IOException
- if any.public int getOpenCount(String path) throws IOException
path
- RRD's path for which informations is needed.IOException
- if any.public int getOpenCount(URI uri) throws IOException
uri
- RRD's uri for which informations is needed.IOException
- if any.