public GraphHopperStorage(List<? extends Weighting> chWeightings, Directory dir, final EncodingManager encodingManager, boolean withElevation, GraphExtension extendedStorage) { if (extendedStorage == null) throw new IllegalArgumentException("GraphExtension cannot be null, use NoOpExtension"); if (encodingManager == null) throw new IllegalArgumentException("EncodingManager needs to be non-null since 0.7. Create one using new EncodingManager or EncodingManager.create(flagEncoderFactory, ghLocation)"); this.encodingManager = encodingManager; this.dir = dir; this.properties = new StorableProperties(dir); InternalGraphEventListener listener = new InternalGraphEventListener() { @Override public void initStorage() { for (CHGraphImpl cg : chGraphs) { cg.initStorage(); } } @Override public void freeze() { for (CHGraphImpl cg : chGraphs) { cg._freeze(); } } }; this.baseGraph = new BaseGraph(dir, encodingManager, withElevation, listener, extendedStorage); for (Weighting w : chWeightings) { chGraphs.add(new CHGraphImpl(w, dir, this.baseGraph)); } }
/** * Create the EncodingManager from the provided GraphHopper location. Throws an * IllegalStateException if it fails. Used if no EncodingManager specified on load. */ public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) { Directory dir = new RAMDirectory(ghLoc, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation()); // check encoding for compatibility properties.checkVersions(false); String acceptStr = properties.get("graph.flag_encoders"); if (acceptStr.isEmpty()) throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytes_for_flags"))) bytesForFlags = 8; return new EncodingManager(factory, acceptStr, bytesForFlags); }
@Test public void testLoad() { StorableProperties instance = new StorableProperties(createDir("", false)); // an in-memory storage does not load anything assertFalse(instance.loadExisting()); instance = new StorableProperties(createDir("", true)); assertFalse(instance.loadExisting()); instance.close(); }
@Test public void testStore() { String dir = "./target/test"; Helper.removeDir(new File(dir)); StorableProperties instance = new StorableProperties(createDir(dir, true)); instance.create(1000); instance.put("test.min", 123); instance.put("test.max", 321); instance.flush(); instance.close(); instance = new StorableProperties(createDir(dir, true)); assertTrue(instance.loadExisting()); assertEquals("123", instance.get("test.min")); assertEquals("321", instance.get("test.max")); instance.close(); Helper.removeDir(new File(dir)); }
@Test public void testVersionCheck() { StorableProperties instance = new StorableProperties(createDir("", false)); instance.putCurrentVersions(); assertTrue(instance.checkVersions(true)); instance.put("nodes.version", 0); assertFalse(instance.checkVersions(true)); try { instance.checkVersions(false); assertTrue(false); } catch (Exception ex) { } instance.close(); }
public GraphHopperStorage(List<? extends Weighting> chWeightings, Directory dir, final EncodingManager encodingManager, boolean withElevation, GraphExtension extendedStorage) { if (extendedStorage == null) throw new IllegalArgumentException("GraphExtension cannot be null, use NoOpExtension"); if (encodingManager == null) throw new IllegalArgumentException("EncodingManager needs to be non-null since 0.7. Create one using new EncodingManager or EncodingManager.create(flagEncoderFactory, ghLocation)"); this.encodingManager = encodingManager; this.dir = dir; this.properties = new StorableProperties(dir); InternalGraphEventListener listener = new InternalGraphEventListener() { @Override public void initStorage() { for (CHGraphImpl cg : chGraphs) { cg.initStorage(); } } @Override public void freeze() { for (CHGraphImpl cg : chGraphs) { cg._freeze(); } } }; this.baseGraph = new BaseGraph(dir, encodingManager, withElevation, listener, extendedStorage); for (Weighting w : chWeightings) { chGraphs.add(new CHGraphImpl(w, dir, this.baseGraph)); } }
public GraphHopperStorage(List<? extends Weighting> chWeightings, Directory dir, final EncodingManager encodingManager, boolean withElevation, GraphExtension extendedStorage) { if (extendedStorage == null) throw new IllegalArgumentException("GraphExtension cannot be null, use NoOpExtension"); if (encodingManager == null) throw new IllegalArgumentException("EncodingManager needs to be non-null since 0.7. Create one using new EncodingManager or EncodingManager.create(flagEncoderFactory, ghLocation)"); this.encodingManager = encodingManager; this.dir = dir; this.properties = new StorableProperties(dir); InternalGraphEventListener listener = new InternalGraphEventListener() { @Override public void initStorage() { for (CHGraphImpl cg : chGraphs) { cg.initStorage(); } } @Override public void freeze() { for (CHGraphImpl cg : chGraphs) { cg._freeze(); } } }; this.baseGraph = new BaseGraph(dir, encodingManager, withElevation, listener, extendedStorage); for (Weighting w : chWeightings) { chGraphs.add(new CHGraphImpl(w, dir, this.baseGraph)); } }
this.properties = new StorableProperties(dir); InternalGraphEventListener listener = new InternalGraphEventListener()
/** * Create the EncodingManager from the provided GraphHopper location. Throws an * IllegalStateException if it fails. Used if no EncodingManager specified on load. */ public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) { Directory dir = new RAMDirectory(ghLoc, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation()); // check encoding for compatibility properties.checkVersions(false); String acceptStr = properties.get("graph.flag_encoders"); if (acceptStr.isEmpty()) throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytes_for_flags"))) bytesForFlags = 8; return new EncodingManager(factory, acceptStr, bytesForFlags); }
/** * Create the EncodingManager from the provided GraphHopper location. Throws an * IllegalStateException if it fails. Used if no EncodingManager specified on load. */ public static EncodingManager create(FlagEncoderFactory factory, String ghLoc) { Directory dir = new RAMDirectory(ghLoc, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation()); // check encoding for compatibility properties.checkVersions(false); String acceptStr = properties.get("graph.flag_encoders"); if (acceptStr.isEmpty()) throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytes_for_flags"))) bytesForFlags = 8; return new EncodingManager(factory, acceptStr, bytesForFlags); }
/** * Create the EncodingManager from the provided GraphHopper location. Throws an * IllegalStateException if it fails. Used if no EncodingManager specified on load. */ public static EncodingManager create( FlagEncoderFactory factory, String ghLoc ) { Directory dir = new RAMDirectory(ghLoc, true); StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) throw new IllegalStateException("Cannot load properties to fetch EncodingManager configuration at: " + dir.getLocation()); // check encoding for compatibility properties.checkVersions(false); String acceptStr = properties.get("graph.flag_encoders"); if (acceptStr.isEmpty()) throw new IllegalStateException("EncodingManager was not configured. And no one was found in the graph: " + dir.getLocation()); int bytesForFlags = 4; if ("8".equals(properties.get("graph.bytes_for_flags"))) bytesForFlags = 8; return new EncodingManager(factory, acceptStr, bytesForFlags); } }
StorableProperties properties = new StorableProperties(dir); if (!properties.loadExisting()) { properties.close();