Ejemplo n.º 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!");
    }
  }
Ejemplo n.º 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());
    }
  }
Ejemplo n.º 3
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());
    }
  }