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; }
@Override public void writeValue(T newValue) { synchronized(forwardFunction) { valueCache.writeValue(newValue); R forwardValue = forwardFunction.readValue(); forwardWriter.writeValue(forwardValue); } }
/** * Creates the pv such that writes are synchronous and read notifications * comes at most at the rate specified. * * @param period minimum time between read notifications * @return a new PV */ public PV<R, W> synchWriteAndMaxReadRate(Duration period) { PVReader<R> pvReader = pvReaderConfiguration.maxRate(period); PVWriter<W> pvWriter = pvWriterConfiguration.sync(); return new PV<R, W>(pvReader, pvWriter); }
public void m3_readWriteMultipleChannels() { // Read and write a map to the channels named "one", "two" and "three" PV<Map<String, Object>, Map<String, Object>> pv = PVManager .readAndWrite(mapOf(latestValueOf(channels("one", "two", "three")))) .asynchWriteAndMaxReadRate(ofMillis(100)); // Do something // ... // Remember to close pv.close(); }
/** * Both reads and writes the given expression, and returns an object to configure the parameters * for the both read and write. It's similar to use both {@link #read(org.diirt.datasource.expression.SourceRateExpression) } * and {@link #write(org.diirt.datasource.expression.WriteExpression) } at the same time. * * @param <R> type of the read payload * @param <W> type of the write payload * @param readWriteExpression the expression to read and write * @return the read and write configuration */ public static <R, W> PVConfiguration<R, W> readAndWrite(SourceRateReadWriteExpression<R, W> readWriteExpression) { return readAndWrite(ExpressionLanguage.latestValueOf(readWriteExpression)); }
@Override public void run() { try { pv.setLastWriteException(lastException); pv.setWriteConnected(connected); pv.firePvWritten(); } finally { notificationInFlight = false; scanStrategy.readyForNextEvent(); } } });
/** * Reads the given expression, and returns an object to configure the parameters * for the read. At each notification it will return the latest value, * even if more had been received from the last notification. * * @param <T> type of the read payload * @param pvExpression the expression to read * @return the read configuration */ public static <T> PVReaderConfiguration<T> read(SourceRateExpression<T> pvExpression) { return new PVReaderConfiguration<T>(ExpressionLanguage.latestValueOf(pvExpression)); }
/** * 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)); } }
void fireWriteFailure(Exception ex) { setLastWriteException(ex); PVWriterEvent<T> event; synchronized(lock) { event = new PVWriterEvent<>(PVWriterEvent.WRITE_FAILED_MASK, writerForNotification); } for (PVWriterListener<T> listener : pvWriterListeners) { listener.pvChanged(event); } }
@Override void newWriteSuccededEvent() { DesiredRateEvent event = new DesiredRateEvent(); event.addType(DesiredRateEvent.Type.WRITE_SUCCEEDED); scheduleWriteOutcome(event); }
static <T> PVDirector<T> prepareDirector(PVReaderConfiguration<T> readConfiguration) { PVDirector<T> director = new PVDirector<>(readConfiguration.pv, readConfiguration.aggregatedFunction, PVManager.getReadScannerExecutorService(), readConfiguration.notificationExecutor, readConfiguration.dataSource, readConfiguration.exceptionHandler); if (readConfiguration.timeout != null) { if (readConfiguration.timeoutMessage == null) readConfiguration.timeoutMessage = "Read timeout"; director.readTimeout(readConfiguration.timeout, readConfiguration.timeoutMessage); } return director; }
@Override public void pvChanged(PVReaderEvent<VType> event) { // We can switch on the full type if (event.getPvReader().getValue() instanceof VDouble) { VDouble vDouble = (VDouble) event.getPvReader().getValue(); // Do something with a VDouble } // ... } })
void fireWriteSuccess() { PVWriterEvent<T> event; synchronized(lock) { event = new PVWriterEvent<>(PVWriterEvent.WRITE_SUCCEEDED_MASK, writerForNotification); } for (PVWriterListener<T> listener : pvWriterListeners) { listener.pvChanged(event); } }
PVConfiguration(DesiredRateReadWriteExpression<R, W> readWriteExpression) { pvReaderConfiguration = new PVReaderConfiguration<R>(readWriteExpression); pvWriterConfiguration = new PVWriterConfiguration<W>(readWriteExpression); }
/** * Specifies a timeout, with a different message for the read and the write. * * @param timeout time before notification * @param readMessage exception message for the read timeout * @param writeMessage exception message for the write timeout * @return this */ public PVConfiguration<R, W> timeout(Duration timeout, String readMessage, String writeMessage) { pvReaderConfiguration.timeout(timeout, readMessage); pvWriterConfiguration.timeout(timeout, writeMessage); return this; }