From 0b18e94e685c509b6bbcd8998fad62e8ce0b12d3 Mon Sep 17 00:00:00 2001
From: Bruno Bonte <bonte.bruno@gmail.com>
Date: Wed, 25 Nov 2020 12:20:19 +0100
Subject: [PATCH] Add a debug mode for J2KCoupling

* new jams components J2K_couplage_cowat.jar
* Adding an attribute debugMode to Coupling communicaiton
modules of jams files set to "true"
* -> effect: if set to true, jams keep listening for One hour
instead of 2 minutes which allows to start and stop simulation at will
---
 jamsmodel/j2k_cowat_buech_ju_couplage.jam |  1 +
 modules/CouplingCommunication.java        | 15 +++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/jamsmodel/j2k_cowat_buech_ju_couplage.jam b/jamsmodel/j2k_cowat_buech_ju_couplage.jam
index 7665a13..5673678 100644
--- a/jamsmodel/j2k_cowat_buech_ju_couplage.jam
+++ b/jamsmodel/j2k_cowat_buech_ju_couplage.jam
@@ -196,6 +196,7 @@
             <var attribute="HRUS" context="J2K_RHONE" name="hrus"/>
             <var attribute="time" context="J2K_RHONE" name="time"/>
 						<var attribute="Runoff" context="TimeLoop" name="catchmentSimRunoff"/>
+            <var name="debugMode" value="true"/>
         </component>
         <component class="jams.components.gui.JAMSExecInfo" enabled="true" name="JAMSExecInfo" version="1.1_0"/>
         <component class="org.unijena.j2k.DoubleSetter" enabled="true" name="DoubleSetter" version="1.0_0">
diff --git a/modules/CouplingCommunication.java b/modules/CouplingCommunication.java
index 150ae19..d809b5d 100644
--- a/modules/CouplingCommunication.java
+++ b/modules/CouplingCommunication.java
@@ -104,6 +104,12 @@ public class CouplingCommunication extends JAMSComponent {
     )
     public Attribute.Double catchmentSimRunoff;
     
+        @JAMSVarDescription(
+            access = JAMSVarDescription.AccessType.READ,
+            description = "Tell if we run in debug mode (no timeout)"
+    )
+    public Attribute.Boolean debugMode;
+    
     public void init() {
         singleton = this;
         //double t = 1;
@@ -919,8 +925,13 @@ public class CouplingCommunication extends JAMSComponent {
                     client.close(); // Close the socket itself
 
                     // launch timeout
-                    startTimeout(120);
-
+                    System.err.println("debug mode is: " + debugMode.getValue() + "\n");
+                    if (debugMode.getValue() == true)
+                    {
+                        startTimeout(3600);
+                    } else {
+                        startTimeout(120);
+                    }
                 } // Now loop again, waiting for the next connection
             } // If anything goes wrong, print an error message
             catch (Exception e) {
-- 
GitLab