2626import org .epics .vtype .VType ;
2727import org .phoebus .framework .macros .MacroHandler ;
2828import org .phoebus .framework .macros .MacroValueProvider ;
29- import org .phoebus .pv .PVPool .TypedName ;
3029
3130import java .util .ArrayList ;
3231import java .util .Collection ;
@@ -107,7 +106,8 @@ public class WidgetRuntime<MW extends Widget> {
107106 */
108107 // This is empty for most widgets, or contains very few PVs,
109108 // so using List with linear lookup by name and not a HashMap
110- private volatile List <RuntimePV > writable_pvs = null ;
109+ // Set pv_name as Key to find the corresponding RuntimePV
110+ private volatile Map <String ,RuntimePV > writable_pvs = null ;
111111
112112 /**
113113 * Handlers for widget's behaviorScripts property,
@@ -230,16 +230,14 @@ public void start() {
230230 // Prepare action-related PVs
231231 final List <ActionInfo > actions = widget .propActions ().getValue ().getActions ();
232232 if (actions .size () > 0 ) {
233- final List < RuntimePV > action_pvs = new ArrayList <>();
233+ final Map < String , RuntimePV > action_pvs = new HashMap <>();
234234 for (final ActionInfo action : actions ) {
235235 if (action instanceof WritePVAction ) {
236236 final String pv_name = ((WritePVAction ) action ).getPV ();
237237 try {
238238 final String expanded = MacroHandler .replace (widget .getMacrosOrProperties (), pv_name );
239- // Manage default datasource if not ca
240- final TypedName type_name = TypedName .analyze (expanded );
241- final RuntimePV pv = PVFactory .getPV (type_name .toString ());
242- action_pvs .add (pv );
239+ final RuntimePV pv = PVFactory .getPV (expanded );
240+ action_pvs .put (expanded , pv );
243241 addPV (pv , true );
244242 } catch (Exception ex ) {
245243 logger .log (Level .WARNING , widget + " cannot start action to write PV '" + pv_name + "'" , ex );
@@ -398,12 +396,8 @@ public void writePrimaryPV(final Object value) {
398396 public void writePV (final String pv_name , final Object value ) throws Exception {
399397 final String expanded = MacroHandler .replace (widget .getMacrosOrProperties (), pv_name );
400398 String name_to_check = expanded ;
401- // Check for default datasource to manage custom datasource
402- final TypedName type_name = TypedName .analyze (name_to_check );
403- name_to_check = type_name != null ? type_name .toString () : name_to_check ;
404- String dataType = type_name != null ? type_name .type : null ;
405399 // For local PV,
406- if (dataType != null && dataType . equals ("loc" )) {
400+ if (name_to_check . startsWith ("loc:// " )) {
407401 // strip optional data type ...
408402 int sep = name_to_check .indexOf ('<' );
409403 if (sep > 0 )
@@ -414,18 +408,20 @@ public void writePV(final String pv_name, final Object value) throws Exception {
414408 name_to_check = name_to_check .substring (0 , sep );
415409 }
416410 awaitStartup ();
417- final List < RuntimePV > safe_pvs = writable_pvs ;
418- if (safe_pvs != null )
419- for ( final RuntimePV pv : safe_pvs )
420- if (pv . getName (). equals ( name_to_check ) ) {
411+ final Map < String , RuntimePV > safe_pvs = writable_pvs ;
412+ if (safe_pvs != null ) {
413+ final RuntimePV pv = safe_pvs . get ( name_to_check );
414+ if (pv != null ) {
421415 try {
422416 pv .write (value );
423417 } catch (final Exception ex ) {
424418 throw new Exception ("Failed to write " + value + " to PV " + name_to_check , ex );
425419 }
426- return ;
427420 }
428- throw new Exception ("Unknown PV '" + pv_name + "' (expanded: '" + name_to_check + "')" );
421+ else {
422+ throw new Exception ("Unknown PV '" + pv_name + "' (expanded: '" + name_to_check + "')" );
423+ }
424+ }
429425 }
430426
431427 /**
@@ -448,13 +444,15 @@ public void stop() {
448444 awaitStartup ();
449445 widget .propClass ().removePropertyListener (update_widget_class );
450446
451- final List <RuntimePV > safe_pvs = writable_pvs ;
452- if (safe_pvs != null ) {
453- for (final RuntimePV pv : safe_pvs ) {
454- removePV (pv );
455- PVFactory .releasePV (pv );
447+ if (writable_pvs != null && !writable_pvs .isEmpty ()) {
448+ final Collection <RuntimePV > safe_pvs = writable_pvs .values ();
449+ if (safe_pvs != null ) {
450+ for (final RuntimePV pv : safe_pvs ) {
451+ removePV (pv );
452+ PVFactory .releasePV (pv );
453+ }
454+ writable_pvs = null ;
456455 }
457- writable_pvs = null ;
458456 }
459457
460458 final PVNameToValueBinding binding = pv_name_binding .getAndSet (null );
0 commit comments