コード例 #1
0
ファイル: Scheduler.java プロジェクト: SteinMaerivoet/myHome
  public void initialize() {
    scheduleTimeList = new ArrayList<>();

    loadScheduleTimesFromDatabase();

    scheduler = Executors.newScheduledThreadPool(scheduleTimeList.size() + 2);

    for (ScheduleTime scheduleTime : scheduleTimeList) {
      // start startEvent
      scheduler.scheduleAtFixedRate(
          startEvent, scheduleTime.calculateStartDelay(), SECONDS_IN_WEEK, SECONDS);
      // start endEvent
      scheduler.scheduleAtFixedRate(
          stopEvent, scheduleTime.calculateStopDelay(), SECONDS_IN_WEEK, SECONDS);
    }
  }
コード例 #2
0
ファイル: Trip.java プロジェクト: sheldonabrown/core
  /**
   * For adding ScheduleTimes for stops to a Trip. Updates scheduledTimesMap, startTime, and
   * endTime.
   *
   * @param newScheduledTimesList
   * @throws ArrayIndexOutOfBoundsException If not enough space allocated for serialized schedule
   *     times in scheduledTimesMap column
   */
  public void addScheduleTimes(List<ScheduleTime> newScheduledTimesList) {
    // For each schedule time (one per stop path)
    for (ScheduleTime scheduleTime : newScheduledTimesList) {
      // Add the schedule time to the map
      scheduledTimesList.add(scheduleTime);

      // Determine the begin and end time. Assumes that times are added in order
      if (startTime == null
          || (scheduleTime.getDepartureTime() != null
              && scheduleTime.getDepartureTime() < startTime))
        startTime = scheduleTime.getDepartureTime();
      if (endTime == null
          || (scheduleTime.getArrivalTime() != null && scheduleTime.getArrivalTime() > endTime))
        endTime = scheduleTime.getArrivalTime();
    }

    // If resulting map takes up too much memory throw an exception.
    // Only bother checking if have at least a few schedule times.
    /*if (scheduledTimesList.size() > 5) {
    	int serializedSize = HibernateUtils.sizeof(scheduledTimesList);
    	if (serializedSize > scheduleTimesMaxBytes) {
    		String msg = "Too many elements in "
    				+ "scheduledTimesMap when constructing a "
    				+ "Trip. Have " + scheduledTimesList.size()
    				+ " schedule times taking up " + serializedSize
    				+ " bytes but only have " + scheduleTimesMaxBytes
    				+ " bytes allocated for the data. Trip="
    				+ this.toShortString();
    		logger.error(msg);

    		// Since this could be a really problematic issue, throw an error
    		throw new ArrayIndexOutOfBoundsException(msg);
    	}
    }*/
  }
コード例 #3
0
ファイル: Trip.java プロジェクト: sheldonabrown/core
  /**
   * Creates a copy of the Trip object but adjusts the startTime, endTime, and scheduledTimesMap
   * according to the frequenciesBasedStartTime. This is used when the frequencies.txt file
   * specifies exact_times for a trip.
   *
   * @param tripFromStopTimes
   * @param frequenciesBasedStartTime
   */
  public Trip(Trip tripFromStopTimes, int frequenciesBasedStartTime) {
    this.configRev = tripFromStopTimes.configRev;
    this.tripId = tripFromStopTimes.tripId;
    this.tripShortName = tripFromStopTimes.tripShortName;
    this.directionId = tripFromStopTimes.directionId;
    this.routeId = tripFromStopTimes.routeId;
    this.routeShortName = tripFromStopTimes.routeShortName;
    this.serviceId = tripFromStopTimes.serviceId;
    this.headsign = tripFromStopTimes.headsign;
    this.shapeId = tripFromStopTimes.shapeId;
    this.tripPattern = tripFromStopTimes.tripPattern;
    this.travelTimes = tripFromStopTimes.travelTimes;

    // Set the updated start and end times by using the frequencies
    // based start time.
    this.startTime = tripFromStopTimes.startTime + frequenciesBasedStartTime;
    this.endTime = tripFromStopTimes.endTime + frequenciesBasedStartTime;

    // Since frequencies being used for configuration we will have multiple
    // trips with the same ID. But need a different block ID for each one.
    // Therefore use the original trip's block ID but then append the
    // start time as a string to make it unique.
    this.blockId = tripFromStopTimes.blockId + "_" + Time.timeOfDayStr(this.startTime);

    // Set the scheduledTimesMap by using the frequencies based start time
    for (ScheduleTime schedTimeFromStopTimes : tripFromStopTimes.scheduledTimesList) {
      Integer arrivalTime = null;
      if (schedTimeFromStopTimes.getArrivalTime() != null)
        arrivalTime = schedTimeFromStopTimes.getArrivalTime() + frequenciesBasedStartTime;
      Integer departureTime = null;
      if (schedTimeFromStopTimes.getDepartureTime() != null)
        departureTime = schedTimeFromStopTimes.getDepartureTime() + frequenciesBasedStartTime;

      ScheduleTime schedTimeFromFrequency = new ScheduleTime(arrivalTime, departureTime);
      this.scheduledTimesList.add(schedTimeFromFrequency);
    }

    // Since this constructor is only for frequency based trips where
    // exact_times is true set the corresponding members to indicate such
    this.noSchedule = false;
    this.exactTimesHeadway = true;
  }