org.opennms.netmgt.rrd.rrdtool
Class JniRrdStrategy

java.lang.Object
  extended by org.opennms.netmgt.rrd.rrdtool.JniRrdStrategy
All Implemented Interfaces:
org.opennms.netmgt.rrd.RrdStrategy

public class JniRrdStrategy
extends Object
implements org.opennms.netmgt.rrd.RrdStrategy

Provides an rrdtool based implementation of RrdStrategy. It uses the existing JNI based single-threaded interface to write the rrdtool compatibile RRD files. The JNI interface takes command-like arguments and doesn't provide open files so the the Objects used to represent open files are really partial command strings See the individual methods for more details


Constructor Summary
JniRrdStrategy()
           
 
Method Summary
 void closeFile(Object rrd)
          The 'closes' the rrd file.
 Object createDefinition(String creator, String directory, String rrdName, int step, List<org.opennms.netmgt.rrd.RrdDataSource> dataSources, List<String> rraList)
           
 void createFile(Object rrdDef)
          Creates a the rrd file from the rrdDefinition.
 InputStream createGraph(String command, File workDir)
          Executes the given graph command as process with workDir as the current directory.
 org.opennms.netmgt.rrd.RrdGraphDetails createGraphReturnDetails(String command, File workDir)
           
 Double fetchLastValue(String rrdFile, String ds, int interval)
          Fetches the last value directly from the rrd file using the JNI Interface.
 Double fetchLastValue(String rrdFile, String ds, String consolidationFunction, int interval)
           
 Double fetchLastValueInRange(String rrdFile, String ds, int interval, int range)
           
 String getDefaultFileExtension()
           
 int getGraphLeftOffset()
           
 int getGraphRightOffset()
           
 int getGraphTopOffsetWithText()
           
 String getStats()
          No stats are kept for this implementation.
 void graphicsInitialize()
           
 void initialize()
          Initialized the JNI Interface
 Category log()
           
 Object openFile(String fileName)
          The 'opens' the given rrd file.
 void promoteEnqueuedFiles(Collection<String> rrdFiles)
           
 void updateFile(Object rrd, String owner, String data)
          This 'updates' the given rrd file by providing data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JniRrdStrategy

public JniRrdStrategy()
Method Detail

closeFile

public void closeFile(Object rrd)
               throws Exception
The 'closes' the rrd file. This is where the actual work of writing the RRD files takes place. The passed in rrd is actually an rrd command string containing updates. This method executes this command.

Specified by:
closeFile in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
Exception

createDefinition

public Object createDefinition(String creator,
                               String directory,
                               String rrdName,
                               int step,
                               List<org.opennms.netmgt.rrd.RrdDataSource> dataSources,
                               List<String> rraList)
                        throws Exception
Specified by:
createDefinition in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
Exception

createFile

public void createFile(Object rrdDef)
                throws Exception
Creates a the rrd file from the rrdDefinition. Since this definition is really just the create command string it just executes it.

Specified by:
createFile in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
Exception

openFile

public Object openFile(String fileName)
                throws Exception
The 'opens' the given rrd file. In actuality since the JNI interface does not provide files that may be open, this constructs the beginning portion of the rrd command to update the file.

Specified by:
openFile in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
Exception

updateFile

public void updateFile(Object rrd,
                       String owner,
                       String data)
                throws Exception
This 'updates' the given rrd file by providing data. Since the JNI interface does not provide files that can be open, this just appends the data to the command string constructed so far. The data is not immediately written to the file since this would eliminate the possibility of getting performance benefit by doing more than one write per open. The updates are all performed at once in the closeFile method.

Specified by:
updateFile in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
Exception

initialize

public void initialize()
                throws Exception
Initialized the JNI Interface

Specified by:
initialize in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
Exception

graphicsInitialize

public void graphicsInitialize()
                        throws Exception
Specified by:
graphicsInitialize in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
Exception

fetchLastValue

public Double fetchLastValue(String rrdFile,
                             String ds,
                             int interval)
                      throws NumberFormatException,
                             org.opennms.netmgt.rrd.RrdException
Fetches the last value directly from the rrd file using the JNI Interface.

Specified by:
fetchLastValue in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
NumberFormatException
org.opennms.netmgt.rrd.RrdException

fetchLastValue

public Double fetchLastValue(String rrdFile,
                             String ds,
                             String consolidationFunction,
                             int interval)
Specified by:
fetchLastValue in interface org.opennms.netmgt.rrd.RrdStrategy

fetchLastValueInRange

public Double fetchLastValueInRange(String rrdFile,
                                    String ds,
                                    int interval,
                                    int range)
                             throws NumberFormatException,
                                    org.opennms.netmgt.rrd.RrdException
Specified by:
fetchLastValueInRange in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
NumberFormatException
org.opennms.netmgt.rrd.RrdException

createGraph

public InputStream createGraph(String command,
                               File workDir)
                        throws IOException,
                               org.opennms.netmgt.rrd.RrdException
Executes the given graph command as process with workDir as the current directory. The output stream of the command (a PNG image) is copied to a the InputStream returned from the method.

Specified by:
createGraph in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
IOException
org.opennms.netmgt.rrd.RrdException

getStats

public String getStats()
No stats are kept for this implementation.

Specified by:
getStats in interface org.opennms.netmgt.rrd.RrdStrategy

log

public Category log()

getGraphLeftOffset

public int getGraphLeftOffset()
Specified by:
getGraphLeftOffset in interface org.opennms.netmgt.rrd.RrdStrategy

getGraphRightOffset

public int getGraphRightOffset()
Specified by:
getGraphRightOffset in interface org.opennms.netmgt.rrd.RrdStrategy

getGraphTopOffsetWithText

public int getGraphTopOffsetWithText()
Specified by:
getGraphTopOffsetWithText in interface org.opennms.netmgt.rrd.RrdStrategy

getDefaultFileExtension

public String getDefaultFileExtension()
Specified by:
getDefaultFileExtension in interface org.opennms.netmgt.rrd.RrdStrategy

createGraphReturnDetails

public org.opennms.netmgt.rrd.RrdGraphDetails createGraphReturnDetails(String command,
                                                                       File workDir)
                                                                throws IOException,
                                                                       org.opennms.netmgt.rrd.RrdException
Specified by:
createGraphReturnDetails in interface org.opennms.netmgt.rrd.RrdStrategy
Throws:
IOException
org.opennms.netmgt.rrd.RrdException

promoteEnqueuedFiles

public void promoteEnqueuedFiles(Collection<String> rrdFiles)
Specified by:
promoteEnqueuedFiles in interface org.opennms.netmgt.rrd.RrdStrategy


Copyright ? 2007. All Rights Reserved.