|
From: <sa...@us...> - 2003-10-21 13:50:59
|
Update of /cvsroot/jrobin/src/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv14516/jrobin/core
Modified Files:
Archive.java FetchPoint.java FetchRequest.java Robin.java
RrdDb.java
Log Message:
Two nice graphs...
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Archive.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Archive.java 6 Oct 2003 10:45:04 -0000 1.5
--- Archive.java 21 Oct 2003 12:53:05 -0000 1.6
***************
*** 312,315 ****
--- 312,351 ----
}
+ FetchData fetchData(FetchRequest request) throws IOException, RrdException {
+ long arcStep = getArcStep();
+ long fetchStart = Util.normalize(request.getFetchStart(), arcStep);
+ long fetchEnd = Util.normalize(request.getFetchEnd(), arcStep);
+ if(fetchEnd < request.getFetchEnd()) {
+ fetchEnd += arcStep;
+ }
+ long startTime = getStartTime();
+ long endTime = getEndTime();
+ int dsCount = robins.length;
+ int ptsCount = (int) ((fetchEnd - fetchStart) / arcStep + 1);
+ long[] timestamps = new long[ptsCount];
+ double[][] values = new double[dsCount][ptsCount];
+ for(int ptIndex = 0; ptIndex < ptsCount; ptIndex++) {
+ long time = fetchStart + ptIndex * arcStep;
+ timestamps[ptIndex] = time;
+ if(time >= startTime && time <= endTime) {
+ // inbound time
+ int robinIndex = (int)((time - startTime) / arcStep);
+ for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
+ values[dsIndex][ptIndex] = robins[dsIndex].getValue(robinIndex);
+ }
+ }
+ else {
+ // time out of bounds
+ for(int dsIndex = 0; dsIndex < dsCount; dsIndex++) {
+ values[dsIndex][ptIndex] = Double.NaN;
+ }
+ }
+ }
+ FetchData fetchData = new FetchData(this, request);
+ fetchData.setTimestamps(timestamps);
+ fetchData.setValues(values);
+ return fetchData;
+ }
+
void appendXml(XmlWriter writer) throws IOException {
writer.startTag("rra");
Index: FetchPoint.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/FetchPoint.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FetchPoint.java 4 Sep 2003 13:26:41 -0000 1.1
--- FetchPoint.java 21 Oct 2003 12:53:05 -0000 1.2
***************
*** 74,90 ****
* @param i Data source index.
* @return Value of the i-th data source.
- * @throws RrdException
*/
! public double getValue(int i) throws RrdException {
! if(i >= values.length) {
! throw new RrdException("Index [" + i + "] out of bounds [" + values.length + "]");
! }
return values[i];
}
! void setValue(int index, double value) throws RrdException {
! if(index >= values.length) {
! throw new RrdException("Index [" + index + "] out of bounds [" + values.length + "]");
! }
values[index] = value;
}
--- 74,83 ----
* @param i Data source index.
* @return Value of the i-th data source.
*/
! public double getValue(int i) {
return values[i];
}
! void setValue(int index, double value) {
values[index] = value;
}
Index: FetchRequest.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/FetchRequest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FetchRequest.java 4 Sep 2003 13:26:41 -0000 1.1
--- FetchRequest.java 21 Oct 2003 12:53:05 -0000 1.2
***************
*** 119,124 ****
/**
! * Returns data from RRD file. Returned data consists of many fetch points (see
! * {@link jrobin.core.FetchPoint FetchPoint}), and each fetch point represents
* RRD datasource values for the specific timestamp. Timestamp difference between
* consecutive fecth points is guaranteed to be constant.
--- 119,124 ----
/**
! * Returns data from the underlying RRD file as an array of
! * {@link jrobin.core.FetchPoint FetchPoint} objects. Each fetch point object represents
* RRD datasource values for the specific timestamp. Timestamp difference between
* consecutive fecth points is guaranteed to be constant.
***************
*** 126,132 ****
--- 126,145 ----
* @throws RrdException Thrown in case of JRobin specific error.
* @throws IOException Thrown in case of I/O error.
+ * @deprecated As of version 1.2.0 replaced with {@link #fetchData() fetchData()}.
*/
public FetchPoint[] fetch() throws RrdException, IOException {
return parentDb.fetch(this);
+ }
+
+ /**
+ * Returns data from the underlying RRD file and puts it in a single
+ * {@link jrobin.core.FetchData FetchData} object. Use this method instead of
+ * deprecated {@link #fetch() fetch()} method.
+ * @return FetchPoint object filled with timestamps and datasource values.
+ * @throws RrdException Thrown in case of JRobin specific error.
+ * @throws IOException Thrown in case of I/O error.
+ */
+ public FetchData fetchData() throws RrdException, IOException {
+ return parentDb.fetchData(this);
}
Index: Robin.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/Robin.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Robin.java 6 Oct 2003 10:45:04 -0000 1.3
--- Robin.java 21 Oct 2003 12:53:05 -0000 1.4
***************
*** 101,105 ****
*/
public double getValue(int index) throws IOException {
- assert(index < rows);
return values.get((pointer.get() + index) % rows);
}
--- 101,104 ----
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/core/RrdDb.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** RrdDb.java 17 Oct 2003 12:12:20 -0000 1.8
--- RrdDb.java 21 Oct 2003 12:53:05 -0000 1.9
***************
*** 24,27 ****
--- 24,28 ----
import java.io.*;
+ import java.util.GregorianCalendar;
/**
***************
*** 133,137 ****
* @throws RrdException Thrown in case of JRobin specific error.
*/
-
public RrdDb(String path) throws IOException, RrdException {
// opens existing RRD file - throw exception if the file does not exist...
--- 134,137 ----
***************
*** 185,189 ****
* @throws RrdException Thrown in case of JRobin specific error
*/
-
public RrdDb(String rrdPath, String xmlPath) throws IOException, RrdException {
initializeSetup(rrdPath);
--- 185,188 ----
***************
*** 228,232 ****
* @throws IOException Thrown in case of I/O related error.
*/
-
public synchronized void close() throws IOException {
if(file != null) {
--- 227,230 ----
***************
*** 243,247 ****
* @return Underlying RrdFile object
*/
-
public RrdFile getRrdFile() {
return file;
--- 241,244 ----
***************
*** 388,391 ****
--- 385,395 ----
}
+ synchronized FetchData fetchData(FetchRequest request) throws IOException, RrdException {
+ Archive archive = findMatchingArchive(request);
+ FetchData fetchData = archive.fetchData(request);
+ Util.debug(request.getRrdToolCommand());
+ return fetchData;
+ }
+
private Archive findMatchingArchive(FetchRequest request) throws IOException, RrdException {
String consolFun = request.getConsolFun();
***************
*** 640,643 ****
close();
}
-
}
--- 644,646 ----
|