Search in sources :

Example 21 with Router

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;
}
Also used : Router(org.opentripplanner.standalone.Router) GraphNotFoundException(org.opentripplanner.routing.error.GraphNotFoundException)

Example 22 with 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);
    }
}
Also used : Router(org.opentripplanner.standalone.Router)

Aggregations

Router (org.opentripplanner.standalone.Router)22 GET (javax.ws.rs.GET)9 Produces (javax.ws.rs.Produces)8 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)8 Path (javax.ws.rs.Path)6 Graph (org.opentripplanner.routing.graph.Graph)6 Envelope2D (org.geotools.geometry.Envelope2D)5 TimeSurface (org.opentripplanner.analyst.TimeSurface)5 TileRequest (org.opentripplanner.analyst.request.TileRequest)5 RenderRequest (org.opentripplanner.analyst.request.RenderRequest)4 ArrayList (java.util.ArrayList)3 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)3 GraphPathFinder (org.opentripplanner.routing.impl.GraphPathFinder)3 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)3 CommandLineParameters (org.opentripplanner.standalone.CommandLineParameters)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 Date (java.util.Date)2 MIMEImageFormat (org.opentripplanner.api.parameter.MIMEImageFormat)2 GenericLocation (org.opentripplanner.common.model.GenericLocation)2