From ead7f2ac6d0ba81c5afd4eeefe5e9fd835bcecab Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Fri, 2 Sep 2016 19:05:50 +0200 Subject: [PATCH] cleanup and bugfixes --- .../src/main/java/btools/router/OsmTrack.java | 2 +- .../java/btools/router/RoutingEngine.java | 67 ++++++++++--------- .../java/btools/router/RoutingHelper.java | 9 --- .../btools/mapcreator/MapcreatorTest.java | 6 -- .../java/btools/mapaccess/NodesCache.java | 24 ++----- .../btools/routingapp/BRouterActivity.java | 2 +- .../btools/routingapp/BRouterService.java | 15 +++++ 7 files changed, 58 insertions(+), 67 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/OsmTrack.java b/brouter-core/src/main/java/btools/router/OsmTrack.java index 01f9aa1..f38baa8 100644 --- a/brouter-core/src/main/java/btools/router/OsmTrack.java +++ b/brouter-core/src/main/java/btools/router/OsmTrack.java @@ -729,7 +729,7 @@ public final class OsmTrack return e.message; } e = e.origin; - if ( cnt++ == 10000 ) + if ( cnt++ == 1000000 ) { throw new IllegalArgumentException( "ups?" ); } diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index 979ce9d..0949da1 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -68,30 +68,33 @@ public class RoutingEngine extends Thread this.infoLogEnabled = outfileBase != null; this.routingContext = rc; - File baseFolder = new File( routingContext.localFunction ).getParentFile().getParentFile(); - try + File baseFolder = new File( routingContext.localFunction ).getParentFile(); + baseFolder = baseFolder == null ? null : baseFolder.getParentFile(); + if ( baseFolder != null ) { - File debugLog = new File( baseFolder, "debug.txt" ); - if ( debugLog.exists() ) + try { - infoLogWriter = new FileWriter( debugLog, true ); - logInfo( "********** start request at " ); - logInfo( "********** " + new Date() ); + File debugLog = new File( baseFolder, "debug.txt" ); + if ( debugLog.exists() ) + { + infoLogWriter = new FileWriter( debugLog, true ); + logInfo( "********** start request at " ); + logInfo( "********** " + new Date() ); + } + } + catch( IOException ioe ) + { + throw new RuntimeException( "cannot open debug-log:" + ioe ); + } + + File stackLog = new File( baseFolder, "stacks.txt" ); + if ( stackLog.exists() ) + { + stackSampler = new StackSampler( stackLog, 1000 ); + stackSampler.start(); + logInfo( "********** started stacksampling" ); } } - catch( IOException ioe ) - { - throw new RuntimeException( "cannot open debug-log:" + ioe ); - } - - File stackLog = new File( baseFolder, "stacks.txt" ); - if ( stackLog.exists() ) - { - stackSampler = new StackSampler( stackLog, 1000 ); - stackSampler.start(); - logInfo( "********** started stacksampling" ); - } - boolean cachedProfile = ProfileCache.parseProfile( rc ); if ( hasInfo() ) { @@ -406,6 +409,18 @@ public class RoutingEngine extends Thread { preloadPosition( mwp.waypoint ); } + + if ( nodesCache.first_file_access_failed ) + { + throw new IllegalArgumentException( "datafile " + nodesCache.first_file_access_name + " not found" ); + } + for( MatchedWaypoint mwp : unmatchedWaypoints ) + { + if ( mwp.crosspoint == null ) + { + throw new IllegalArgumentException( mwp.waypoint.name + "-position not mapped in existing datafile" ); + } + } } private void preloadPosition( OsmNode n ) @@ -558,7 +573,7 @@ public class RoutingEngine extends Thread logInfo( "NodesCache status before reset=" + nodesCache.formatStatus() ); } nodesMap = new OsmNodesMap(); - nodesCache = new NodesCache(segmentDir, nodesMap, routingContext.expctxWay, routingContext.carMode, routingContext.forceSecondaryData, nodesCache ); + nodesCache = new NodesCache(segmentDir, nodesMap, routingContext.expctxWay, routingContext.forceSecondaryData, nodesCache ); } private OsmNode getStartNode( long startId ) @@ -991,16 +1006,6 @@ public class RoutingEngine extends Thread } } - private void preloadPosition( OsmNode n, int minRingWidth, int minCount ) - { - int c = 0; - int ring = 0; - while( ring <= minRingWidth || ( c < minCount && ring <= 5 ) ) - { - c += preloadRing( n, ring++ ); - } - } - private int preloadRing( OsmNode n, int ring ) { int d = 12500; diff --git a/brouter-core/src/main/java/btools/router/RoutingHelper.java b/brouter-core/src/main/java/btools/router/RoutingHelper.java index 6edea02..36866f8 100644 --- a/brouter-core/src/main/java/btools/router/RoutingHelper.java +++ b/brouter-core/src/main/java/btools/router/RoutingHelper.java @@ -44,15 +44,6 @@ public final class RoutingHelper { if ( fileName.endsWith( ".rd5" ) ) return true; } - File carSubset = new File( dir, "carsubset" ); - if ( carSubset.isDirectory() ) - { - fileNames = carSubset.list(); - for( String fileName : fileNames ) - { - if ( fileName.endsWith( ".cd5" ) ) return true; - } - } return false; } } 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 3c3fb88..4da0bd5 100644 --- a/brouter-map-creator/src/test/java/btools/mapcreator/MapcreatorTest.java +++ b/brouter-map-creator/src/test/java/btools/mapcreator/MapcreatorTest.java @@ -67,11 +67,5 @@ public class MapcreatorTest File segments = new File( tmpdir, "segments" ); segments.mkdir(); new WayLinker().process( unodes55, waytiles55, bordernodes, lookupFile, profileAllFile, segments, "rd5" ); - - // run WayLinker, car subset - File carsubset = new File( segments, "carsubset" ); - carsubset.mkdir(); - File profileCarFile = new File( profileDir, "car-test.brf" ); - new WayLinker().process( unodes55, waytiles55, bordernodes, lookupFile, profileCarFile, carsubset, "cd5" ); } } diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java b/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java index e0512b2..4e09088 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/NodesCache.java @@ -25,7 +25,6 @@ public final class NodesCache private BExpressionContextWay expCtxWay; private int lookupVersion; private int lookupMinorVersion; - private boolean carMode; private boolean forceSecondaryData; private String currentFileName; @@ -48,15 +47,13 @@ public final class NodesCache return "collecting=" + garbageCollectionEnabled + " cacheSum=" + cacheSum; } - public NodesCache( String segmentDir, OsmNodesMap nodesMap, BExpressionContextWay ctxWay, boolean carMode, boolean forceSecondaryData, - NodesCache oldCache ) + public NodesCache( String segmentDir, OsmNodesMap nodesMap, BExpressionContextWay ctxWay, boolean forceSecondaryData, NodesCache oldCache ) { this.segmentDir = new File( segmentDir ); this.nodesMap = nodesMap; this.expCtxWay = ctxWay; this.lookupVersion = ctxWay.meta.lookupVersion; this.lookupMinorVersion = ctxWay.meta.lookupMinorVersion; - this.carMode = carMode; this.forceSecondaryData = forceSecondaryData; first_file_access_failed = false; @@ -238,7 +235,7 @@ public final class NodesCache String slat = lat < 0 ? "S" + ( -lat ) : "N" + lat; String filenameBase = slon + "_" + slat; - currentFileName = filenameBase + ".rd5/cd5"; + currentFileName = filenameBase + ".rd5"; PhysicalFile ra = null; if ( !fileCache.containsKey( filenameBase ) ) @@ -254,21 +251,10 @@ public final class NodesCache } if ( f == null ) { - if ( carMode ) // look for carsubset-files only in secondary (primaries are now good for car-mode) + File secondary = new File( secondarySegmentsDir, filenameBase + ".rd5" ); + if ( secondary.exists() ) { - File carFile = new File( secondarySegmentsDir, "carsubset/" + filenameBase + ".cd5" ); - if ( carFile.exists() ) - { - f = carFile; - } - } - if ( f == null ) - { - File secondary = new File( secondarySegmentsDir, filenameBase + ".rd5" ); - if ( secondary.exists() ) - { - f = secondary; - } + f = secondary; } } if ( f != null ) diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java index 3c90aca..acc35fe 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterActivity.java @@ -332,7 +332,7 @@ public class BRouterActivity extends Activity implements OnInitListener { showWaypointDatabaseHelp(); } - else if ( wpCount == -1 ) + else if ( wpCount == -1 || wpCount == -3 ) { finish(); } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java index 2e32a8b..6a1b9b8 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java @@ -34,6 +34,8 @@ public class BRouterService extends Service @Override public String getTrackFromParams( Bundle params ) throws RemoteException { + logBundle( params ); + BRouterWorker worker = new BRouterWorker(); // get base dir from private file @@ -227,6 +229,19 @@ public class BRouterService extends Service } } + private void logBundle( Bundle params ) + { + if ( AppLogger.isLogging() ) + { + for( String k : params.keySet() ) + { + Object val = "remoteProfile".equals( k ) ? "<..cut..>" : params.get(k); + String desc = "key=" + k + (val == null ? "" : " class=" + val.getClass() + " val=" + val.toString() ); + AppLogger.log( desc ); + } + } + } + }; @Override