use of com.google.transit.realtime.GtfsRealtime.FeedMessage 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);
}
}
use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project OpenTripPlanner by opentripplanner.
the class GtfsRealtimeFileTripUpdateSource method getUpdates.
@Override
public List<TripUpdate> getUpdates() {
FeedMessage feedMessage = null;
List<FeedEntity> feedEntityList = null;
List<TripUpdate> updates = null;
fullDataset = true;
try {
InputStream is = new FileInputStream(file);
if (is != null) {
// Decode message
feedMessage = FeedMessage.PARSER.parseFrom(is);
feedEntityList = feedMessage.getEntityList();
// Change fullDataset value if this is an incremental update
if (feedMessage.hasHeader() && feedMessage.getHeader().hasIncrementality() && feedMessage.getHeader().getIncrementality().equals(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL)) {
fullDataset = false;
}
// Create List of TripUpdates
updates = new ArrayList<TripUpdate>(feedEntityList.size());
for (FeedEntity feedEntity : feedEntityList) {
if (feedEntity.hasTripUpdate())
updates.add(feedEntity.getTripUpdate());
}
}
} catch (Exception e) {
LOG.warn("Failed to parse gtfs-rt feed at " + file + ":", e);
}
return updates;
}
use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project OpenTripPlanner by opentripplanner.
the class GtfsRealtimeHttpTripUpdateSource method getUpdates.
@Override
public List<TripUpdate> getUpdates() {
FeedMessage feedMessage = null;
List<FeedEntity> feedEntityList = null;
List<TripUpdate> updates = null;
fullDataset = true;
try {
InputStream is = HttpUtils.getData(url);
if (is != null) {
// Decode message
feedMessage = FeedMessage.PARSER.parseFrom(is);
feedEntityList = feedMessage.getEntityList();
// Change fullDataset value if this is an incremental update
if (feedMessage.hasHeader() && feedMessage.getHeader().hasIncrementality() && feedMessage.getHeader().getIncrementality().equals(GtfsRealtime.FeedHeader.Incrementality.DIFFERENTIAL)) {
fullDataset = false;
}
// Create List of TripUpdates
updates = new ArrayList<>(feedEntityList.size());
for (FeedEntity feedEntity : feedEntityList) {
if (feedEntity.hasTripUpdate())
updates.add(feedEntity.getTripUpdate());
}
}
} catch (Exception e) {
LOG.warn("Failed to parse gtfs-rt feed from " + url + ":", e);
}
return updates;
}
use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project onebusaway-application-modules by camsys.
the class AlertsFromRssResource method getAllDebug.
@Path("/service-alerts-debug")
@GET
@Produces("text/plain")
public Response getAllDebug() {
FeedMessage serviceAlertFeed = _alertsService.getServlceAlertFeed();
if (serviceAlertFeed == null) {
_log.info("empty feed");
return Response.ok().build();
}
// return the string representation of the protocol buffers
Response response = Response.ok(serviceAlertFeed.toString()).build();
return response;
}
use of com.google.transit.realtime.GtfsRealtime.FeedMessage in project onebusaway-application-modules by camsys.
the class GtfsRtProxyAction method execute.
public String execute() {
FeedMessage tu = getFeedMessage(getTripUpdatesPath());
if (tu != null) {
tripUpdates = GtfsRealtimeConversionLibrary.readTripUpdates(tu);
}
FeedMessage vp = getFeedMessage(getVehiclePositionsPath());
if (vp != null) {
vehiclePositions = GtfsRealtimeConversionLibrary.readVehiclePositions(vp);
}
return SUCCESS;
}
Aggregations