Пример #1
0
 /**
  * Creates and returns a copy of this object. The precise meaning of "copy" may depend on the
  * class of the object. The general intent is that, for any object <tt>x</tt>, the expression:
  */
 protected Object clone() {
   Alarm ret = null;
   try {
     ret = (Alarm) super.clone();
     ret.pcs = null;
     ret.setTime((Time) time.clone());
   } catch (CloneNotSupportedException e) {
     e.printStackTrace();
   }
   return ret;
 }
Пример #2
0
  /** The body method is called on the instatiated plan instance from the scheduler. */
  public void body() {
    while (true) {
      // Check if there is an alarm to do.
      Alarm alarm = (Alarm) getParameter("alarm").getValue();
      //			System.out.println("Alarmplan got alarm: "+alarm);

      long alarmtime = alarm.getAlarmtime(getTime());
      //			System.out.println("Alarm plan alarmtime: "+alarmtime);
      if (alarmtime == Alarm.NO_ALARM) {
        getLogger().info("Alarmplan fails due to no alarm time: " + getReason());
        fail();
      }

      // Wait until the alarm time has come.
      long wait = alarmtime - getTime();
      if (wait > 0) {
        getLogger().info("Waiting for: " + wait / 1000 + " secs");
        waitFor(wait);
      }
      // Play the designated alarm song.
      if (wait > -1000) // todo: what is the limit?
      {
        // System.out.println("Notifying user.");
        IGoal notify = createGoal("notify");
        notify.getParameter("alarm").setValue(alarm);
        try {
          dispatchSubgoalAndWait(notify);
        } catch (GoalFailureException e) {
          getLogger().info("Could not play alarm for reason:" + e);
        }
      }

      // Avoid triggering more than once for the same alarm time.
      waitFor(1000);
      // Indicate that alarm has triggered.
      alarm.triggerd();
    }
  }