-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
ExtendedStorage.groovy
165 lines (130 loc) · 4.57 KB
/
ExtendedStorage.groovy
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
CCU-Historian, a long term archive for the HomeMatic CCU
Copyright (C) 2011-2017 MDZ (info@ccu-historian.de)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package mdz.ccuhistorian
import groovy.lang.Closure
import java.util.Date
import java.util.List
import java.util.concurrent.atomic.AtomicBoolean
import mdz.hc.DataPoint
import mdz.hc.DataPointIdentifier
import mdz.hc.Event
import mdz.hc.ProcessValue
import mdz.hc.persistence.Storage
import mdz.hc.timeseries.TimeSeries
class ExtendedStorage implements Storage {
Storage storage
// The onReadListener's are called first.
HashSet<Closure> onReadListener=[]
// The onRequestFlushListener's are called after the onReadListener's.
HashSet<Closure> onRequestFlushListener=[]
public void consume(Event t) throws Exception {
storage.consume(t)
}
public List<DataPoint> getDataPoints() throws Exception {
fireOnRead()
return storage.getDataPoints()
}
public List<DataPoint> getDataPointsOfInterface(String itfName) throws Exception {
fireOnRead()
return storage.getDataPointsOfInterface(itfName)
}
public DataPoint getDataPoint(int idx) throws Exception {
fireOnRead()
return storage.getDataPoint(idx)
}
public DataPoint getDataPoint(DataPointIdentifier id) throws Exception {
fireOnRead()
return storage.getDataPoint(id)
}
public void createDataPoint(DataPoint dp) throws Exception {
storage.createDataPoint(dp)
}
public void updateDataPoint(DataPoint dp) throws Exception {
storage.updateDataPoint(dp)
}
public void deleteDataPoint(DataPoint dp) throws Exception {
storage.deleteDataPoint(dp)
}
public void normalizeDataPoint(DataPoint dp) {
storage.normalizeDataPoint(dp)
}
public Date getFirstTimestamp(DataPoint dp) throws Exception {
fireOnRead()
return storage.getFirstTimestamp(dp)
}
public ProcessValue getLast(DataPoint dp) throws Exception {
fireOnRead()
fireOnRequestFlush(dp.id)
return storage.getLast(dp)
}
public Date getFirstBeforeIncl(DataPoint dp, Date ts) {
fireOnRead()
return storage.getFirstBeforeIncl(dp, ts)
}
public Date getFirstAfterIncl(DataPoint dp, Date ts) {
fireOnRead()
return storage.getFirstAfterIncl(dp, ts)
}
public TimeSeries getTimeSeriesRaw(DataPoint dp, Date begin, Date end) throws Exception {
fireOnRead()
fireOnRequestFlush(dp.id)
return storage.getTimeSeriesRaw(dp, begin, end)
}
public TimeSeries getTimeSeries(DataPoint dp, Date begin, Date end) throws Exception {
fireOnRead()
fireOnRequestFlush(dp.id)
return storage.getTimeSeries(dp, begin, end)
}
public int getCount(DataPoint dp, Date startTime, Date endTime) throws Exception {
fireOnRead()
return storage.getCount(dp, startTime, endTime)
}
public int deleteTimeSeries(DataPoint dp, Date startTime, Date endTime) throws Exception {
fireOnRead()
return storage.deleteTimeSeries(dp, startTime, endTime)
}
public int copyTimeSeries(DataPoint dstDp, DataPoint srcDp, Date startTime, Date endTime, Date newStartTime) throws Exception {
fireOnRead()
return storage.copyTimeSeries(dstDp, srcDp, startTime, endTime, newStartTime)
}
public int replaceTimeSeries(DataPoint dstDp, Iterable<ProcessValue> srcSeries, Date startTime, Date endTime) throws Exception {
fireOnRead()
return storage.replaceTimeSeries(dstDp, srcSeries, startTime, endTime)
}
public void createBackup(String fileName) {
fireOnRead()
storage.createBackup(fileName)
}
String getConfig(String name) {
return storage.getConfig(name)
}
void setConfig(String name, String value) {
storage.setConfig(name, value)
}
/**
* Forward reading of configuration properties.
* @param propertyName
* @return
*/
public Object propertyMissing(String propertyName) {
storage."$propertyName"
}
private fireOnRead() {
onReadListener.each { Closure cl -> cl() }
}
private fireOnRequestFlush(DataPointIdentifier id) {
onRequestFlushListener.each { Closure cl -> cl(id) }
}
}