Package com.google.transit.realtime.GtfsRealtime

Examples of com.google.transit.realtime.GtfsRealtime.FeedMessage


        this.file = new File(preferences.get("file", ""));
    }

    @Override
    public List<TripUpdate> getUpdates() {
        FeedMessage feedMessage = null;
        List<FeedEntity> feedEntityList = null;
        List<TripUpdate> updates = null;
        try {
            InputStream is = new FileInputStream(file);
            if (is != null) {
                feedMessage = FeedMessage.PARSER.parseFrom(is);
                feedEntityList = feedMessage.getEntityList();
                updates = new ArrayList<TripUpdate>(feedEntityList.size());
                for (FeedEntity feedEntity : feedEntityList) {
                    updates.add(feedEntity.getTripUpdate());
                }
            }
View Full Code Here


     * Auxiliary class to handle incoming messages via the websocket connection
     */
    private class Listener extends DefaultWebSocketListener {
        @Override
        public void onMessage(byte[] message) {
            FeedMessage feedMessage = null;
            List<FeedEntity> feedEntityList = null;
            List<TripUpdate> updates = null;
            try {
                // Decode message into List of TripUpdates
                feedMessage = FeedMessage.PARSER.parseFrom(message);
                feedEntityList = feedMessage.getEntityList();
                updates = new ArrayList<TripUpdate>(feedEntityList.size());
                for (FeedEntity feedEntity : feedEntityList) {
                    if (feedEntity.hasTripUpdate()) updates.add(feedEntity.getTripUpdate());
                }
            } catch (InvalidProtocolBufferException e) {
View Full Code Here

        this.agencyId = preferences.get("defaultAgencyId", null);
    }

    @Override
    public List<TripUpdate> getUpdates() {
        FeedMessage feedMessage = null;
        List<FeedEntity> feedEntityList = null;
        List<TripUpdate> updates = null;
        try {
            InputStream is = HttpUtils.getData(url);
            if (is != null) {
                feedMessage = FeedMessage.PARSER.parseFrom(is);
                feedEntityList = feedMessage.getEntityList();
                updates = new ArrayList<TripUpdate>(feedEntityList.size());
                for (FeedEntity feedEntity : feedEntityList) {
                    updates.add(feedEntity.getTripUpdate());
                }
            }
View Full Code Here

            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;
            }
View Full Code Here

        alertsUpdateHandler.setAlertPatchService(alertPatchServiceImpl);
        alertsUpdateHandler.setDefaultAgencyId("MMRI");

        try {
            InputStream inputStream = new FileInputStream(gtfsRealTime);
            FeedMessage feedMessage = FeedMessage.PARSER.parseFrom(inputStream);
            List<FeedEntity> feedEntityList = feedMessage.getEntityList();
            List<TripUpdate> updates = new ArrayList<TripUpdate>(feedEntityList.size());
            for (FeedEntity feedEntity : feedEntityList) {
                updates.add(feedEntity.getTripUpdate());
            }
            timetableSnapshotSource.applyTripUpdates(updates, agencyId);
View Full Code Here

      _refreshTask = null;
    }
  }

  public void refresh() throws IOException {
    FeedMessage tripUpdates = readOrReturnDefault(_tripUpdatesUrl);
    FeedMessage vehiclePositions = readOrReturnDefault(_vehiclePositionsUrl);
    FeedMessage alerts = readOrReturnDefault(_alertsUrl);
    MonitoredResult result = new MonitoredResult();
    result.setAgencyIds(_agencyIds);
    handeUpdates(result, tripUpdates, vehiclePositions, alerts);
    // update reference in a thread safe manner
    _monitoredResult = result;
View Full Code Here

    _action.setTime(new Date(now));

    _action.show();
   
    ResponseBean model = _action.getModel();
    FeedMessage feed = (FeedMessage) model.getData();
    assertEquals(now / 1000, feed.getHeader().getTimestamp());
    assertEquals(2, feed.getEntityCount());

    {
      FeedEntity entity = feed.getEntity(0);
      assertEquals("1", entity.getId());
      VehiclePosition vehiclePosition = entity.getVehicle();
      assertEquals("t0", vehiclePosition.getTrip().getTripId());
      assertEquals("r1", vehiclePosition.getTrip().getRouteId());
      assertEquals("v1", vehiclePosition.getVehicle().getId());
      assertEquals(1234, vehiclePosition.getTimestamp());
      assertEquals(47.0, vehiclePosition.getPosition().getLatitude(), 0.01);
      assertEquals(-122.0, vehiclePosition.getPosition().getLongitude(), 0.01);
    }

    {
      FeedEntity entity = feed.getEntity(1);
      assertEquals("2", entity.getId());
      VehiclePosition vehiclePosition = entity.getVehicle();
      assertEquals("t1", vehiclePosition.getTrip().getTripId());
      assertEquals("r1", vehiclePosition.getTrip().getRouteId());
      assertEquals("v2", vehiclePosition.getVehicle().getId());
View Full Code Here

    _action.setTime(new Date(now));

    _action.show();
   
    ResponseBean model = _action.getModel();
    FeedMessage feed = (FeedMessage) model.getData();
    assertEquals(now / 1000, feed.getHeader().getTimestamp());
    assertEquals(2, feed.getEntityCount());

    {
      FeedEntity entity = feed.getEntity(0);
      assertEquals("1", entity.getId());
      TripUpdate tripUpdate = entity.getTripUpdate();
      assertEquals("t0", tripUpdate.getTrip().getTripId());
      assertEquals("r1", tripUpdate.getTrip().getRouteId());
      assertEquals("v1", tripUpdate.getVehicle().getId());
      assertEquals(1234, tripUpdate.getTimestamp());
      assertEquals(1, tripUpdate.getStopTimeUpdateCount());
      StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
      assertEquals("s2", stopTimeUpdate.getStopId());
      assertEquals(now / 1000 + 5 * 60, stopTimeUpdate.getDeparture().getTime());
    }
    {
      FeedEntity entity = feed.getEntity(1);
      assertEquals("2", entity.getId());
      TripUpdate tripUpdate = entity.getTripUpdate();
      assertEquals("t1", tripUpdate.getTrip().getTripId());
      assertEquals("r1", tripUpdate.getTrip().getRouteId());
      assertEquals("v2", tripUpdate.getVehicle().getId());
View Full Code Here

    _action.setTime(new Date(now));

    _action.show();

    ResponseBean model = _action.getModel();
    FeedMessage feed = (FeedMessage) model.getData();
    assertEquals(now / 1000, feed.getHeader().getTimestamp());
    assertEquals(2, feed.getEntityCount());

    {
      FeedEntity entity = feed.getEntity(0);
      assertEquals("1", entity.getId());
      Alert alert = entity.getAlert();
      assertEquals(1, alert.getActivePeriodCount());
      TimeRange range = alert.getActivePeriod(0);
      assertEquals(1234, range.getStart());
      assertEquals(5678, range.getEnd());
      assertEquals(2, alert.getInformedEntityCount());
      {
        EntitySelector affects = alert.getInformedEntity(0);
        assertEquals("1", affects.getAgencyId());
        assertEquals("r0", affects.getRouteId());
        assertEquals("t0", affects.getTrip().getTripId());
        assertEquals("s0", affects.getStopId());
      }
      {
        EntitySelector affects = alert.getInformedEntity(1);
        assertEquals("2", affects.getAgencyId());
      }
      TranslatedString header = alert.getHeaderText();
      assertEquals(2, header.getTranslationCount());
      {
        Translation translation = header.getTranslation(0);
        assertEquals("Name", translation.getText());
        assertEquals("en", translation.getLanguage());
      }
      {
        Translation translation = header.getTranslation(1);
        assertEquals("Nombre", translation.getText());
        assertEquals("es", translation.getLanguage());
      }
      TranslatedString description = alert.getDescriptionText();
      assertEquals(2, description.getTranslationCount());
      {
        Translation translation = description.getTranslation(0);
        assertEquals("Description", translation.getText());
        assertEquals("en", translation.getLanguage());
      }
      {
        Translation translation = description.getTranslation(1);
        assertEquals("Descripción", translation.getText());
        assertEquals("es", translation.getLanguage());
      }
    }
    {
      FeedEntity entity = feed.getEntity(1);
      assertEquals("2", entity.getId());
      Alert alert = entity.getAlert();
      assertEquals(1, alert.getActivePeriodCount());
      TimeRange range = alert.getActivePeriod(0);
      assertEquals(5678, range.getStart());
View Full Code Here

    _gtfsRealtimeService = gtfsRealtimeService;
  }

  @RequestMapping(value = "/gtfs-realtime/trip-updates.action")
  public void tripUpdates(OutputStream out) throws IOException {
    FeedMessage tripUpdates = _gtfsRealtimeService.getTripUpdates();
    tripUpdates.writeTo(out);
  }
View Full Code Here

TOP

Related Classes of com.google.transit.realtime.GtfsRealtime.FeedMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.