@Override @SuppressWarnings("unchecked") public void fillWriteRecipe(PVWriterDirector director, WriteRecipeBuilder builder) { synchronized(lock) { this.director = director; for (Map.Entry<String, WriteExpression<T>> entry : expressions.entrySet()) { WriteExpression<T> writeExpression = entry.getValue(); director.connectExpression(writeExpression); } } }
public ScannerParameters writerDirector(PVWriterDirector director) { this.listener = director.getDesiredRateEventListener(); return this; }
@Override public void write(T newValue) { // Safely taking the write directory // the whole method can't be in a synchronized block, or // it would block the notifications in case of syncWrite // and would deadlock PVWriterDirector<T> director; synchronized(lock) { director = writeDirector; } if (syncWrite) { director.syncWrite(newValue, this); } else { director.write(newValue, this); } }
static <T> PVWriterDirector<T> prepareDirector(PVWriterConfiguration<T> writerConfiguration) { PVWriterDirector<T> writerDirector = new PVWriterDirector<T>(writerConfiguration.pvWriter, writerConfiguration.writeFunction, writerConfiguration.dataSource, PVManager.getAsyncWriteExecutor(), writerConfiguration.notificationExecutor, PVManager.getReadScannerExecutorService(), writerConfiguration.timeout, writerConfiguration.timeoutMessage, writerConfiguration.exceptionHandler); writerDirector.connectExpression(writerConfiguration.writeExpression); writerConfiguration.pvWriter.setWriteDirector(writerDirector); return writerDirector; }
/** * */ public void close() { synchronized(lock) { scanStrategy.stop(); while (!recipes.isEmpty()) { WriteExpression<?> expression = recipes.keySet().iterator().next(); disconnectExpression(expression); } } }
/** * De-registers all listeners, stops all notifications and closes all * connections from the data sources needed by this. Once the PV * is closed, it can't be re-opened. Subsequent calls to close do not * do anything. */ @Override public void close() { synchronized(lock) { if (closed) { return; } closed = true; } pvWriterListeners.clear(); PVWriterDirector<T> director; synchronized(lock) { director = writeDirector; } director.close(); }
@Override public void fillWriteRecipe(PVWriterDirector director, WriteRecipeBuilder builder) { super.fillWriteRecipe(director, builder); director.connectStatic(new RuntimeException(errorMessage), false, getName()); }
static <T> void prepareDecoupler(PVWriterDirector<T> director, PVWriterConfiguration<T> writerConfiguration) { ScannerParameters scannerParameters = new ScannerParameters() .writerDirector(director) .scannerExecutor(PVManager.getReadScannerExecutorService()) .maxDuration(Duration.ofMillis(100)); scannerParameters.type(ScannerParameters.Type.PASSIVE); SourceDesiredRateDecoupler rateDecoupler = scannerParameters.build(); director.setScanner(rateDecoupler); rateDecoupler.start(); }
/** * Removes the expression with the given name. * * @param name the name of the expression to remove * @return this expression */ public WriteMap<T> remove(String name) { synchronized(lock) { if (!expressions.containsKey(name)) { throw new IllegalArgumentException("MapExpression does not contain an expression named '" + name + "'"); } getMapOfWriteFunction().getMapUpdateCollector().writeValue(MapUpdate.<T>removeFunction(name)); WriteExpression<T> expression = expressions.remove(name); if (director != null) { director.disconnectExpression(expression); } return this; } }
/** * Removes all the expressions currently in the map. * * @return this expression */ public WriteMap<T> clear() { synchronized(lock) { getMapOfWriteFunction().getMapUpdateCollector().writeValue(MapUpdate.<T>clear()); if (director != null) { for (WriteExpression<T> desiredRateExprewritession : expressions.values()) { director.disconnectExpression(desiredRateExprewritession); } } expressions.clear(); return this; } }
/** * Adds the expression to the map. * * @param expression the expression to be added * @return this expression */ public WriteMap<T> add(WriteExpression<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() + "'"); } getMapOfWriteFunction().getMapUpdateCollector().writeValue(MapUpdate.addWriteFunction(expression.getName(), expression.getWriteFunction())); expressions.put(expression.getName(), expression); if (director != null) { director.connectExpression(expression); } return this; } }