@Override public void writeValue(Map<String, T> newValue) { for (MapUpdate<T> mapUpdate : mapUpdateCollector.readValue()) { for (String name : mapUpdate.getExpressionsToDelete()) { functions.remove(name); } functions.putAll(mapUpdate.getWriteFunctionsToAdd()); } for (Map.Entry<String, T> entry : newValue.entrySet()) { WriteFunction<T> function = functions.get(entry.getKey()); if (function != null) { function.writeValue(entry.getValue()); } } }
@Override public void writeValue(Exception newValue) { super.writeValue(newValue); exceptionHandler.handleException(newValue); }
private static <T> QueueCollector<T> createQueue(int maxSize) { return new QueueCollector<>(maxSize); }
void setScanner(final SourceDesiredRateDecoupler scanStrategy) { synchronized(lock) { this.scanStrategy = scanStrategy; } readExceptionCollector.setChangeNotification(new Runnable() { @Override public void run() { scanStrategy.newReadExceptionEvent(); } }); readConnCollector.setChangeNotification(new Runnable() { @Override public void run() { scanStrategy.newReadConnectionEvent(); } }); }
/** * Changes the maximum size of the queue. * * @param maxSize the number of values kept in the queue * @return this expression */ public Queue<T> maxSize(int maxSize) { getCollector().setMaxSize(maxSize); return this; }
void setScanner(final SourceDesiredRateDecoupler scanStrategy) { synchronized(lock) { this.scanStrategy = scanStrategy; } writeExceptionCollector.setChangeNotification(new Runnable() { @Override public void run() { scanStrategy.newWriteExceptionEvent(); } }); writeConnCollector.setChangeNotification(new Runnable() { @Override public void run() { scanStrategy.newWriteConnectionEvent(); } }); }
/** * Posts a readTimeout exception in the exception queue. * * @param timeoutMessage the message for the readTimeout */ private void processReadTimeout(String timeoutMessage) { PVReaderImpl<T> pv = pvReaderRef.get(); if (pv != null && !pv.isSentFirsEvent()) { readExceptionCollector.writeValue(new TimeoutException(timeoutMessage)); } }
@Override public Map<String, T> readValue() { for (MapUpdate<T> mapUpdate : mapUpdateCollector.readValue()) { for (String name : mapUpdate.getExpressionsToDelete()) { functions.remove(name); } functions.putAll(mapUpdate.getReadFunctionsToAdd()); previousValue = null; } Map<String, T> map = new HashMap<String, T>(); for (Map.Entry<String, ReadFunction<T>> entry : functions.entrySet()) { String name = entry.getKey(); T value = entry.getValue().readValue(); if (value != null) { map.put(name, value); } } if (Objects.equals(previousValue, map)) { return previousValue; } previousValue = map; return map; }
/** * Creates a new group. */ public ReadMap() { super(new DesiredRateExpressionListImpl<Object>(), new MapOfReadFunction<T>(new QueueCollector<MapUpdate<T>>(1000)), "map"); }
@Override public void update(SparklineGraph2DRendererUpdate update) { ((SparklineGraph2DFunction) getFunction()).getRendererUpdateQueue().writeValue(update); }
List<Exception> exceptions = writeExceptionCollector.readValue(); final Exception lastException; if (exceptions.isEmpty()) {
/** * Creates a new group. */ public WriteMap() { super(new WriteExpressionListImpl<Object>(), new MapOfWriteFunction<T>(new QueueCollector<MapUpdate<T>>(1000)), "map"); }
@Override public void update(LineGraph2DRendererUpdate update) { ((LineGraph2DFunction) getFunction()).getRendererUpdateQueue().writeValue(update); }
List<Exception> exceptions = readExceptionCollector.readValue(); final Exception lastException; if (calculationException != null) {
/** * Returns up to maxValues new values generated by the expression source rate. * * @param <T> type being read * @param expression source rate expression * @param maxValues maximum number of values to send with each notification * @return a new expression */ public static <T> DesiredRateExpression<List<T>> newValuesOf(SourceRateExpression<T> expression, int maxValues) { return new DesiredRateExpressionImpl<List<T>>(expression, new QueueCollector<T>(maxValues), expression.getName()); }
@Override public void update(MultiAxisLineGraph2DRendererUpdate update) { ((MultiAxisLineGraph2DFunction) getFunction()).getRendererUpdateQueue().writeValue(update); }
@Override public Graph2DResult readValue() { VNumberArray data = arrayData.readValue(); // Data must be available if (data == null) { return null; } // TODO: check array is one dimensional Cell1DDataset dataset = null; dataset = DatasetConversions.cell1DDatasetsFromVNumberArray(data); // Process all renderer updates for (AreaGraph2DRendererUpdate rendererUpdate : getUpdateQueue().readValue()) { renderer.update(rendererUpdate); } // If no size is set, don't calculate anything if (renderer.getImageHeight() == 0 && renderer.getImageWidth() == 0) return null; BufferedImage image = new BufferedImage(renderer.getImageWidth(), renderer.getImageHeight(), BufferedImage.TYPE_3BYTE_BGR); renderer.draw(image.createGraphics(), dataset); int index = -1; if (renderer.getFocusValueIndex() != null) { index = renderer.getFocusValueIndex(); } return new Graph2DResult(data, ValueUtil.toVImage(image), new GraphDataRange(renderer.getXPlotRange(), dataset.getXRange(), dataset.getXRange()), new GraphDataRange(renderer.getYPlotRange(), dataset.getStatistics().getRange(), renderer.getYAggregatedRange()), index); }
PVWriterDirector(PVWriterImpl<T> pvWriter, WriteFunction<T> writeFunction, DataSource dataSource, ScheduledExecutorService writeExecutor, Executor notificationExecutor, ScheduledExecutorService scannerExecutor, Duration writeTimeout, String writeTimeoutMessage, ExceptionHandler exceptionHandler) { this.pvRef = new WeakReference<>(pvWriter); this.writeFunction = writeFunction; this.dataSource = dataSource; this.writeExecutor = writeExecutor; this.notificationExecutor = notificationExecutor; this.scannerExecutor = scannerExecutor; this.timeout = writeTimeout; this.timeoutMessage = writeTimeoutMessage; if (exceptionHandler == null) { writeExceptionCollector = new QueueCollector<>(1); } else { writeExceptionCollector = new LastExceptionCollector(1, exceptionHandler); } }
@Override public void update(BubbleGraph2DRendererUpdate update) { ((BubbleGraph2DFunction) getFunction()).getRendererUpdateQueue().writeValue(update); }
.readValue(); for (ScatterGraph2DRendererUpdate scatterGraph2DRendererUpdate : updates) { renderer.update(scatterGraph2DRendererUpdate);