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 can also be used a factory for RrdDb, using a default backend factory.
In case of interruptions, it throws IllegalStateException.
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.
|
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.
|
String[] |
getOpenFiles()
Returns an array of open RRD.
|
URI[] |
getOpenUri()
Returns an array of open RRD URI.
|
java.util.stream.Stream<URI> |
getOpenUriStream()
Returns an stream open RRD.
|
Lock |
lockEmpty(long timeout,
TimeUnit unit)
Wait until the pool is empty and return a lock that prevent any additions of new RrdDb references until it's released.
|
void |
release(RrdDb rrdDb)
Deprecated.
A RrdDb remember if it was open directly or from a pool, no need to manage it manually any more
|
RrdDb |
requestRrdDb(RrdDef rrdDef)
Requests a RrdDb reference for the given RRD definition object.
|
(package private) RrdDb |
requestRrdDb(RrdDef rrdDef,
RrdBackendFactory factory) |
RrdDb |
requestRrdDb(String path)
Requests a RrdDb reference for the given RRD 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 URI.
|
(package private) RrdDb |
requestRrdDb(URI uri,
RrdBackendFactory factory) |
(package private) RrdDb |
requestRrdDb(URI uri,
RrdBackendFactory factory,
DataImporter importer) |
RrdDb |
requestRrdDb(URI uri,
String sourcePath)
Requests a RrdDb reference for the given URI.
|
void |
setCapacity(int newCapacity)
Sets the maximum number of simultaneously open RRD.
|
void |
setDefaultFactory(RrdBackendFactory defaultFactory)
Deprecated.
the pool is no longer a singleton, create a new pool instead of changing it.
|
public static final int INITIAL_CAPACITY
public RrdDbPool()
public RrdDbPool(RrdBackendFactory defaultFactory)
defaultFactory
- the default factory used when given a simple path of a RRD.public static RrdDbPool getInstance()
public int getOpenFileCount()
public URI[] getOpenUri()
URI
to open RRD held in the pool.public java.util.stream.Stream<URI> getOpenUriStream()
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 errorIllegalStateException
- if the thread was interruptedpublic RrdDb requestRrdDb(String path) throws IOException
Requests a RrdDb reference for the given RRD path.
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 to
getCapacity()
, 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.
path
- Path to existing RRD.IOException
- Thrown in case of I/O errorpublic RrdDb requestRrdDb(URI uri) throws IOException
Requests a RrdDb reference for the given RRD URI.
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 to
getCapacity()
, 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.
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 factory) throws IOException
IOException
RrdDb requestRrdDb(URI uri, RrdBackendFactory factory, DataImporter importer) throws IOException
IOException
public RrdDb requestRrdDb(RrdDef rrdDef) throws IOException
Requests a RrdDb reference for the given RRD definition object.
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 to
getCapacity()
, 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.
rrdDef
- Definition of the RRD file to be created.IOException
- Thrown in case of I/O errorIllegalStateException
- if the thread was interruptedpublic RrdDb requestRrdDb(String path, String sourcePath) throws IOException
Requests a RrdDb reference for the given path. The RRD will be created from external data (from XML dump or RRDTool's binary RRD file).
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 to
getCapacity()
, the method blocks until some RrdDb references are closed.
The path is transformed to an URI using the default factory of the pool.
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.IOException
- Thrown in case of I/O errorIllegalStateException
- if the thread was interruptedpublic RrdDb requestRrdDb(URI uri, String sourcePath) throws IOException
Requests a RrdDb reference for the given URI. The RRD will be created from external data (from XML dump or RRDTool's binary RRD file).
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 to
getCapacity()
, the method blocks until some RrdDb references are closed.
RrdBackendFactory.findFactory(URI)
will be used to choose the factory.uri
- URI to the RRD that 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 errorIllegalStateException
- if the thread was interrupted@Deprecated public void setDefaultFactory(RrdBackendFactory defaultFactory)
defaultFactory
- The factory to use.IllegalStateException
- if called while the pool is not empty or the thread was interruptedIllegalStateException
- if the thread was interruptedpublic void setCapacity(int newCapacity)
newCapacity
- Maximum number of simultaneously open RRD.IllegalStateException
- if called while the pool is not empty or the thread was interrupted.public int getCapacity()
IllegalStateException
- if the thread was interruptedpublic int getOpenCount(RrdDb rrdDb)
rrdDb
- RrdDb reference for which informations is needed.IllegalStateException
- if the thread was interruptedpublic int getOpenCount(String path)
The path is transformed to an URI using the default factory.
path
- RRD's path for which informations is needed.IllegalStateException
- if the thread was interruptedpublic int getOpenCount(URI uri)
uri
- RRD's URI for which informations is needed.IllegalStateException
- if the thread was interruptedpublic Lock lockEmpty(long timeout, TimeUnit unit) throws InterruptedException
timeout
- the time to wait for the write lockunit
- the time unit of the timeout argumentInterruptedException
- if interrupted whole waiting for the lock