use of org.openmuc.framework.data.FutureValue in project OpenMUC by isc-konstanz.
the class ChannelImpl method getLoggedRecords.
@Override
public List<Record> getLoggedRecords(long startTime, long endTime) throws DataLoggerNotAvailableException, IOException {
String reader = getValidReaderIdFromConfig();
List<Record> toReturn = dataManager.getDataLogger(reader).getRecords(config.getId(), startTime, endTime);
// values in the future values list are sorted.
Long currentTime = System.currentTimeMillis();
for (FutureValue futureValue : futureValues) {
if (futureValue.getWriteTime() >= currentTime) {
if (futureValue.getWriteTime() <= endTime) {
Record futureValAsRec = new Record(futureValue.getValue(), futureValue.getWriteTime());
toReturn.add(futureValAsRec);
} else {
break;
}
}
}
return toReturn;
}
use of org.openmuc.framework.data.FutureValue in project OpenMUC by isc-konstanz.
the class ChannelImpl method writeFuture.
@Override
public void writeFuture(List<FutureValue> values) {
if (values == null) {
throw new NullPointerException("Argument is not allowed to be null.");
}
this.futureValues = values;
Collections.sort(values, new Comparator<FutureValue>() {
@Override
public int compare(FutureValue o1, FutureValue o2) {
return o1.getWriteTime().compareTo(o2.getWriteTime());
}
});
if (timer != null) {
timer.cancel();
}
timer = new Timer("Timer ChannelImpl " + config.getId());
long currentTimestamp = System.currentTimeMillis();
for (final FutureValue value : futureValues) {
if ((currentTimestamp - value.getWriteTime()) >= 1000l) {
continue;
}
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
write(value.getValue());
}
};
Date scheduleTime = new Date(value.getWriteTime());
timer.schedule(timerTask, scheduleTime);
}
}
Aggregations