Beispiel #1
0
  private void getValueReply(String msg) {
    StringTokenizer st = new StringTokenizer(msg);
    String label;
    String timestamp;

    st.nextToken(); // Skip command

    label = st.nextToken();
    timestamp = st.nextToken();

    logger.debug("?get_value label: (" + label + ") at time " + timestamp);

    Channel channel = dataAccessService.getChannel(label);

    Record value = null;
    try {
      value = channel.getLoggedRecord(Long.parseLong(timestamp));
    } catch (Exception e) {
      out.println("!ERROR");
      logger.error(e.getMessage());
    }

    if (value != null) {
      out.println("!GET_VALUE_RESPONSE " + label + " " + value.getValue());
    } else {
      out.println("!ERROR: Value not found!");
    }
  }
Beispiel #2
0
  private void getReply(String msg) {
    StringTokenizer st = new StringTokenizer(msg);
    String label;

    try {
      st.nextToken(); // Skip command

      label = st.nextToken();

      logger.debug("?get label: (" + label + ")");

      Channel channel = dataAccessService.getChannel(label);

      Record value = channel.getLatestRecord();

      if (value != null) {
        out.println("!GET_RESPONSE " + label + " " + value.getValue());
      } else {
        out.println("!ERROR: Value not found!");
      }

    } catch (Exception e) {
      out.println("!ERROR");
      logger.error(e.getMessage());
    }
  }
Beispiel #3
0
  private void getAge(String msg) {
    StringTokenizer st = new StringTokenizer(msg);
    String label;

    try {
      st.nextToken(); // Skip command

      label = st.nextToken();

      logger.debug("?get_age label: (" + label + ")");

      long lastUpdate;
      long age;

      Channel channel = dataAccessService.getChannel(label);

      lastUpdate = channel.getLatestRecord().getTimestamp();

      age = System.currentTimeMillis() - lastUpdate;

      out.println("!GET_AGE_RESPONSE " + label + " " + age + " ms");

    } catch (Exception e) {
      out.println("!ERROR");
      logger.error(e.getMessage());
    }
  }
Beispiel #4
0
  private void setValueReply(String msg) {
    StringTokenizer st = new StringTokenizer(msg);
    String label, value;

    st.nextToken(); // Skip command
    label = st.nextToken();
    value = st.nextToken();

    if ((label == null) || (value == null)) {
      out.println("!ERROR: argument missing!");
      return;
    }

    Channel channel = dataAccessService.getChannel(label);

    if (channel != null) {

      double dblVal = Double.valueOf(value);

      channel.write(new DoubleValue(dblVal));
    } else {
      out.println("!ERROR: label not found!");
      return;
    }

    out.println("!OK");
  } /* setValueReply() */
Beispiel #5
0
  private void getValuesReply(String msg) {
    StringTokenizer st = new StringTokenizer(msg);
    String label;
    String startTime;
    String endTime;

    try {
      st.nextToken(); // Skip command

      label = st.nextToken();

      startTime = st.nextToken();

      logger.debug("?get_values label: (" + label + ") at time " + startTime);

      Channel storage = dataAccessService.getChannel(label);

      List<Record> values;

      System.out.println("got storage for label: " + label);

      if (storage == null) {
        System.out.println("Storage == null !!!");
      }

      System.out.println("storage: " + storage.toString());

      if (st.hasMoreTokens()) {
        endTime = st.nextToken();
        values = storage.getLoggedRecords(Long.parseLong(startTime), Long.parseLong(endTime));
        System.out.printf("getValues(%d,%d)", Long.parseLong(startTime), Long.parseLong(endTime));
      } else {
        values = storage.getLoggedRecords(Long.parseLong(startTime));
        System.out.printf("getValues(%d)", Long.parseLong(startTime));
      }
      System.out.println("result size:" + values.size());

      out.print("!GET_VALUES_RESPONSE");

      for (Record value : values) {
        out.print(" (" + value.getTimestamp() + "," + value.getValue() + ")");
      }

      System.out.println("step5");

      out.println();

    } catch (Exception e) {
      out.println("!ERROR");
      logger.error(e.getMessage());
    }
  }
Beispiel #6
0
  private void getAllValuesReply(String msg) {
    List<String> directory = dataAccessService.getAllIds();

    out.print("!GET_ALL_VALUES_RESPONSE");

    for (String label : directory) {
      Channel dataChannel = dataAccessService.getChannel(label);

      if (dataChannel != null) {
        out.print(" " + label + ":" + dataChannel.getLatestRecord().getValue());
      }
    }

    out.println();
  }
Beispiel #7
0
  private void configureReport(String msg) {
    StringTokenizer st = new StringTokenizer(msg);

    try {
      Report report;
      String type;

      st.nextToken(); // Skip command

      type = st.nextToken();

      if (type.equals("periodic")) {
        String interval = st.nextToken();

        int intvl = Integer.parseInt(interval);

        report = new PeriodicReport(reportHandle++, intvl);
      } else {
        out.println("!ERROR: Unknown report type!");
        return;
      }

      String label;

      while (st.hasMoreTokens()) {
        label = st.nextToken();
        Channel storage = dataAccessService.getChannel(label);

        if (storage != null) {
          report.addDataStorage(storage);
        } else {
          out.println("!ERROR: label not known!");
          return;
        }
      }

      reports.add(report);

      out.println("!CONFIGURE_REPORT_RESPONSE handle:" + report.getHandle());
    } catch (Exception e) {
      out.println("!ERROR");
      logger.error(e.getMessage());
    }
  }