Exemplo n.º 1
0
  //
  // / Interval logging
  //
  private void initializeIntervalLogging() {
    synchronized (intervalLoggingLock) {
      if (vo.getLoggingType() != DataPointVO.LoggingTypes.INTERVAL) return;

      // Are we using a custom timer?
      if (this.timer == null)
        intervalLoggingTask =
            new TimeoutTask(
                new FixedRateTrigger(
                    0,
                    Common.getMillis(
                        vo.getIntervalLoggingPeriodType(), vo.getIntervalLoggingPeriod())),
                this);
      else
        intervalLoggingTask =
            new TimeoutTask(
                new FixedRateTrigger(
                    0,
                    Common.getMillis(
                        vo.getIntervalLoggingPeriodType(), vo.getIntervalLoggingPeriod())),
                this,
                this.timer);

      intervalValue = pointValue;
      if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.AVERAGE) {
        intervalStartTime = System.currentTimeMillis();
        averagingValues = new ArrayList<IValueTime>();
      }
    }
  }
Exemplo n.º 2
0
  @DwrPermission(admin = true)
  public synchronized void scheduleRestart() {
    if (RESTART_TASK == null) {
      SystemEventType.raiseEvent(
          new SystemEventType(SystemEventType.TYPE_SYSTEM_SHUTDOWN),
          System.currentTimeMillis(),
          false,
          new TranslatableMessage("modules.restartScheduledBy", Common.getUser().getUsername()));

      long timeout = Common.getMillis(Common.TimePeriods.SECONDS, 10);
      RESTART_TASK =
          new TimeoutTask(
              timeout,
              new TimeoutClient() {
                @Override
                public void scheduleTimeout(long fireTime) {
                  File restartFlag = new File(Common.M2M2_HOME, "RESTART");
                  if (!restartFlag.exists()) {
                    try {
                      FileWriter fw = new FileWriter(restartFlag);
                      fw.write("restart");
                      fw.close();
                    } catch (IOException e) {
                      LOG.error("Unabled to create restart flag file", e);
                    }
                  }
                  Providers.get(ILifecycle.class).terminate();
                }
              });
    }
  }