org.rrd4j.core
Class RrdDbPool

java.lang.Object
  extended by org.rrd4j.core.RrdDbPool

public abstract 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).

The abstract wrapper for different implementations of the pools.


Field Summary
static int INITIAL_CAPACITY
          Initial capacity of the pool i.e. maximum number of simultaneously open RRD files.
 
Constructor Summary
RrdDbPool()
           
 
Method Summary
abstract  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.
abstract  int getOpenCount(RrdDb rrdDb)
          Returns the number of usage for a RRD.
abstract  int getOpenCount(String path)
          Returns the number of usage for a RRD.
abstract  int getOpenFileCount()
          Returns the number of open RRD files.
abstract  String[] getOpenFiles()
          Returns an array of open file names.
abstract  void release(RrdDb rrdDb)
          Releases RrdDb reference previously obtained from the pool.
abstract  RrdDb requestRrdDb(RrdDef rrdDef)
          Requests a RrdDb reference for the given RRD file definition object.
abstract  RrdDb requestRrdDb(String path)
          Requests a RrdDb reference for the given RRD file path.
abstract  RrdDb requestRrdDb(String path, String sourcePath)
          Requests a RrdDb reference for the given path.
abstract  void setCapacity(int capacity)
          Sets the maximum number of simultaneously open RRD files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

RrdDbPool

public RrdDbPool()
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 the RrdFileBackendFactory

requestRrdDb

public abstract RrdDb requestRrdDb(String path)
                            throws IOException
Requests a RrdDb reference for the given RRD file path.

Parameters:
path - Path to existing RRD file
Returns:
reference for the give RRD file
Throws:
IOException - Thrown in case of I/O error

requestRrdDb

public abstract RrdDb requestRrdDb(RrdDef rrdDef)
                            throws IOException
Requests a RrdDb reference for the given RRD file definition object.

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

public abstract 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, RRD file or RRDTool's binary RRD file).

Parameters:
path - Path to RRD file which 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 file
Throws:
IOException - Thrown in case of I/O error

release

public abstract void release(RrdDb rrdDb)
                      throws IOException
Releases 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

getCapacity

public abstract int getCapacity()
Returns the maximum number of simultaneously open RRD files.

Returns:
maximum number of simultaneously open RRD files

setCapacity

public abstract void setCapacity(int capacity)
Sets the maximum number of simultaneously open RRD files.

Parameters:
capacity - Maximum number of simultaneously open RRD files.

getOpenFiles

public abstract String[] getOpenFiles()
Returns an array of open file names.

Returns:
Array with canonical paths to open RRD files held in the pool.

getOpenFileCount

public abstract int getOpenFileCount()
Returns the number of open RRD files.

Returns:
Number of currently open RRD files held in the pool.

getOpenCount

public abstract 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

getOpenCount

public abstract int getOpenCount(String path)
                          throws IOException
Returns the number of usage for a RRD.

Parameters:
path - RRD file for which informations is needed.
Returns:
the number of request for this file
Throws:
IOException


Copyright © 2011. All Rights Reserved.