/** * Adds a listener for the write events. * * @param listener the new listener * @return this expression */ public PVConfiguration<R, W> writeListener(PVWriterListener<? extends W> listener) { pvWriterConfiguration.writeListener(listener); return this; }
/** * Writes the given expression, and returns an object to configure the parameters * for the write. * * @param <T> type of the write payload * @param writeExpression the expression to write * @return the write configuration */ public static <T> PVWriterConfiguration<T> write(WriteExpression<T> writeExpression) { return new PVWriterConfiguration<T>(writeExpression); }
private PVWriter<T> create(boolean syncWrite) { validateWriterConfiguration(); checkDataSourceAndThreadSwitch(); preparePvWriter(syncWrite); PVWriterDirector<T> writerDirector = prepareDirector(this); prepareDecoupler(writerDirector, this); return pvWriter; }
public void b3_asynchronousWrite() { PVWriter<Object> pvWriter = PVManager.write(channel("channelName")) .writeListener(new PVWriterListener<Object>() { public void pvChanged(PVWriterEvent<Object> event) { if (event.isWriteSucceeded()) { System.out.println("Write finished"); } } }) .async(); // This will return right away, and the notification will be sent // on the listener pvWriter.write("New value"); // Remember to close pvWriter.close(); }
@Override @SuppressWarnings("unchecked") public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if (columnIndex > 2) { throw new RuntimeException(); } if (columnIndex == 1) { writePvValues.set(rowIndex, aValue.toString()); pvWriters.get(rowIndex).write(aValue.toString()); } else { String name = aValue.toString(); try { if (rowIndex == writePvNames.size()) { pvWriters.add(PVManager.write(channel(name)).async()); writePvNames.add(name); writePvValues.add(""); } else { pvWriters.set(rowIndex, PVManager.write(channel(name)).async()); writePvNames.set(rowIndex, name); writePvValues.set(rowIndex, ""); } fireTableDataChanged(); } catch (Exception ex) { JOptionPane.showMessageDialog(MockDynamicTablePVFrame.this, ex.getMessage(), "Can't open pv", JOptionPane.ERROR_MESSAGE); } } }
/** * 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); }
/** * Creates a new PVWriter where the {@link PVWriter#write(java.lang.Object) } * method is synchronous (i.e. blocking). * * @return a new PVWriter */ public PVWriter<T> sync() { return create(true); }
@Override public PVConfiguration<R, W> from(DataSource dataSource) { pvReaderConfiguration.from(dataSource); pvWriterConfiguration.from(dataSource); return this; }
@Override public PVConfiguration<R, W> notifyOn(Executor onThread) { pvReaderConfiguration.notifyOn(onThread); pvWriterConfiguration.notifyOn(onThread); return this; }
public void m2_readMultipleChannels() { // Write a map to the channels named "one", "two" and "three" PVWriter<Map<String, Object>> pvWriter = PVManager .write(mapOf(channels("one", "two", "three"))) .async(); // Prepare the 3 values Map<String, Object> values = new HashMap<String, Object>(); values.put("one", 1.0); values.put("two", 2.0); values.put("three", "run"); // Write pvWriter.write(values); // Remember to close pvWriter.close(); // Note that when using a composite datasource, the channels can be //from different sources (e.g. "sim://noise" and "ca://mypv"). }
public void b4_synchronousWrite() { PVWriter<Object> pvWriter = PVManager.write(channel("channelName")).sync(); // This will block until the write is done pvWriter.write("New value"); System.out.println("Write finished"); // Remember to close pvWriter.close(); }
/** * Creates a new PVWriter where the {@link PVWriter#write(java.lang.Object) } * method is asynchronous (i.e. non-blocking). * * @return a new PVWriter */ public PVWriter<T> async() { return create(false); } }
.async(); System.out.println("Write sim://noise to " + pvNamePv); namePv.write("sim://noise");
PVConfiguration(DesiredRateReadWriteExpression<R, W> readWriteExpression) { pvReaderConfiguration = new PVReaderConfiguration<R>(readWriteExpression); pvWriterConfiguration = new PVWriterConfiguration<W>(readWriteExpression); }
/** * Creates the pv such that writes are asynchronous 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> asynchWriteAndMaxReadRate(Duration period) { PVReader<R> pvReader = pvReaderConfiguration.maxRate(period); PVWriter<W> pvWriter = pvWriterConfiguration.async(); PV<R, W> pv = new PV<R, W>(pvReader, pvWriter); // XXX: This should really be set before the scanning starts PVReaderImpl.implOf(pvReader).setReaderForNotification(pv); PVWriterImpl.implOf(pvWriter).setWriterForNotification(pv); return pv; }
public void m5_writeOrdering() { // Write a map to the channels named "one", "two" and "three" // Write "two" after "one" and write "three" after "two" PVWriter<Map<String, Object>> pvWriter = PVManager.write( mapOf(channel("one") .and(channel("two").after("one")) .and(channel("three").after("two")))).async(); // Do something // ... // Remember to close pvWriter.close(); } }