extended configuration (to hande Kitkat issues)

This commit is contained in:
Arndt 2014-07-26 12:25:44 +02:00
parent a6878ba04e
commit 631057cd5f
10 changed files with 251 additions and 40 deletions

View file

@ -13,7 +13,9 @@ import java.util.List;
public final class NodesCache
{
private String segmentDir;
private File segmentDir;
private File secondarySegmentsDir = null;
private OsmNodesMap nodesMap;
private int lookupVersion;
private int lookupMinorVersion;
@ -33,21 +35,25 @@ public final class NodesCache
private long cacheSum = 0;
private boolean garbageCollectionEnabled = false;
public NodesCache( String segmentDir, OsmNodesMap nodesMap, int lookupVersion, int minorVersion, boolean varLen, boolean carMode, NodesCache oldCache )
{
this.segmentDir = segmentDir;
this.segmentDir = new File( segmentDir );
this.nodesMap = nodesMap;
this.lookupVersion = lookupVersion;
this.lookupMinorVersion = minorVersion;
this.readVarLength = varLen;
this.carMode = carMode;
if ( !this.segmentDir.isDirectory() ) throw new RuntimeException( "segment directory " + segmentDir + " does not exist" );
if ( oldCache != null )
{
fileCache = oldCache.fileCache;
iobuffer = oldCache.iobuffer;
oom_carsubset_hint = oldCache.oom_carsubset_hint;
secondarySegmentsDir = oldCache.secondarySegmentsDir;
// re-use old, virgin caches
fileRows = oldCache.fileRows;
@ -65,8 +71,20 @@ public final class NodesCache
fileCache = new HashMap<String,PhysicalFile>(4);
fileRows = new OsmFile[180][];
iobuffer = new byte[65636];
secondarySegmentsDir = StorageConfigHelper.getSecondarySegmentDir( segmentDir );
}
}
private File getFileFromSegmentDir( String filename )
{
File f = new File( segmentDir, filename );
if ( secondarySegmentsDir != null && !f.exists() )
{
File f2 = new File( secondarySegmentsDir, filename );
if ( f2.exists() ) return f2;
}
return f;
}
// if the cache sum exceeded a threshold,
// clean all ghosts and enable garbage collection
@ -185,9 +203,6 @@ public final class NodesCache
private OsmFile fileForSegment( int lonDegree, int latDegree ) throws Exception
{
File base = new File( segmentDir );
if ( !base.isDirectory() ) throw new RuntimeException( "segment directory " + segmentDir + " does not exist" );
int lonMod5 = lonDegree % 5;
int latMod5 = latDegree % 5;
int tileIndex = lonMod5 * 5 + latMod5;
@ -207,12 +222,12 @@ public final class NodesCache
File f = null;
if ( carMode )
{
File carFile = new File( new File( base, "carsubset" ), filenameBase + ".cd5" );
File carFile = getFileFromSegmentDir( "carsubset/" + filenameBase + ".cd5" );
if ( carFile.exists() ) f = carFile;
}
if ( f == null )
{
File fullFile = new File( base, filenameBase + ".rd5" );
File fullFile = getFileFromSegmentDir( filenameBase + ".rd5" );
if ( fullFile.exists() ) f = fullFile;
if ( carMode && f != null ) oom_carsubset_hint = true;
}

View file

@ -0,0 +1,55 @@
/**
* Access to the storageconfig.txt config file
*
* @author ab
*/
package btools.mapaccess;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
public class StorageConfigHelper
{
public static File getSecondarySegmentDir( String segmentDir )
{
return getStorageLocation( segmentDir, "secondary_segment_dir=" );
}
public static File getAdditionalMaptoolDir( String segmentDir )
{
return getStorageLocation( segmentDir, "additional_maptool_dir=" );
}
private static File getStorageLocation( String segmentDir, String tag )
{
File res = null;
BufferedReader br = null;
String configFile = segmentDir + "/storageconfig.txt";
try
{
br = new BufferedReader( new FileReader (configFile ) );
for(;;)
{
String line = br.readLine();
if ( line == null ) break;
line = line.trim();
if ( line.startsWith( "#") ) continue;
if ( line.startsWith( tag ) )
{
String path = line.substring( tag.length() ).trim();
res = path.startsWith( "/" ) ? new File( path ) : new File( new File( segmentDir ) , path );
if ( !res.exists() ) res = null;
break;
}
}
}
catch( Exception e ) {}
finally
{
if ( br != null ) try { br.close(); } catch( Exception ee ) {}
}
return res;
}
}