Search in sources :

Example 1 with GraphWriterRunnable

use of org.opentripplanner.updater.GraphWriterRunnable in project OpenTripPlanner by opentripplanner.

the class GtfsRealtimeAlertsUpdater method runPolling.

@Override
protected void runPolling() {
    try {
        InputStream data = HttpUtils.getData(url);
        if (data == null) {
            throw new RuntimeException("Failed to get data from url " + url);
        }
        final FeedMessage feed = FeedMessage.PARSER.parseFrom(data);
        long feedTimestamp = feed.getHeader().getTimestamp();
        if (feedTimestamp <= lastTimestamp) {
            LOG.info("Ignoring feed with an old timestamp.");
            return;
        }
        // Handle update in graph writer runnable
        updaterManager.execute(new GraphWriterRunnable() {

            @Override
            public void run(Graph graph) {
                updateHandler.update(feed);
            }
        });
        lastTimestamp = feedTimestamp;
    } catch (Exception e) {
        LOG.error("Error reading gtfs-realtime feed from " + url, e);
    }
}
Also used : FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) GraphWriterRunnable(org.opentripplanner.updater.GraphWriterRunnable) Graph(org.opentripplanner.routing.graph.Graph) InputStream(java.io.InputStream)

Example 2 with GraphWriterRunnable

use of org.opentripplanner.updater.GraphWriterRunnable in project OpenTripPlanner by opentripplanner.

the class BikeParkUpdater method setup.

@Override
public void setup() throws InterruptedException, ExecutionException {
    // Creation of network linker library will not modify the graph
    linker = new SimpleStreetSplitter(graph);
    // Adding a bike park station service needs a graph writer runnable
    updaterManager.executeBlocking(new GraphWriterRunnable() {

        @Override
        public void run(Graph graph) {
            bikeService = graph.getService(BikeRentalStationService.class, true);
        }
    });
}
Also used : GraphWriterRunnable(org.opentripplanner.updater.GraphWriterRunnable) Graph(org.opentripplanner.routing.graph.Graph) SimpleStreetSplitter(org.opentripplanner.graph_builder.linking.SimpleStreetSplitter)

Aggregations

Graph (org.opentripplanner.routing.graph.Graph)2 GraphWriterRunnable (org.opentripplanner.updater.GraphWriterRunnable)2 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)1 InputStream (java.io.InputStream)1 SimpleStreetSplitter (org.opentripplanner.graph_builder.linking.SimpleStreetSplitter)1