altos-map: Retry connection to cache service
authorKeith Packard <keithp@keithp.com>
Sun, 7 Oct 2018 04:25:48 +0000 (22:25 -0600)
committerKeith Packard <keithp@keithp.com>
Sun, 7 Oct 2018 04:25:48 +0000 (22:25 -0600)
Just in case the cache service gets busy, retry the connection instead
of immediately failing.

Signed-off-by: Keith Packard <keithp@keithp.com>
map-server/altos-map/AltosMap.java

index 380556f..d78396d 100644 (file)
@@ -109,7 +109,17 @@ public class AltosMap {
                        fail(400, "Missing zoom");
 
                try {
-                       Socket  socket = new Socket(InetAddress.getLoopbackAddress(), port);
+                       Socket  socket = null;
+                       int tries = 0;
+
+                       while (tries < 10 && socket == null) {
+                               try {
+                                       socket = new Socket(InetAddress.getLoopbackAddress(), port);
+                               } catch (IOException ie) {
+                                       Thread.sleep(100);
+                                       tries++;
+                               }
+                       }
 
                        AltosJson       request = new AltosJson();