示例#1
0
  public void destroy() {
    System.out.println("Destroy called!");
    view.dispose();

    running = false;

    voice.deallocate();

    timer.stop();

    arduino.close();
  }
示例#2
0
  /** @param args */
  @SuppressWarnings("unchecked")
  public void readSettingsFromXML() {

    String settingsFilename = "snitcher.xml";

    File xml = new File(settingsFilename);
    if (!xml.exists()) {
      createDefaultXMLFile(settingsFilename);
    }

    try {
      SAXReader reader = new SAXReader();
      Document doc;
      doc = reader.read(xml);
      Element root = doc.getRootElement();

      comPort = root.elementText("com");
      host = root.elementText("host");

      System.out.println("Monitoring: " + host);
      System.out.println("Arduino on: " + comPort);

      Element projectsElement = root.element("projects");

      List<Element> projects = (List<Element>) projectsElement.elements("project");

      for (Element project : projects) {
        System.out.println("Project: " + project.elementText("display"));
        addProject(
            new JenkinsProject(
                host, project.elementText("display"), project.elementText("jenkins")));
      }

    } catch (DocumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    monitor.sortProjects();

    arduino.initialize(comPort);
  }
示例#3
0
  public void start() {
    while (running) {
      int offset = 0;

      boolean buildInterrupted = false;
      boolean buildFailed = false;
      boolean building = false;

      List<String> blames = new ArrayList<String>();
      String sayString = "";

      try {
        for (JenkinsProject project : monitor.projects) {
          if (project.isBuilding()) {
            // arduino.setChannelToState(offset,
            // ProjectState.BUILDING);
            building = true;
          } else if (project.getStatus().equals("SUCCESS")) {
            // arduino.setChannelToState(offset,
            // / ProjectState.BUILD_SUCCEEDED);
          } else if (project.getStatus().equals("ABORTED")) {
            // arduino.setChannelToState(offset,
            // ProjectState.BUILD_INTERRUPTED);
            buildInterrupted = true;
          } else {
            // arduino.setChannelToState(offset,
            // ProjectState.BUILD_FAILED);
            buildFailed = true;

            String person = project.getLastUser();

            if ((!person.equals("anonymous")) && (!blames.contains(person))) {
              blames.add(person);
            }
          }

          if (project.mustNotify()) {

            if (sayString.equals("")) {
              sayString = "Attention please! ";
            }

            String notifyString = project.getNotifyString();
            sayString += notifyString + "! ";

            project.setNotified(true);
          }

          offset += 1;
        }

        ProjectState serverState = ProjectState.BUILD_SUCCEEDED;
        if (buildFailed) {
          serverState = ProjectState.BUILD_FAILED;
        }

        if (!sayString.equals("")) {
          say(sayString);
        }

        view.setBlames(blames);

        arduino.setChannelToState(0, serverState);

      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      arduino.sendStatus();
      // view.update();

      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }