Example #1
0
  private synchronized void updateAlarms() {
    //        activeAlarms.clear();
    for (TagBlankEntity tagBlankEntity : deviceEntity.getTagBlankEntities()) {
      for (AlarmBlank alarmBlank : tagBlankEntity.getAlarmBlanks()) {
        StringBuffer sb = new StringBuffer();

        try {
          sb.append(values.get(tagBlankEntity.getTagDescr()).getRegister());
          sb.append(alarmBlank.getCondition());
          String script = sb.toString();
          Boolean res = (Boolean) AlarmUtil.getInstance().getScriptEngine().eval(script);
          Alarm alarm = new Alarm(alarmBlank);
          if (res == true) {
            if (activeAlarms.contains(alarm)) {
              continue;
            } else {
              activeAlarms.add(alarm);
              AlarmEntity alarmEntity = new AlarmEntity();
              alarmEntity.setAlarmBlank(alarmBlank);
              alarmEntity.setAlarmTime(alarm.getStartTime());
              DataHelper.getInstance().saveAlarm(alarmEntity);
            }
          } else {
            if (activeAlarms.contains(alarm)) {
              activeAlarms.remove(alarm);
            }
          }
        } catch (RuntimeException ex) {
          ex.printStackTrace();
        } catch (ScriptException e) {
          e.printStackTrace();
        }
      }
    }
  }