Search in sources :

Example 1 with RealtimeFeed

use of com.graphhopper.gtfs.RealtimeFeed in project graphhopper by graphhopper.

the class RealtimeFeedLoadingCache method start.

@Override
public void start() {
    this.transfers = new HashMap<>();
    for (Map.Entry<String, GTFSFeed> entry : this.gtfsStorage.getGtfsFeeds().entrySet()) {
        this.transfers.put(entry.getKey(), new Transfers(entry.getValue()));
    }
    this.executor = Executors.newSingleThreadExecutor();
    this.cache = CacheBuilder.newBuilder().maximumSize(1).refreshAfterWrite(1, TimeUnit.MINUTES).build(new CacheLoader<String, RealtimeFeed>() {

        public RealtimeFeed load(String key) {
            return fetchFeedsAndCreateGraph();
        }

        @Override
        public ListenableFuture<RealtimeFeed> reload(String key, RealtimeFeed oldValue) {
            ListenableFutureTask<RealtimeFeed> task = ListenableFutureTask.create(() -> fetchFeedsAndCreateGraph());
            executor.execute(task);
            return task;
        }
    });
}
Also used : RealtimeFeed(com.graphhopper.gtfs.RealtimeFeed) Transfers(com.graphhopper.gtfs.Transfers) CacheLoader(com.google.common.cache.CacheLoader) HashMap(java.util.HashMap) Map(java.util.Map) GTFSFeed(com.conveyal.gtfs.GTFSFeed)

Aggregations

GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 CacheLoader (com.google.common.cache.CacheLoader)1 RealtimeFeed (com.graphhopper.gtfs.RealtimeFeed)1 Transfers (com.graphhopper.gtfs.Transfers)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1