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,12 +39,15 @@ public class OsmParser extends MapCreatorBase {
int rawBlobCount = 0; int rawBlobCount = 0;
long bytesRead = 0L; long bytesRead = 0L;
Boolean avoidMapPolling = Boolean.getBoolean("avoidMapPolling");
if (!avoidMapPolling) {
// wait for file to become available // wait for file to become available
while (!mapFile.exists()) { while (!mapFile.exists()) {
System.out.println("--- waiting for " + mapFile + " to become available"); System.out.println("--- waiting for " + mapFile + " to become available");
Thread.sleep(10000); Thread.sleep(10000);
} }
}
long currentSize = mapFile.length(); long currentSize = mapFile.length();
long currentSizeTime = System.currentTimeMillis(); long currentSizeTime = System.currentTimeMillis();
@ -53,7 +56,8 @@ 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) {
// 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) { while (currentSize - bytesRead < 100000000L) {
long newSize = mapFile.length(); long newSize = mapFile.length();
if (newSize != currentSize) { if (newSize != currentSize) {
@ -67,6 +71,7 @@ public class OsmParser extends MapCreatorBase {
Thread.sleep(10000); Thread.sleep(10000);
} }
} }
}
int headerLength; int headerLength;
try { try {

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());