From c058cc57eff7855489bb87164895c3280d562ee2 Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Fri, 19 Aug 2022 06:50:18 +0200 Subject: [PATCH] Configurable map polling --- .../java/btools/mapcreator/OsmParser.java | 37 +++++++++++-------- .../btools/mapcreator/MapcreatorTest.java | 4 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/OsmParser.java b/brouter-map-creator/src/main/java/btools/mapcreator/OsmParser.java index 3fde438..f188031 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/OsmParser.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/OsmParser.java @@ -39,11 +39,14 @@ public class OsmParser extends MapCreatorBase { int rawBlobCount = 0; long bytesRead = 0L; + Boolean avoidMapPolling = Boolean.getBoolean("avoidMapPolling"); - // wait for file to become available - while (!mapFile.exists()) { - System.out.println("--- waiting for " + mapFile + " to become available"); - Thread.sleep(10000); + if (!avoidMapPolling) { + // wait for file to become available + while (!mapFile.exists()) { + System.out.println("--- waiting for " + mapFile + " to become available"); + Thread.sleep(10000); + } } long currentSize = mapFile.length(); @@ -53,18 +56,20 @@ public class OsmParser extends MapCreatorBase { for (; ; ) { - // continue reading if either more then a 100 MB unread, or the current-size is known for more then 2 Minutes - while (currentSize - bytesRead < 100000000L) { - long newSize = mapFile.length(); - if (newSize != currentSize) { - currentSize = newSize; - currentSizeTime = System.currentTimeMillis(); - } else if (System.currentTimeMillis() - currentSizeTime > 120000) { - break; - } - if (currentSize - bytesRead < 100000000L) { - System.out.println("--- waiting for more data, currentSize=" + currentSize + " bytesRead=" + bytesRead); - Thread.sleep(10000); + if (!avoidMapPolling) { + // continue reading if either more then a 100 MB unread, or the current-size is known for more than 2 Minutes + while (currentSize - bytesRead < 100000000L) { + long newSize = mapFile.length(); + if (newSize != currentSize) { + currentSize = newSize; + currentSizeTime = System.currentTimeMillis(); + } else if (System.currentTimeMillis() - currentSizeTime > 120000) { + break; + } + if (currentSize - bytesRead < 100000000L) { + System.out.println("--- waiting for more data, currentSize=" + currentSize + " bytesRead=" + bytesRead); + Thread.sleep(10000); + } } } diff --git a/brouter-map-creator/src/test/java/btools/mapcreator/MapcreatorTest.java b/brouter-map-creator/src/test/java/btools/mapcreator/MapcreatorTest.java index d44d6e1..562d4d2 100644 --- a/brouter-map-creator/src/test/java/btools/mapcreator/MapcreatorTest.java +++ b/brouter-map-creator/src/test/java/btools/mapcreator/MapcreatorTest.java @@ -1,16 +1,16 @@ package btools.mapcreator; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import java.io.File; import java.net.URL; public class MapcreatorTest { - @Ignore("Fails with PBF parser") @Test public void mapcreatorTest() throws Exception { + System.setProperty("avoidMapPolling", "true"); + URL mapurl = this.getClass().getResource("/dreieich.pbf"); Assert.assertNotNull("test-osm-map dreieich.pbf not found", mapurl); File mapFile = new File(mapurl.getFile());