Package org.onebusaway.uk.network_rail.gtfs_realtime.model

Examples of org.onebusaway.uk.network_rail.gtfs_realtime.model.TrainMovementBody


    }
    return schedule;
  }

  private TrainInstance getTrainInstanceForTrainId(TrainMovementMessage message) {
    TrainMovementBody body = message.getBody();
    String trainId = body.getTrainId();
    if (trainId == null) {
      return null;
    }
    TrainInstance instance = _trainsById.get(trainId);
    if (instance != null) {
View Full Code Here


  @Override
  public synchronized void handleTrainMovementMessage(long fileTimestamp,
      TrainMovementMessage message, String source) {
    long msgTimestamp = Long.parseLong(message.getHeader().getMsgQueueTimestamp());
    long timestamp = pickBestTimestamp(msgTimestamp, fileTimestamp);
    TrainMovementBody body = message.getBody();
    String trainId = body.getTrainId();
    String trainReportingNumber = trainId.substring(2, 6);
    int trainClassCode = Integer.parseInt(trainReportingNumber.substring(0, 1));
    ETrainClass trainClass = ETrainClass.getTrainClassForCode(trainClassCode);
    if (!trainClass.isPassengerClass()) {
      return;
View Full Code Here

    SerializedNarrative.TrainMovementEvent.Builder trainMovementEvent = eventBuilder.getTrainMovementBuilder();

    ETrainMovementMessageType msgType = ETrainMovementMessageType.getTypeForCode(Integer.parseInt(message.getHeader().getMsgType()));
    trainMovementEvent.setType(SerializedNarrative.TrainMovementEvent.Type.valueOf(msgType.name()));

    TrainMovementBody body = message.getBody();
    if (body.getTrainId() != null) {
      trainMovementEvent.setTrainId(body.getTrainId());
    }
    if (body.getTrainUid() != null) {
      trainMovementEvent.setTrainUid(body.getTrainUid());
    }
    if (body.getLocStanox() != null) {
      int stanox = Integer.parseInt(body.getLocStanox());
      if (stanox != 0) {
        trainMovementEvent.setStanoxId(stanox);
      }
    }
    if (body.getEventSource() != null) {
      trainMovementEvent.setEventSource(body.getEventSource());
    }
    SerializedNarrative.Event event = eventBuilder.build();
    return event;
  }
View Full Code Here

        break;
    }
  }

  private void handleActivation(TrainMovementMessage message) {
    TrainMovementBody body = message.getBody();
    BasicScheduleElement schedule = getBestScheduleForTrainUid(body.getTrainUid());
    if (schedule == null) {
      return;
    }
    String trainId = body.getTrainId();
    long timestamp = Long.parseLong(message.getHeader().getMsgQueueTimestamp());

    Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Europe/London"));
    c.setTimeInMillis(timestamp);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    long serviceDate = c.getTimeInMillis();

    TrainInstance instance = new TrainInstance(trainId, serviceDate);

    fillTimepointsForTrainInstance(instance);

    _trainsById.put(trainId, instance);
    _narrativeService.addMessage(instance,
        "activation: trainUid=" + body.getTrainUid());
    _narrativeService.addMessage(instance.getTrainReportingNumber(), timestamp,
        "activation: trainUid=" + body.getTrainUid() + " trainId=" + trainId);
  }
View Full Code Here

      _narrativeService.addMessage(instance, "cancelation");
    }
  }

  private void handleMovement(TrainMovementMessage message) {
    TrainMovementBody body = message.getBody();
    _narrativeService.addMessage(
        body.getTrainId().substring(2, 6),
        Long.parseLong(message.getHeader().getMsgQueueTimestamp()),
        "movement: trainId=" + body.getTrainId() + " stanox="
            + body.getLocStanox());
    TrainInstance instance = getTrainInstanceForTrainId(message);
    if (instance == null) {
      _statisticsService.incrementUnknownTrainIdCount();
      return;
    }

    Set<TrainInstance> instances = _trainsByShortId.get(instance.getTrainReportingNumber());
    if (instances == null) {
      instances = new HashSet<TrainInstance>();
      _trainsByShortId.put(instance.getTrainReportingNumber(), instances);
    }
    instances.add(instance);

    if (body.getLocStanox() == null) {
      _statisticsService.incrementEmptyLocStanoxCount();
    }
    int stanox = Integer.parseInt(body.getLocStanox());
    TimepointElement timepoint = null; // what?
    if (timepoint == null) {
      _statisticsService.incrementUnknownStanoxCount();
      return;
    }

    if (body.getPlatform() != null) {
      String platform = body.getPlatform().trim();
      if (!platform.isEmpty() && !platform.equals(timepoint.getPlatform())) {
        _statisticsService.incrementPlatformChange();
      }
    }

    _narrativeService.addMessage(instance, "movement: stanox=" + stanox
        + " tiploc=" + timepoint.getTiploc());

    if (body.getActualTimestamp().isEmpty()
        || body.getPlannedTimestamp().isEmpty()) {
      return;
    }

    long actualTimestamp = Long.parseLong(body.getActualTimestamp());
    long plannedTimestamp = Long.parseLong(body.getPlannedTimestamp());
    int delay = (int) ((actualTimestamp - plannedTimestamp) / 1000);

    StopTimeEvent.Builder departure = StopTimeEvent.newBuilder();
    departure.setDelay(delay);
View Full Code Here

  private void handleChangleOfIdentity(TrainMovementMessage message) {
    /**
     * Theoretically, we should
     */
    TrainMovementBody body = message.getBody();
    String trainId = body.getTrainId();
    String revisedTrainId = body.getRevisedTrainId();
    if (!trainId.equals(revisedTrainId)) {
      TrainInstance train = _trainsById.remove(trainId);
      if (train != null) {
        throw new UnsupportedOperationException();
       
View Full Code Here

TOP

Related Classes of org.onebusaway.uk.network_rail.gtfs_realtime.model.TrainMovementBody

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.