1 /* ============================================================
2  * JRobin : Pure java implementation of RRDTool's functionality
3  * ============================================================
4  *
5  * Project Info:  http://www.jrobin.org
6  * Project Lead:  Sasa Markovic (saxon@jrobin.org);
7  *
8  * (C) Copyright 2003-2005, by Sasa Markovic.
9  *
10  * Developers:    Sasa Markovic (saxon@jrobin.org)
11  *
12  *
13  * This library is free software; you can redistribute it and/or modify it under the terms
14  * of the GNU Lesser General Public License as published by the Free Software Foundation;
15  * either version 2.1 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License along with this
22  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */

25
26 package org.jrobin.data;
27
28 import org.jrobin.core.FetchData;
29 import org.jrobin.core.RrdException;
30 import org.jrobin.core.Util;
31
32 import java.io.IOException;
33
34 class Def extends Source {
35     private String path, dsName, consolFun, backend;
36     private FetchData fetchData;
37
38     Def(String name, FetchData fetchData) {
39         this(name, null, name, nullnull);
40         setFetchData(fetchData);
41     }
42
43     Def(String name, String path, String dsName, String consolFunc) {
44         this(name, path, dsName, consolFunc, null);
45     }
46
47     Def(String name, String path, String dsName, String consolFunc, String backend) {
48         super(name);
49         this.path = path;
50         this.dsName = dsName;
51         this.consolFun = consolFunc;
52         this.backend = backend;
53     }
54
55     String getPath() {
56         return path;
57     }
58
59     String getCanonicalPath() throws IOException {
60         return Util.getCanonicalPath(path);
61     }
62
63     String getDsName() {
64         return dsName;
65     }
66
67     String getConsolFun() {
68         return consolFun;
69     }
70
71     String getBackend() {
72         return backend;
73     }
74
75     boolean isCompatibleWith(Def def) throws IOException {
76         return getCanonicalPath().equals(def.getCanonicalPath()) &&
77                 getConsolFun().equals(def.consolFun) &&
78                 ((backend == null && def.backend == null) ||
79                         (backend != null && def.backend != null && backend.equals(def.backend)));
80     }
81
82     void setFetchData(FetchData fetchData) {
83         this.fetchData = fetchData;
84     }
85
86     long[] getRrdTimestamps() {
87         return fetchData.getTimestamps();
88     }
89
90     double[] getRrdValues() throws RrdException {
91         return fetchData.getValues(dsName);
92     }
93
94     long getArchiveEndTime() {
95         return fetchData.getArcEndTime();
96     }
97
98     long getFetchStep() {
99         return fetchData.getStep();
100     }
101
102     Aggregates getAggregates(long tStart, long tEnd) throws RrdException {
103         long[] t = getRrdTimestamps();
104         double[] v = getRrdValues();
105         Aggregator agg = new Aggregator(t, v);
106         return agg.getAggregates(tStart, tEnd);
107     }
108
109     double getPercentile(long tStart, long tEnd, double percentile) throws RrdException {
110         long[] t = getRrdTimestamps();
111         double[] v = getRrdValues();
112         Aggregator agg = new Aggregator(t, v);
113         return agg.getPercentile(tStart, tEnd, percentile);
114     }
115
116     boolean isLoaded() {
117         return fetchData != null;
118     }
119 }
120