Пример #1
0
  public boolean initialize() {
    /**
     * TODO : Checking if the user provides the arguements currectly. TODO : This can now plot only
     * for one input stream value.
     */
    TreeMap<String, String> params = getVirtualSensorConfiguration().getMainClassInitialParams();
    ChartInfo chartInfo = new ChartInfo();
    chartInfo.setInputStreamName(params.get("input-stream"));

    chartInfo.setPlotTitle(params.get("title"));
    chartInfo.setType(params.get("type"));
    chartInfo.setHeight(ParamParser.getInteger(params.get("height"), 480));
    chartInfo.setWidth(ParamParser.getInteger(params.get("width"), 640));
    chartInfo.setVerticalAxisTitle(params.get("vertical-axis"));
    chartInfo.setHistorySize(ParamParser.getInteger(params.get("history-size"), 10));
    input_stream_name_to_ChartInfo_map.put(chartInfo.getInputStreamName(), chartInfo);
    chartInfo.initialize();
    return true;
  }
Пример #2
0
  public void dataAvailable(String inputStreamName, StreamElement streamElement) {
    if (logger.isDebugEnabled())
      logger.debug(
          new StringBuilder("data received under the name *")
              .append(inputStreamName)
              .append("* to the ChartVS.")
              .toString());
    /** Finding the appropriate ChartInfo object for this input stream. */
    ChartInfo chartInfo = input_stream_name_to_ChartInfo_map.get(inputStreamName);
    /**
     * If there is not chartInfo configured for this input stream, the virtual sensor doesn't
     * produce any values. Note that if this virtual sensor is intended to produce output other than
     * plots (e.g., if output of this virtual sensor also container integers), then one might
     * comment the following line.
     */
    if (chartInfo == null) {
      logger.warn(
          "ChartVS drops the input because there is no chart specification defined for the specific input.");
      return;
    }
    /** Sending the data to the chartInfo. */
    chartInfo.addData(streamElement);
    /** counter checks to see if it's the time to do the plotting or not. */
    if (++counter % GENERATE_COUNT != 0) return;
    /**
     * Creating the stream element(s) for output. For creating a stream element one need to provide
     * the field names (in the form of string array) and their types (in the form of integer array).
     * This virtual sensor just produces plots therefore the output is in the form of binary data
     * thus we set the type of the output stream element to Types.Binary.
     */
    String[] fieldNames = input_stream_name_to_ChartInfo_map.keySet().toArray(new String[] {});
    Byte[] fieldTypes = new Byte[fieldNames.length];
    Serializable[] charts = new Serializable[fieldNames.length];
    for (int i = 0; i < fieldTypes.length; i++) {
      /**
       * We set the type of the output stream element to Types.Binary because we are producing
       * images.
       */
      fieldTypes[i] = DataTypes.BINARY;
    }
    /**
     * Creating an stream element with the specified fieldnames, fieldtypes and using the current
     * time as the timestamp of the stream element.
     */

    /**
     * In here our stream element's relation contains just one row of data and it's filled using the
     * binary data which contains the plots. Note that this virtual sensor plots one diagram for
     * each InputStreamName. Also Note that, each InputStreamName can have one or more variables
     * inside it's stream elements's relation thus having one plot for several variables.
     */
    for (int i = 0; i < fieldNames.length; i++) {
      ChartInfo chart = input_stream_name_to_ChartInfo_map.get(fieldNames[i]);
      charts[i] = chart.writePlot().toByteArray();
    }
    StreamElement output =
        new StreamElement(fieldNames, fieldTypes, charts, System.currentTimeMillis());

    /** Informing container about existance of a stream element. */
    dataProduced(output);
    /** For debugging purposes. */
    if (logger.isDebugEnabled())
      logger.debug(
          new StringBuilder()
              .append("Data received under the name: ")
              .append(inputStreamName)
              .toString());
  }