Search in sources :

Example 11 with GraphService

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;
    }
}
Also used : GraphService(org.opentripplanner.routing.services.GraphService) InputStreamGraphSource(org.opentripplanner.routing.impl.InputStreamGraphSource)

Example 12 with GraphService

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());
}
Also used : GraphService(org.opentripplanner.routing.services.GraphService) Graph(org.opentripplanner.routing.graph.Graph) GraphNotFoundException(org.opentripplanner.routing.error.GraphNotFoundException) Test(org.junit.Test)

Aggregations

GraphService (org.opentripplanner.routing.services.GraphService)12 Graph (org.opentripplanner.routing.graph.Graph)9 Test (org.junit.Test)6 MemoryGraphSource (org.opentripplanner.routing.impl.MemoryGraphSource)6 CommandLineParameters (org.opentripplanner.standalone.CommandLineParameters)5 OTPServer (org.opentripplanner.standalone.OTPServer)4 RolesAllowed (javax.annotation.security.RolesAllowed)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 GraphNotFoundException (org.opentripplanner.routing.error.GraphNotFoundException)3 File (java.io.File)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 RouterInfo (org.opentripplanner.api.model.RouterInfo)2 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)2 GraphPathFinder (org.opentripplanner.routing.impl.GraphPathFinder)2 Router (org.opentripplanner.standalone.Router)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1