1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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, null, null);
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 }