@Override public void close() { // TODO: close client super.close(); }
@Override public Map<String, ChannelHandler> getChannels() { Map<String, ChannelHandler> channels = new HashMap<String, ChannelHandler>(); for (Entry<String, DataSource> entry : dataSources.entrySet()) { String dataSourceName = entry.getKey(); DataSource dataSource = entry.getValue(); for (Entry<String, ChannelHandler> channelEntry : dataSource.getChannels().entrySet()) { String channelName = channelEntry.getKey(); ChannelHandler channelHandler = channelEntry.getValue(); channels.put(dataSourceName + conf.delimiter + channelName, channelHandler); } } return channels; }
@Override ChannelHandler channel(String channelName) { String name = nameOf(channelName); String dataSource = sourceOf(channelName); return dataSources.get(dataSource).channel(name); }
/** * Returns a channel from the given name, either cached or it * will create it. * * @param channelName name of a channel * @return a new or cached handler */ ChannelHandler channel(String channelName) { ChannelHandler channel = usedChannels.get(channelHandlerLookupName(channelName)); if (channel == null) { channel = createChannel(channelName); if (channel == null) return null; usedChannels.put(channelHandlerRegisterName(channelName, channel), channel); } return channel; }
if (!isWriteable()) { throw new RuntimeException("Data source is read only"); try { String channelName = channelWriteRecipe.getChannelName(); ChannelHandler handler = channel(channelName);
@Override public void connectRead(ReadRecipe readRecipe) { Map<String, ReadRecipe> splitRecipe = splitRecipe(readRecipe); // Dispatch calls to all the data sources for (Map.Entry<String, ReadRecipe> entry : splitRecipe.entrySet()) { try { retrieveDataSource(entry.getKey()).connectRead(entry.getValue()); } catch (RuntimeException ex) { // If data source fail, still go and connect the others readRecipe.getChannelReadRecipes().iterator().next().getReadSubscription().getExceptionWriteFunction().writeValue(ex); } } }
/** * Returns the name the given handler should be registered as. * By default, it returns the lookup name, so that lookup and * registration in the cache are consistent. If a datasource * needs multiple different channel names to be the same * channel handler (e.g. parts of the channel name are read/write * parameters) then it can override this method to change the * registration. * * @param channelName the name under which the ChannelHandler was created * @param handler the handler to register * @return the name under which to register in the cache */ protected String channelHandlerRegisterName(String channelName, ChannelHandler handler) { return channelHandlerLookupName(channelName); }
if (!isWriteable()) { throw new RuntimeException("Data source is read only"); try { String channelName = channelWriteRecipe.getChannelName(); ChannelHandler handler = channel(channelName); if (handler == null) { throw new RuntimeException("Channel " + channelName + " does not exist");
/** * Connects the given expression. * <p> * This can be used for dynamic expression to add and connect child expressions. * The added expression will be automatically closed when the associated * reader is closed, if it's not disconnected first. * * @param expression the expression to connect */ public void connectReadExpression(DesiredRateExpression<?> expression) { ReadRecipeBuilder builder = new ReadRecipeBuilder(); expression.fillReadRecipe(this, builder); ReadRecipe recipe = builder.build(readExceptionCollector, readConnCollector); synchronized(lock) { readRecipies.put(expression, recipe); } if (!recipe.getChannelReadRecipes().isEmpty()) { try { dataSource.connectRead(recipe); } catch(Exception ex) { recipe.getChannelReadRecipes().iterator().next().getReadSubscription().getExceptionWriteFunction().writeValue(ex); } } }
@Override public void close() { exec.shutdownNow(); super.close(); }
if (!isWriteable()) throw new UnsupportedOperationException("This data source is read only"); ChannelHandler channel = channel(channelWriteRecipe.getChannelName()); planner.addChannel(channel, channelWriteRecipe.getWriteSubscription().getWriteCache().getValue(), channelWriteRecipe.getWriteSubscription().getWriteCache().getPrecedingChannels());
private void channelDetailsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_channelDetailsButtonActionPerformed try { ChannelHandler handler = PVManager.getDefaultDataSource().getChannels().get(pvName.getText()); if (handler != null) { Map<String, Object> properties = handler.getProperties(); StringBuilder builder = new StringBuilder(); builder.append("Channel properties:\n"); for (Map.Entry<String, Object> entry : properties.entrySet()) { String string = entry.getKey(); Object object = entry.getValue(); builder.append(string).append(" = ").append(object).append("\n"); } JOptionPane.showMessageDialog(this, builder.toString()); } } catch (RuntimeException e) { e.printStackTrace(); } }//GEN-LAST:event_channelDetailsButtonActionPerformed PVReader<?> pv;
} else { String channelName = channelRecipe.getChannelName(); ChannelHandler channelHandler = channel(channelName);
/** * Closes all DataSources that are registered in the composite. */ @Override public void close() { for (DataSource dataSource : dataSources.values()) { dataSource.close(); } }
try { String channelName = channelRecipe.getChannelName(); ChannelHandler channelHandler = channel(channelName); if (channelHandler == null) { throw new RuntimeException("Channel named '" + channelName + "' not found");
@Override public void close() { super.close(); ctxt.dispose(); }
public static void main(String[] args) throws Exception { System.out.println("Starting pv"); PVReader<VNumber> reader = PVManager.read(vNumber("sim://gaussianNoise()")) .readListener(new PVReaderListener<VNumber>() { @Override public void pvChanged(PVReaderEvent<VNumber> event) { if (event.isValueChanged()) { System.out.println("... value is " + event.getPvReader().getValue().getValue()); } } }) .maxRate(Duration.ofMillis(500)); Thread.sleep(2000); System.out.println("Voiding reference"); reader = null; Thread.sleep(100); System.out.println("Garbage collecting"); System.gc(); Thread.sleep(3000); System.out.println("Closing..."); PVManager.getDefaultDataSource().close(); System.out.println("Done"); } }
public static void main(String[] args) throws Exception { // Increasing logging at CONFIG level Logger.getLogger("").getHandlers()[0].setLevel(Level.CONFIG); Logger.getLogger("").setLevel(Level.CONFIG); System.out.println("Open channel"); PVReader<VNumber> reader = PVManager.read(vNumber("sim://noise")) .readListener(new PVReaderListener<VNumber>() { @Override public void pvChanged(PVReaderEvent<VNumber> event) { if (event.isValueChanged()) { System.out.println("... value is " + event.getPvReader().getValue().getValue()); } } }) .maxRate(Duration.ofMillis(500)); Thread.sleep(2000); System.out.println("Close channel"); reader.close(); Thread.sleep(1000); System.out.println("Close data source"); PVManager.getDefaultDataSource().close(); System.out.println("Done"); } }
PVManager.getDefaultDataSource().close(); System.out.println("Done");
public static void main(String[] args) throws Exception { //System.setProperty("com.cosylab.epics.caj.CAJContext.max_array_bytes", "20000000"); PVManager.setDefaultDataSource(new SimulationDataSource()); final PVReader<Object> reader = PVManager.read(channel("gaussian()")) .readListener(new PVReaderListener<Object>() { @Override public void pvChanged(PVReaderEvent<Object> event) { System.out.println("Monitor called"); } }) .maxRate(Duration.ofMillis(10)); Thread.sleep(10000); reader.close(); System.out.println("After five seconds"); Thread.sleep(10000); System.out.println("After another five seconds"); PVManager.getDefaultDataSource().close(); System.out.println("Done"); } }