diff --git a/plugins-dev/cloud/src/java/pt/lsts/ripples/RipplesUpdater.java b/plugins-dev/cloud/src/java/pt/lsts/ripples/RipplesUpdater.java index 4dc1123935..6df4b59117 100644 --- a/plugins-dev/cloud/src/java/pt/lsts/ripples/RipplesUpdater.java +++ b/plugins-dev/cloud/src/java/pt/lsts/ripples/RipplesUpdater.java @@ -222,36 +222,43 @@ private RipplesPlan pcsToRipplesPlan(PlanControlState pcs) { @Periodic(millisBetweenUpdates = 1000) public void sendUpdatesToRipples() { - if (!this.connected) + if (!this.connected) { return; - ArrayList payload = new ArrayList<>(); - assetStates.forEach((sysName, assetState) -> { - PlanControlState pcs = planStates.get(sysName); - RipplesPlan plan = new RipplesPlan(); - if (pcs != null) { - plan = pcsToRipplesPlan(pcs); - } - ImcSystem imcSystem = ImcSystemsHolder.lookupSystemByName(sysName); - int imcId = (imcSystem != null && imcSystem.getId() != null) ? imcSystem.getId().intValue() : -1; - payload.add(new RipplesAsset(sysName, imcId, assetState, plan)); - NeptusLog.pub().debug("Asset state: " + assetState); - }); + } - String assetsAsJson = gson.toJson(payload); try { - NeptusLog.pub().info("Sending update for " + payload.size() + " assets"); - sendPost(assetsAsJson); - } - catch (IOException e) { - e.printStackTrace(); - } + ArrayList payload = new ArrayList<>(); + assetStates.forEach((sysName, assetState) -> { + PlanControlState pcs = planStates.get(sysName); + RipplesPlan plan = new RipplesPlan(); + if (pcs != null) { + plan = pcsToRipplesPlan(pcs); + } + ImcSystem imcSystem = ImcSystemsHolder.lookupSystemByName(sysName); + int imcId = (imcSystem != null && imcSystem.getId() != null) ? imcSystem.getId().intValue() : -1; + payload.add(new RipplesAsset(sysName, imcId, assetState, plan)); + NeptusLog.pub().debug("Asset state: " + assetState); + }); + + try { + String assetsAsJson = gson.toJson(payload); + NeptusLog.pub().info("Sending update for " + payload.size() + " assets"); + sendPost(assetsAsJson); + } + catch (Exception e) { + NeptusLog.pub().warn(e.getMessage()); + } - synchronized (assetStates) { - assetStates.clear(); + synchronized (assetStates) { + assetStates.clear(); + } + } + catch (Exception e) { + NeptusLog.pub().warn(e.getMessage()); } } - private String sendPost(String data) throws IOException { + private String sendPost(String data) throws Exception { if (this.connected) { URL url = new URL(this.ripplesPostUrl); HttpURLConnection con = (HttpURLConnection) url.openConnection();