/** * Set a NamedBean (Turnout, Sensor, SignalHead, ...) to a specific value in a thread-safe way. * * <p>You can't assume that all the consequences of that setting will have propagated through when * this returns; those might take a long time. But the set operation itself will be complete. * * @param NamedBean * @param state */ public static void setBeanState(NamedBean bean, int state) { try { javax.swing.SwingUtilities.invokeAndWait( () -> { try { bean.setState(state); } catch (JmriException e) { log.error("Threw exception while setting state: ", e); } }); } catch (InterruptedException e) { log.warn("Interrupted while setting state: ", e); } catch (InvocationTargetException e) { log.warn("Failed during invocation while setting state: ", e); } }