Example #1
0
  @Override
  public void scheduleEvent(ArdenEvent event) {
    starting.scheduleEvent(event);
    if (starting.runOnEvent(event)) {
      ArdenEvent startEvent = starting.getTriggeringEvent();

      ArdenTime startTime = new ArdenTime(startEvent.eventTime);
      ArdenTime end = new ArdenTime(startTime.add(length));
      ScheduledCycle cycle = new ScheduledCycle(startTime, end);
      scheduledCycles.add(cycle);
    }
  }
Example #2
0
  @Override
  public ArdenTime getNextRunTime() {
    // Check if the starting trigger has happened
    ArdenTime startTime = starting.getNextRunTime();
    if (startTime != null) {
      ArdenTime end = new ArdenTime(startTime.add(length));
      ScheduledCycle cycle = new ScheduledCycle(startTime, end);
      scheduledCycles.add(cycle);
    }

    ScheduledCycle oldestCycle = null;
    Iterator<ScheduledCycle> iterator = scheduledCycles.iterator();
    while (iterator.hasNext()) {
      ScheduledCycle cycle = iterator.next();

      if (cycle.next.compareTo(cycle.end) > 0) {
        // Cycle is already finished.
        iterator.remove();
        continue;
      }

      // Calculate cycle, which should be returned
      if (oldestCycle == null) {
        oldestCycle = cycle;
      } else if (cycle.next.compareTo(oldestCycle.next) < 0) {
        oldestCycle = cycle;
      }
    }

    if (oldestCycle == null) {
      return null;
    }

    currentDelay = oldestCycle.next.value - oldestCycle.start.value;
    ArdenTime nextRunTime = oldestCycle.next;

    oldestCycle.next = new ArdenTime(oldestCycle.next.add(interval));
    return nextRunTime;
  }