Search in sources :

Example 1 with FutureValue

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;
}
Also used : FutureValue(org.openmuc.framework.data.FutureValue) Record(org.openmuc.framework.data.Record)

Example 2 with FutureValue

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);
    }
}
Also used : FutureValue(org.openmuc.framework.data.FutureValue) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Date(java.util.Date)

Aggregations

FutureValue (org.openmuc.framework.data.FutureValue)2 Date (java.util.Date)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Record (org.openmuc.framework.data.Record)1