コード例 #1
0
  @SuppressWarnings("unchecked")
  public void restoreFromMemento(OpenmrsMemento memento) {

    if (memento != null && memento instanceof TimerSchedulerMemento) {
      TimerSchedulerMemento timerMemento = (TimerSchedulerMemento) memento;

      Set<Integer> taskIds = (HashSet<Integer>) timerMemento.getState();

      // try to start all of the tasks that were stopped right before this restore
      for (Integer taskId : taskIds) {
        TaskDefinition task = getTask(taskId);
        try {
          scheduleTask(task);
        } catch (Exception e) {
          // essentially swallow exceptions
          log.debug(
              "EXPECTED ERROR IF STOPPING THIS TASK'S MODULE: Unable to start task " + taskId, e);

          // save this errored task and try again next time we restore
          timerMemento.addErrorTask(taskId);
        }
      }
      timerMemento = null; // so the old cl can be gc'd
    }
  }