use of org.opentripplanner.routing.services.GraphService in project OpenTripPlanner by opentripplanner.
the class OTPMain method makeGraphService.
/**
* Create a cached GraphService that will be used by all OTP components to resolve router IDs to Graphs.
* If a graph is supplied (graph parameter is not null) then that graph is also registered.
* TODO move into OTPServer and/or GraphService itself, eliminate FileFactory and put basePath in GraphService
*/
public void makeGraphService() {
graphService = new GraphService(params.autoReload);
InputStreamGraphSource.FileFactory graphSourceFactory = new InputStreamGraphSource.FileFactory(params.graphDirectory);
graphService.graphSourceFactory = graphSourceFactory;
if (params.graphDirectory != null) {
graphSourceFactory.basePath = params.graphDirectory;
}
}
use of org.opentripplanner.routing.services.GraphService in project OpenTripPlanner by opentripplanner.
the class GraphServiceTest method testGraphServiceMemory.
@Test
public final void testGraphServiceMemory() {
GraphService graphService = new GraphService();
graphService.registerGraph("A", new MemoryGraphSource("A", emptyGraph));
assertEquals(1, graphService.getRouterIds().size());
Graph graph = graphService.getRouter("A").graph;
assertNotNull(graph);
assertEquals(emptyGraph, graph);
assertEquals("A", emptyGraph.routerId);
try {
graph = graphService.getRouter("inexistant").graph;
// Should not be there
assertTrue(false);
} catch (GraphNotFoundException e) {
}
graphService.setDefaultRouterId("A");
graph = graphService.getRouter().graph;
assertEquals(emptyGraph, graph);
graphService.registerGraph("B", new MemoryGraphSource("B", smallGraph));
assertEquals(2, graphService.getRouterIds().size());
graph = graphService.getRouter("B").graph;
assertNotNull(graph);
assertEquals(smallGraph, graph);
assertEquals("B", graph.routerId);
graphService.evictRouter("A");
assertEquals(1, graphService.getRouterIds().size());
try {
graph = graphService.getRouter("A").graph;
// Should not be there
assertTrue(false);
} catch (GraphNotFoundException e) {
}
try {
graph = graphService.getRouter().graph;
// Should not be there
assertTrue(false);
} catch (GraphNotFoundException e) {
}
graphService.evictAll();
assertEquals(0, graphService.getRouterIds().size());
}
Aggregations