use of org.opentripplanner.standalone.Router in project OpenTripPlanner by opentripplanner.
the class GraphService method getRouter.
/**
* @return the graph object for the given router ID
*/
public Router getRouter(String routerId) throws GraphNotFoundException {
if (routerId == null || routerId.isEmpty() || routerId.equalsIgnoreCase("default")) {
routerId = defaultRouterId;
LOG.debug("routerId not specified, set to default of '{}'", routerId);
}
/*
* Here we should not synchronize on graphSource as it may block for a while (during
* reload/autoreload). For normal operations a simple get do not need to be synchronized so
* we should be safe.
*/
GraphSource graphSource = graphSources.get(routerId);
if (graphSource == null) {
LOG.error("no graph registered with the routerId '{}'", routerId);
throw new GraphNotFoundException();
}
Router router = graphSource.getRouter();
if (router == null) {
evictRouter(routerId);
throw new GraphNotFoundException();
}
return router;
}
use of org.opentripplanner.standalone.Router in project OpenTripPlanner by opentripplanner.
the class InputStreamGraphSource method reload.
@Override
public boolean reload(boolean force, boolean preEvict) {
/* We synchronize on 'this' to prevent multiple reloads from being called at the same time */
synchronized (this) {
long lastModified = streams.getLastModified();
boolean doReload = force ? true : checkAutoReload(lastModified);
if (!doReload)
return true;
if (preEvict) {
synchronized (preEvictMutex) {
if (router != null) {
LOG.info("Reloading '{}': pre-evicting router", routerId);
router.shutdown();
}
/*
* Forcing router to null here should remove any references to the graph once
* all current requests are done. So the next reload is supposed to have more
* memory.
*/
router = null;
router = loadGraph();
}
} else {
Router newRouter = loadGraph();
if (newRouter != null) {
// Load OK
if (router != null) {
LOG.info("Reloading '{}': post-evicting router", routerId);
router.shutdown();
}
// Assignment in java is atomic
router = newRouter;
} else {
// Load failed
if (force || router == null) {
LOG.warn("Unable to load data for router '{}'.", routerId);
if (router != null) {
router.shutdown();
}
router = null;
} else {
// No shutdown, since we keep current one.
LOG.warn("Unable to load data for router '{}', keeping old data.", routerId);
}
}
}
if (router == null) {
graphLastModified = 0L;
} else {
/*
* Note: we flag even if loading failed, because we want to wait for fresh new data
* before loading again.
*/
graphLastModified = lastModified;
}
// If a router is null, it will be evicted.
return (router != null);
}
}
Aggregations