Configurable map polling

This commit is contained in:
Manuel Fuhr 2022-08-19 06:50:18 +02:00
parent 93c2d676d0
commit c058cc57ef
2 changed files with 23 additions and 18 deletions

View file

@ -39,11 +39,14 @@ public class OsmParser extends MapCreatorBase {
int rawBlobCount = 0; int rawBlobCount = 0;
long bytesRead = 0L; long bytesRead = 0L;
Boolean avoidMapPolling = Boolean.getBoolean("avoidMapPolling");
// wait for file to become available if (!avoidMapPolling) {
while (!mapFile.exists()) { // wait for file to become available
System.out.println("--- waiting for " + mapFile + " to become available"); while (!mapFile.exists()) {
Thread.sleep(10000); System.out.println("--- waiting for " + mapFile + " to become available");
Thread.sleep(10000);
}
} }
long currentSize = mapFile.length(); long currentSize = mapFile.length();
@ -53,18 +56,20 @@ public class OsmParser extends MapCreatorBase {
for (; ; ) { for (; ; ) {
// continue reading if either more then a 100 MB unread, or the current-size is known for more then 2 Minutes if (!avoidMapPolling) {
while (currentSize - bytesRead < 100000000L) { // continue reading if either more then a 100 MB unread, or the current-size is known for more than 2 Minutes
long newSize = mapFile.length(); while (currentSize - bytesRead < 100000000L) {
if (newSize != currentSize) { long newSize = mapFile.length();
currentSize = newSize; if (newSize != currentSize) {
currentSizeTime = System.currentTimeMillis(); currentSize = newSize;
} else if (System.currentTimeMillis() - currentSizeTime > 120000) { currentSizeTime = System.currentTimeMillis();
break; } else if (System.currentTimeMillis() - currentSizeTime > 120000) {
} break;
if (currentSize - bytesRead < 100000000L) { }
System.out.println("--- waiting for more data, currentSize=" + currentSize + " bytesRead=" + bytesRead); if (currentSize - bytesRead < 100000000L) {
Thread.sleep(10000); System.out.println("--- waiting for more data, currentSize=" + currentSize + " bytesRead=" + bytesRead);
Thread.sleep(10000);
}
} }
} }

View file

@ -1,16 +1,16 @@
package btools.mapcreator; package btools.mapcreator;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
public class MapcreatorTest { public class MapcreatorTest {
@Ignore("Fails with PBF parser")
@Test @Test
public void mapcreatorTest() throws Exception { public void mapcreatorTest() throws Exception {
System.setProperty("avoidMapPolling", "true");
URL mapurl = this.getClass().getResource("/dreieich.pbf"); URL mapurl = this.getClass().getResource("/dreieich.pbf");
Assert.assertNotNull("test-osm-map dreieich.pbf not found", mapurl); Assert.assertNotNull("test-osm-map dreieich.pbf not found", mapurl);
File mapFile = new File(mapurl.getFile()); File mapFile = new File(mapurl.getFile());