/** Connect to PVs */ public void start() throws Exception { if (pv_basename == null) return; jumper_pv = PVPool.getPV(pv_basename + "_sw_jump_status"); jumper_pv.addListener(jumper_pv_listener); mask_pv = PVPool.getPV(pv_basename + "_swmask"); mask_pv.addListener(mask_pv_listener); }
/** Start archiving this channel. */ final void start() throws Exception { is_running = true; need_first_sample = true; final PV pv = PVPool.getPV(name); pv.addListener(this); synchronized (this) { if (this.pv != null) throw new Exception(name + " started twice"); this.pv = pv; } }
/** Stop archiving this channel */ final void stop() { if (!is_running) return; is_running = false; final PV safe_pv; synchronized (this) { safe_pv = pv; pv = null; } safe_pv.removeListener(this); PVPool.releasePV(safe_pv); addInfoToBuffer(ValueButcher.createOff()); }
// ChannelPutRequester @Override public void putDone(final Status status, final ChannelPut channelPut) { if (status.isSuccess()) logger.log(Level.FINE, "Write {0} = {1} completed", new Object[] {pv.getName(), new_value}); else { error = new Exception( "Write " + pv.getName() + " = " + new_value + " failed, " + status.toString()); logger.log(Level.WARNING, "", error); } updates.countDown(); channelPut.destroy(); }
/** Disconnect PVs */ public void stop() { if (pv_basename == null) return; mask_pv.removeListener(mask_pv_listener); jumper_pv.removeListener(jumper_pv_listener); PVPool.releasePV(jumper_pv); PVPool.releasePV(mask_pv); state = BypassState.Disconnected; // Does NOT notify listener // because the way this is used the listener // will soon see a different list of bypasses // or close down. // Either way, no update needed. }
// Future @Override public Object get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (!updates.await(timeout, unit)) throw new TimeoutException(pv.getName() + " write timeout"); if (error != null) throw new ExecutionException(error); return null; }
// ChannelPutRequester @Override public void channelPutConnect( final Status status, final ChannelPut channelPut, final Structure structure) { if (!status.isSuccess()) { error = new Exception("Failed to connect 'put' for " + pv.getName() + ": " + status); updates.countDown(); return; } try { final PVStructure write_structure = PVDataFactory.getPVDataCreate().createPVStructure(structure); final BitSet bit_set = new BitSet(write_structure.getNumberFields()); // Locate the value field at deepest level in structure PVField field = null; PVStructure search = write_structure; while (search != null) { final PVField[] fields = search.getPVFields(); if (fields.length != 1) throw new Exception( "Can only write to simple struct.element.value path, got " + structure); if (fields[0].getFieldName().equals("value")) { field = fields[0]; break; } else if (fields[0] instanceof PVStructure) search = (PVStructure) fields[0]; else search = null; } if (field == null) throw new Exception("Cannot locate 'value' to write in " + structure); // Enumerated? Write to value.index if (field instanceof PVStructure && "enum_t".equals(field.getField().getID())) field = ((PVStructure) field).getSubField("index"); // Indicate what's changed & change it bit_set.set(field.getFieldOffset()); PVStructureHelper.setField(field, new_value); // Perform write channelPut.put(write_structure, bit_set); } catch (Exception ex) { logger.log(Level.WARNING, "Failed to write " + pv.getName() + " = " + new_value, ex); error = new Exception("Failed to write " + pv.getName() + " = " + new_value, ex); updates.countDown(); } }
/** @return Human-readable info on internal state of PV */ public synchronized String getInternalState() { if (pv == null) return "Not initialized"; return pv.read() != null ? "Connected" : "Disconnected"; }
/** @return <code>true</code> if connected */ public final synchronized boolean isConnected() { return pv != null && pv.read() != null; }
@Override public void disconnected(PV pv) { logger.log(Level.WARNING, "Mask PV Disconnected: " + pv.getName()); updateState(jumper, null); }
@Override public void disconnected(PV pv) { logger.log(Level.WARNING, "Jumper PV Disconnected: " + pv.getName()); updateState(null, mask); }
/** @return Name of the Mask PV, for example "Ring_Vac:SGV_AB:FPL_Ring_swmask" */ public String getMaskPVName() { return mask_pv.getName(); }
/** @return Name of the Jumper PV, for example "Ring_Vac:SGV_AB:FPL_Ring_sw_jump_status" */ public String getJumperPVName() { return jumper_pv.getName(); }