protected ChangeGraphHelper createChangeGraphHelper(Graph graph, LocationIndex locationIndex) { return new ChangeGraphHelper(graph, locationIndex); }
/** * This method applies the changes to the graph specified as feature collection. It does so by locking the routing * to avoid concurrent changes which could result in incorrect routing (like when done while a Dijkstra search) or * also while just reading one edge row (inconsistent edge properties). */ public ChangeGraphResponse changeGraph(Collection<JsonFeature> collection) { // TODO allow calling this method if called before CH preparation if (getCHFactoryDecorator().isEnabled()) throw new IllegalArgumentException("To use the changeGraph API you need to turn off CH"); Lock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { ChangeGraphHelper overlay = createChangeGraphHelper(ghStorage, locationIndex); long updateCount = overlay.applyChanges(encodingManager, collection); return new ChangeGraphResponse(updateCount); } finally { writeLock.unlock(); } }
/** * This method applies changes to the graph, specified by the json features. * * @return number of successfully applied edge changes */ public long applyChanges(EncodingManager em, Collection<JsonFeature> features) { if (em == null) throw new NullPointerException("EncodingManager cannot be null to change existing graph"); long updates = 0; for (JsonFeature jsonFeature : features) { if (!jsonFeature.hasProperties()) throw new IllegalArgumentException("One feature has no properties, please specify properties e.g. speed or access"); List<String> encodersAsStr = (List) jsonFeature.getProperty("vehicles"); if (encodersAsStr == null) { for (FlagEncoder encoder : em.fetchEdgeEncoders()) { updates += applyChange(jsonFeature, encoder); } } else { for (String encoderStr : encodersAsStr) { updates += applyChange(jsonFeature, em.getEncoder(encoderStr)); } } } return updates; }
ChangeGraphHelper instance = new ChangeGraphHelper(graph, locationIndex); JsonFeatureCollection collection = Jackson.newObjectMapper().readValue(reader, JsonFeatureCollection.class); long updates = instance.applyChanges(encodingManager, collection.getFeatures()); assertEquals(2, updates);
/** * This method applies changes to the graph, specified by the reader. * * @return number of successfully applied edge changes */ public long applyChanges(Reader reader) { // read full file, later support one json feature or collection per line to avoid high mem consumption JsonFeatureCollection data = ghson.fromJson(reader, JsonFeatureCollection.class); return changeGraphHelper.applyChanges(encodingManager, data.getFeatures()); } }
/** * This method applies the changes to the graph specified as feature collection. It does so by locking the routing * to avoid concurrent changes which could result in incorrect routing (like when done while a Dijkstra search) or * also while just reading one edge row (inconsistent edge properties). */ public ChangeGraphResponse changeGraph(Collection<JsonFeature> collection) { // TODO allow calling this method if called before CH preparation if (getCHFactoryDecorator().isEnabled()) throw new IllegalArgumentException("To use the changeGraph API you need to turn off CH"); Lock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { ChangeGraphHelper overlay = createChangeGraphHelper(ghStorage, locationIndex); long updateCount = overlay.applyChanges(encodingManager, collection); return new ChangeGraphResponse(updateCount); } finally { writeLock.unlock(); } }
protected ChangeGraphHelper createChangeGraphHelper(Graph graph, LocationIndex locationIndex) { return new ChangeGraphHelper(graph, locationIndex); }
/** * This method applies changes to the graph, specified by the json features. * * @return number of successfully applied edge changes */ public long applyChanges(EncodingManager em, Collection<JsonFeature> features) { long updates = 0; for (JsonFeature jsonFeature : features) { if (!jsonFeature.hasProperties()) throw new IllegalArgumentException("One feature has no properties, please specify properties e.g. speed or access"); List<String> encodersAsStr = (List) jsonFeature.getProperty("vehicles"); if (encodersAsStr == null) { for (FlagEncoder encoder : em.fetchEdgeEncoders()) { updates += applyChange(jsonFeature, encoder); } } else { for (String encoderStr : encodersAsStr) { updates += applyChange(jsonFeature, em.getEncoder(encoderStr)); } } } return updates; }
/** * This method applies the changes to the graph specified as feature collection. It does so by locking the routing * to avoid concurrent changes which could result in incorrect routing (like when done while a Dijkstra search) or * also while just reading one edge row (inconsistent edge properties). */ public ChangeGraphResponse changeGraph(Collection<JsonFeature> collection) { // TODO allow calling this method if called before CH preparation if (getCHFactoryDecorator().isEnabled()) throw new IllegalArgumentException("To use the changeGraph API you need to turn off CH"); Lock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { ChangeGraphHelper overlay = createChangeGraphHelper(ghStorage, locationIndex); long updateCount = overlay.applyChanges(encodingManager, collection); return new ChangeGraphResponse(updateCount); } finally { writeLock.unlock(); } }
protected ChangeGraphHelper createChangeGraphHelper(Graph graph, LocationIndex locationIndex) { return new ChangeGraphHelper(graph, locationIndex); }
/** * This method applies changes to the graph, specified by the json features. * * @return number of successfully applied edge changes */ public long applyChanges(EncodingManager em, Collection<JsonFeature> features) { if (em == null) throw new NullPointerException("EncodingManager cannot be null to change existing graph"); long updates = 0; for (JsonFeature jsonFeature : features) { if (!jsonFeature.hasProperties()) throw new IllegalArgumentException("One feature has no properties, please specify properties e.g. speed or access"); List<String> encodersAsStr = (List) jsonFeature.getProperty("vehicles"); if (encodersAsStr == null) { for (FlagEncoder encoder : em.fetchEdgeEncoders()) { updates += applyChange(jsonFeature, encoder); } } else { for (String encoderStr : encodersAsStr) { updates += applyChange(jsonFeature, em.getEncoder(encoderStr)); } } } return updates; }