@Override public void onMessage(String type, JsonNode data, Locale locale) throws IOException, JmriException, JsonException { this.locale = locale; String name = data.path(NAME).asText(); if (data.path(METHOD).asText().equals(PUT)) { this.connection.sendMessage(this.service.doPut(type, name, data, locale)); } else { this.connection.sendMessage(this.service.doPost(type, name, data, locale)); } if (!this.signalHeads.containsKey(name)) { SignalHead signalHead = InstanceManager.getDefault(SignalHeadManager.class).getSignalHead(name); if (signalHead != null) { SignalHeadListener listener = new SignalHeadListener(signalHead); signalHead.addPropertyChangeListener(listener); this.signalHeads.put(name, listener); } } }
@Override public void propertyChange(PropertyChangeEvent e) { if (e.getPropertyName().equals("Appearance") || e.getPropertyName().equals("Held")) { try { try { connection.sendMessage( service.doGet(SIGNAL_HEAD, this.signalHead.getSystemName(), locale)); } catch (JsonException ex) { connection.sendMessage(ex.getJsonMessage()); } } catch (IOException ie) { // if we get an error, de-register signalHead.removePropertyChangeListener(this); signalHeads.remove(this.signalHead.getSystemName()); } } }