@Override @SuppressWarnings("unchecked") public void fillReadRecipe(PVDirector director, ReadRecipeBuilder builder) { synchronized(lock) { this.director = director; for (Map.Entry<String, DesiredRateExpression<T>> entry : expressions.entrySet()) { DesiredRateExpression<T> readExpression = entry.getValue(); director.connectReadExpression(readExpression); } } }
if (newNames.get(i) != null && newExpressions.get(i) == null) { DesiredRateExpression<?> newExpression = channel(newNames.get(i), Object.class); getDirector().connectReadExpression(newExpression); newExpressions.set(i, newExpression);
/** * Adds the expression to the map. * * @param expression the expression to be added * @return this expression */ public ReadMap<T> add(DesiredRateExpression<T> expression) { synchronized(lock) { if (expression.getName() == null) { throw new NullPointerException("Expression has a null name"); } if (expressions.containsKey(expression.getName())) { throw new IllegalArgumentException("MapExpression already contain an expression named '" + expression.getName() + "'"); } getMapOfFunction().getMapUpdateCollector().writeValue(MapUpdate.addReadFunction(expression.getName(), expression.getFunction())); expressions.put(expression.getName(), expression); if (director != null) { director.connectReadExpression(expression); } return this; } }
@Override public Object calculate(final List<Object> args) { // Retrieve the new name VString value = (VString) args.get(0); String newName = null; if (value != null) { newName = value.getValue(); } // If the name does not match, disconnect and connect if (!Objects.equals(newName, previousName)) { // Disconnect previous if (currentExpression != null) { getDirector().disconnectReadExpression(currentExpression); currentExpression = null; } // Connect new if (newName != null) { currentExpression = channel(newName, Object.class); getDirector().connectReadExpression(currentExpression); } previousName = newName; } // Return value if (newName == null) { return null; } return currentExpression.getFunction().readValue(); }
static <T> void prepareDecoupler(PVDirector<T> director, PVReaderConfiguration<T> readConfiguration) { ScannerParameters scannerParameters = new ScannerParameters() .readerDirector(director) .scannerExecutor(PVManager.getReadScannerExecutorService()) .maxDuration(readConfiguration.maxRate); if (readConfiguration.aggregatedFunction instanceof Collector || readConfiguration.aggregatedFunction instanceof ValueCache) { scannerParameters.type(ScannerParameters.Type.PASSIVE); } else { scannerParameters.type(ScannerParameters.Type.ACTIVE); } SourceDesiredRateDecoupler rateDecoupler = scannerParameters.build(); readConfiguration.pv.setDirector(director); director.setScanner(rateDecoupler); director.connectReadExpression(readConfiguration.aggregatedPVExpression); rateDecoupler.start(); }