@Override public SampledValue read(long timestamp) throws IOException { if ((timestamp - startTimeStamp) % storagePeriod == 0) { if (timestamp >= startTimeStamp && timestamp <= getTimestampForLatestValueInternal()) { if (!canRead) { enableInput(); } fis.getChannel().position(getBytePosition(timestamp)); Double toReturn = dis.readDouble(); if (!Double.isNaN(toReturn)) { return new SampledValue(DoubleValues.of(toReturn), timestamp, Quality.getQuality(dis.readByte())); } } } return null; }
@Override public SampledValue read(long timestamp) throws IOException { if ((timestamp - startTimeStamp) % storagePeriod == 0) { if (timestamp >= startTimeStamp && timestamp <= getTimestampForLatestValueInternal()) { if (!canRead) { enableInput(); } fis.getChannel().position(getBytePosition(timestamp)); Double toReturn = dis.readDouble(); if (!Double.isNaN(toReturn)) { return new SampledValue(DoubleValues.of(toReturn), timestamp, Quality.getQuality(dis.readByte())); } } } return null; }
@Override public Void run() throws Exception { lock.writeLock().lock(); try { if (configuration != null) { for (SampledValue value : values) { recorder.getProxy().appendValue(id, value.getValue().getDoubleValue(), value.getTimestamp(), (byte) value.getQuality().getQuality(), configuration); } } } catch (IOException e) { logger.error("", e); } catch (IllegalConversionException e) { logger.error("", e); } finally { lock.writeLock().unlock(); } return null; }
@Override public Void run() throws Exception { lock.writeLock().lock(); try { if (configuration != null) { for (SampledValue value : values) { recorder.getProxy().appendValue(idEncoded, value.getValue().getDoubleValue(), value.getTimestamp(), (byte) value.getQuality().getQuality(), configuration); } } } catch (IOException e) { logger.error("", e); } catch (IllegalConversionException e) { logger.error("", e); } finally { lock.writeLock().unlock(); } return null; }
@Override public Void run() throws Exception { lock.writeLock().lock(); try { if (configuration != null) { recorder.getProxy().appendValue(id, value.getValue().getDoubleValue(), value.getTimestamp(), (byte) value.getQuality().getQuality(), configuration); } } catch (IOException e) { logger.error("", e); } catch (IllegalConversionException e) { logger.error("", e); } catch (NullPointerException e) { logger.error("NPE in SlotsdbStorage - recorder: {}, proxy: {}, id: {}, config: {}, value: {}", recorder, (recorder!=null? recorder.getProxy(): null), id, configuration, value,e); } finally { lock.writeLock().unlock(); } return null; }
@Override public Void run() throws Exception { lock.writeLock().lock(); try { if (configuration != null) { recorder.getProxy().appendValue(idEncoded, value.getValue().getDoubleValue(), value.getTimestamp(), (byte) value.getQuality().getQuality(), configuration); } } catch (IOException e) { logger.error("", e); } catch (IllegalConversionException e) { logger.error("", e); } catch (NullPointerException e) { logger.error("NPE in SlotsdbStorage - recorder: {}, proxy: {}, id: {}, config: {}, value: {}", recorder, (recorder!=null? recorder.getProxy(): null), id, configuration, value,e); } finally { lock.writeLock().unlock(); } return null; }
@Override public SampledValue readPreviousValue(long timestamp) throws IOException { // Calculate next Value, round Timestamp to next Value timestamp = timestamp + (storagePeriod - ((timestamp - startTimeStamp) % storagePeriod)); // what if storagePeriod changes? long startPos = getBytePosition(startTimeStamp); long endPos = getBytePosition(timestamp); for (int i = 0; i <= (endPos - startPos) / 9; i++) { if (timestamp >= startTimeStamp && timestamp <= getTimestampForLatestValueInternal()) { if (!canRead) { enableInput(); } fis.getChannel().position(getBytePosition(timestamp)); Double toReturn = dis.readDouble(); if (!Double.isNaN(toReturn)) { return new SampledValue(DoubleValues.of(toReturn), timestamp, Quality.getQuality(dis.readByte())); } timestamp -= storagePeriod; } } return null; }
@Override public SampledValue readPreviousValue(long timestamp) throws IOException { // Calculate next Value, round Timestamp to next Value timestamp = timestamp + (storagePeriod - ((timestamp - startTimeStamp) % storagePeriod)); // what if storagePeriod changes? long startPos = getBytePosition(startTimeStamp); long endPos = getBytePosition(timestamp); for (int i = 0; i <= (endPos - startPos) / 9; i++) { if (timestamp >= startTimeStamp && timestamp <= getTimestampForLatestValueInternal()) { if (!canRead) { enableInput(); } fis.getChannel().position(getBytePosition(timestamp)); Double toReturn = dis.readDouble(); if (!Double.isNaN(toReturn)) { return new SampledValue(DoubleValues.of(toReturn), timestamp, Quality.getQuality(dis.readByte())); } timestamp -= storagePeriod; } } return null; }
@Override public SampledValue readNextValue(long timestamp) throws IOException { // Calculate next Value, round Timestamp to next Value timestamp = timestamp + (storagePeriod - ((timestamp - startTimeStamp) % storagePeriod)); long startPos = getBytePosition(timestamp); long endPos = getBytePosition(getTimestampForLatestValueInternal()); for (int i = 0; i <= (endPos - startPos) / 9; i++) { if (timestamp >= startTimeStamp && timestamp <= getTimestampForLatestValueInternal()) { if (!canRead) { enableInput(); } fis.getChannel().position(getBytePosition(timestamp)); Double toReturn = dis.readDouble(); if (!Double.isNaN(toReturn)) { return new SampledValue(DoubleValues.of(toReturn), timestamp, Quality.getQuality(dis.readByte())); } timestamp += storagePeriod; } } return null; }
@Override public SampledValue readNextValue(long timestamp) throws IOException { // Calculate next Value, round Timestamp to next Value timestamp = timestamp + (storagePeriod - ((timestamp - startTimeStamp) % storagePeriod)); long startPos = getBytePosition(timestamp); long endPos = getBytePosition(getTimestampForLatestValueInternal()); for (int i = 0; i <= (endPos - startPos) / 9; i++) { if (timestamp >= startTimeStamp && timestamp <= getTimestampForLatestValueInternal()) { if (!canRead) { enableInput(); } fis.getChannel().position(getBytePosition(timestamp)); Double toReturn = dis.readDouble(); if (!Double.isNaN(toReturn)) { return new SampledValue(DoubleValues.of(toReturn), timestamp, Quality.getQuality(dis.readByte())); } timestamp += storagePeriod; } } return null; }
private void writeFloatValues(List<SampledValue> entries) { assert entries.isEmpty() || baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; // 1st case on delete final int size = entries.size(); final long[] times = new long[size]; final int[] qualities = new int[size]; final float[] values = new float[size]; for (int i = 0; i < size; ++i) { final SampledValue entry = entries.get(i); times[i] = entry.getTimestamp(); qualities[i] = entry.getQuality().getQuality(); values[i] = entry.getValue().getFloatValue(); } m_times.getData().setLongArr(times); m_qualities.getData().setIntArr(qualities); m_values.getData().setFloatArr(values); }
private void writeStringValues(List<SampledValue> entries) { assert entries.isEmpty() || baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; // 1st case on delete final int size = entries.size(); final long[] times = new long[size]; final int[] qualities = new int[size]; final String[] values = new String[size]; for (int i = 0; i < size; ++i) { final SampledValue entry = entries.get(i); times[i] = entry.getTimestamp(); qualities[i] = entry.getQuality().getQuality(); values[i] = entry.getValue().getStringValue(); } m_times.getData().setLongArr(times); m_qualities.getData().setIntArr(qualities); m_values.getData().setStringArr(values); }
private void writeBooleanValues(List<SampledValue> entries) { assert entries.isEmpty() || baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; // 1st case on delete final int size = entries.size(); final long[] times = new long[size]; final int[] qualities = new int[size]; final boolean[] values = new boolean[size]; for (int i = 0; i < size; ++i) { final SampledValue entry = entries.get(i); times[i] = entry.getTimestamp(); qualities[i] = entry.getQuality().getQuality(); values[i] = entry.getValue().getBooleanValue(); } m_times.getData().setLongArr(times); m_qualities.getData().setIntArr(qualities); m_values.getData().setBooleanArr(values); }
private void writeLongValues(List<SampledValue> entries) { assert entries.isEmpty() || baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; // 1st case on delete final int size = entries.size(); final long[] times = new long[size]; final int[] qualities = new int[size]; final long[] values = new long[size]; for (int i = 0; i < size; ++i) { final SampledValue entry = entries.get(i); times[i] = entry.getTimestamp(); qualities[i] = entry.getQuality().getQuality(); values[i] = entry.getValue().getLongValue(); } m_times.getData().setLongArr(times); m_qualities.getData().setIntArr(qualities); m_values.getData().setLongArr(values); }
private void writeIntegerValues(List<SampledValue> entries) { assert entries.isEmpty() || baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; // 1st case on delete final int size = entries.size(); final long[] times = new long[size]; final int[] qualities = new int[size]; final int[] values = new int[size]; for (int i = 0; i < size; ++i) { final SampledValue entry = entries.get(i); times[i] = entry.getTimestamp(); qualities[i] = entry.getQuality().getQuality(); values[i] = entry.getValue().getIntegerValue(); } m_times.getData().setLongArr(times); m_qualities.getData().setIntArr(qualities); m_values.getData().setIntArr(values); }
private List<SampledValue> getIntegerValues() { assert baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; final long[] times = m_times.getData().getLongArr(); final int[] values = m_values.getData().getIntArr(); final int[] qualities = m_qualities.getData().getIntArr(); List<SampledValue> result = new ArrayList<>(values.length); for (int i = 0; i < values.length; ++i) { final int v = values[i]; final long t = times[i]; final Quality q = Quality.getQuality(qualities[i]); result.add(new SampledValue(new IntegerValue(v), t, q)); } return result; }
private List<SampledValue> getLongValues() { assert baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; final long[] times = m_times.getData().getLongArr(); final long[] values = m_values.getData().getLongArr(); final int[] qualities = m_qualities.getData().getIntArr(); List<SampledValue> result = new ArrayList<>(values.length); for (int i = 0; i < values.length; ++i) { final long v = values[i]; final long t = times[i]; final Quality q = Quality.getQuality(qualities[i]); result.add(new SampledValue(new LongValue(v), t, q)); } return result; }
private List<SampledValue> getBooleanValues() { assert baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; final long[] times = m_times.getData().getLongArr(); final boolean[] values = m_values.getData().getBooleanArr(); final int[] qualities = m_qualities.getData().getIntArr(); List<SampledValue> result = new ArrayList<>(values.length); for (int i = 0; i < values.length; ++i) { final boolean v = values[i]; final long t = times[i]; final Quality q = Quality.getQuality(qualities[i]); result.add(new SampledValue(new BooleanValue(v), t, q)); } return result; }
private List<SampledValue> getStringValues() { assert baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; final long[] times = m_times.getData().getLongArr(); final String[] values = m_values.getData().getStringArr(); final int[] qualities = m_qualities.getData().getIntArr(); List<SampledValue> result = new ArrayList<>(values.length); for (int i = 0; i < values.length; ++i) { final String v = values[i]; final long t = times[i]; final Quality q = Quality.getQuality(qualities[i]); result.add(new SampledValue(new StringValue(v), t, q)); } return result; }
/** * Gets the entries as a list of SampledValues with type FloatValue * * @return */ private List<SampledValue> getFloatValues() { assert baseElement.isVirtual() || !((VirtualTreeElement) m_values).isVirtual() : "Schedule state inconsistent"; final long[] times = m_times.getData().getLongArr(); final float[] values = m_values.getData().getFloatArr(); final int[] qualities = m_qualities.getData().getIntArr(); List<SampledValue> result = new ArrayList<>(values.length); for (int i = 0; i < values.length; ++i) { final float v = values[i]; final long t = times[i]; final Quality q = Quality.getQuality(qualities[i]); result.add(new SampledValue(new FloatValue(v), t, q)); } return result; }