Esempio n. 1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ice.item.Item#update(org.eclipse.ice.item.messaging.Message)
   */
  @Override
  public boolean update(Message message) {

    // Get the message type and string text
    String type = message.getType();
    String text = message.getMessage();

    // Parse the message type
    if ("MESSAGE_POSTED".equals(type)) {

      // If its a message posted, we expect it to
      // be of the format pp_name:time:value
      String[] data = text.split(":");
      String name = data[0];
      Double time = Double.valueOf(data[1]);
      Double value = Double.valueOf(data[2]);

      // We need the jobLaunch directory to create new VizResources
      String directory = mooseLauncher.getJobLaunchDirectory();

      // Get a reference to the VizResource file we are going
      // to create and populate
      File dataFile = new File(directory + System.getProperty("file.separator") + name + ".csv");

      // Get a reference to the ResourceComponent
      ResourceComponent comp = (ResourceComponent) form.getComponent(3);

      try {

        if (!dataFile.exists()) {
          // If the file hasn't been created yet, we need to create
          // it and start filling it with post processor data
          dataFile.createNewFile();

          // Write the new incoming data
          PrintWriter printWriter = new PrintWriter(new FileOutputStream(dataFile, true));
          printWriter.write("Time, " + name + "\n");
          printWriter.write(time + ", " + value + "\n");
          printWriter.close();

          // Create the VizResource, and add it to the
          // ResourceComponent
          ICEResource resource = getResource(dataFile.getAbsolutePath());
          comp.add(resource);

          // Remember the name of the resource for next time
          postProcessorResources.put(name, resource);

        } else {

          // Write the data to the existing resource
          PrintWriter printWriter = new PrintWriter(new FileOutputStream(dataFile, true));
          printWriter.write(time + ", " + value + "\n");

          // Update the ICEResource
          ICEResource r = postProcessorResources.get(name);

          // Here we are faking a VizResource notification
          // by setting the name with its current name
          r.setName(r.getName());

          // Close the writer
          printWriter.close();
        }

      } catch (IOException e) {
        logger.error(getClass().getName() + " Exception!", e);
      }
    }

    return true;
  }
Esempio n. 2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ice.item.Item#update(org.eclipse.ice.datastructures.ICEObject
   * .IUpdateable)
   */
  @Override
  public void update(IUpdateable updateable) {

    if (updateable instanceof ResourceComponent) {
      ResourceComponent comp = (ResourceComponent) updateable;
      ResourceComponent ourComp = (ResourceComponent) form.getComponent(3);

      ArrayList<String> names = new ArrayList<String>();

      // Get a list of all our Resource Names:
      for (ICEResource r : ourComp.getResources()) {
        names.add(r.getName());
      }

      for (ICEResource r : comp.getResources()) {
        if (!names.contains(r.getName())) {
          logger.info("Adding Resource to Moose: " + r.getName());
          ourComp.add(r);
        }
      }

    } else if (updateable instanceof TreeComposite) {
      // If this is a tree composite we should reset our variables
      Thread varThread =
          new Thread(
              new Runnable() {

                @Override
                public void run() {
                  new MOOSEFileHandler().setupVariables(modelTree);
                  new MOOSEFileHandler().setupAuxVariables(modelTree);
                }
              });
      varThread.start();

    } else if (updateable instanceof Entry) {

      Entry entry = (Entry) updateable;

      // If we get here, then we have a file Entry that
      // has been changed on the modelFiles component
      // and we need to sync up the tree with it.

      // Grab the DataComponent
      if (fileEntryTreeMapping.containsKey(entry.getName())) {
        DataComponent data =
            (DataComponent) fileEntryTreeMapping.get(entry.getName()).getDataNodes().get(0);

        // If not null, loop over the Entries til we find
        // the file Entry.
        if (data != null) {
          for (Entry e : data.retrieveAllEntries()) {

            // If the Entry's tag is "false" it is a commented
            // out
            // parameter.
            if (!"false".equals(e.getTag())
                && e.getValue() != null
                && !e.getValue().isEmpty()
                && (e.getName() + " = " + e.getValue())
                    .matches(mooseLauncher.getFileDependenciesSearchString())) {

              // Set the value of the tree's file entry.
              e.setValue(entry.getValue());
              break;
            }
          }
        }
      }
    }
  }