Example #1
0
  /* (non-Javadoc)
   * @see org.openiot.gsn.vsensor.AbstractVirtualSensor#dataAvailable(java.lang.String, org.openiot.gsn.beans.StreamElement)
   */
  @Override
  public void dataAvailable(String inputStreamName, StreamElement streamElement) {

    if (streamElement.getFieldTypes().length == nbArgs + 1)
      for (int i = 0; i < nbArgs; i++) parameters[i] = (Double) streamElement.getData()[i];
    Double answer;
    try {
      String matlabCommand = functionName + "(";
      for (int i = 0; i < nbArgs; i++) {
        matlabCommand = matlabCommand + parameters[i].toString();
        if (i != nbArgs - 1) matlabCommand = matlabCommand + ",";
      }
      if (nbArgs > 0) matlabCommand = matlabCommand + ")";
      if (logger.isDebugEnabled())
        logger.debug("Calling matlab engine with command: " + matlabCommand);
      engine.evalString(matlabCommand);
      String matlabAnswer = engine.getOutputString(100);
      if (logger.isDebugEnabled())
        logger.debug(
            "Received output from matlab: "
                + matlabAnswer
                + ". Trying to interpret this"
                + " answer as a Java Float object.");
      answer = Double.parseDouble(matlabAnswer);
      StreamElement result = new StreamElement(fieldNames, fieldTypes, new Serializable[] {answer});
      dataProduced(result);
    } catch (IOException e) {
      logger.warn(e);
    }
  }
Example #2
0
 public void consume(StreamElement se, VSensorConfig config) {
   synchronized (listeners) {
     for (DistributionRequest listener : listeners)
       if (listener.getVSensorConfig() == config) {
         logger.debug(
             "sending stream element "
                 + (se == null ? "second-chance-se" : se.toString())
                 + " produced by "
                 + config.getName()
                 + " to listener =>"
                 + listener.toString());
         if (!candidateListeners.containsKey(listener)) {
           addListenerToCandidates(listener);
         } else {
           candidatesForNextRound.put(listener, Boolean.TRUE);
         }
       }
   }
 }
 private void exportValues(StreamElement streamElement) {
   if (logger.isDebugEnabled())
     logger.debug("Trying to add new data items to the rrdfile:" + this.rrdfile);
   String command = "rrdtool update " + rrdfile + " N";
   Serializable[] stream = streamElement.getData();
   String field;
   for (int i = 0; i < stream.length; i++) {
     field = stream[i].toString();
     // if the field is empty we have to add an U for unknown to the rrdfile
     if (field == null || field.equals("")) field = "U";
     command = command + ":" + field;
   }
   Runtime runtime = Runtime.getRuntime();
   try {
     if (logger.isDebugEnabled()) logger.debug("The used rrdtool update command is: " + command);
     Process process = runtime.exec(command);
     if (logger.isDebugEnabled()) logger.debug("The processing did not generate an error!");
   } catch (IOException e) {
     logger.debug("An IOException has occured: " + e);
   }
 }