예제 #1
0
  /**
   * This method builds instances of WebService for the distributed execution on remote nodes and
   * should be only invoked if distribution is specified in the QEP.
   *
   * @param request the request to execute
   * @throws DistributedException
   */
  public DQEEPortType buildEnvironement(Request request) throws DistributedException {

    // node id
    int i = 0;

    // Get node informations and remote QEP to send to remote nodes.
    BlackBoard bl = BlackBoard.getBlackBoard();
    G2NInfoNodes infoNodes = (G2NInfoNodes) bl.get(Constants.infoNodes);
    qepRemoteList = (LinkedList) bl.get(Constants.qepRemoteList);
    serviceURI = infoNodes.getNodes();
    int numberOfRemoteNodes = infoNodes.getNumberOfNodes();

    // Change "localhost" to the real IP address and put it in the BlackBoard.
    RemoteBlackBoardManager.prepareBlackBoard(request);

    try {

      if (!containersStarted) {

        //  Start gt4 containers.
        String start =
            SystemConfiguration.getSystemConfigInfo(Constants.START_WEBSERVICES_FROM_CODE);
        if (start != null) {
          if (start.equalsIgnoreCase("TRUE")) startContainers();
        }

        // Initialize the local Web service.
        qenodes = new DQEEPortType[numberOfRemoteNodes + 1];
      }

      // Prepare the remote nodes.
      ArrayList<Starter> starterThreads = new ArrayList<Starter>();
      for (i = 0; i <= numberOfRemoteNodes; i++) {

        Starter starter = new Starter(i);
        starter.start();
        starterThreads.add(starter);
      }

      long veryfingStartingThreads = System.currentTimeMillis();
      while (startedWebServicesNumber != (numberOfRemoteNodes + 1)) {

        try {

          Thread.sleep(1000);
          if (webServiceCrached == true) break;

        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }

      // Close all Starter Threads
      for (Starter starter : starterThreads) {

        synchronized (starter) {
          starter.interrupt();
        }
      }

      if (webServiceCrached == true) {
        throw new DistributedException("One or more web services are not initialized.");
      } else {
        startedWebServicesNumber = 0;
        containersStarted = true;
      }

      logger.debug(
          "beginStartingThreads : " + (System.currentTimeMillis() - veryfingStartingThreads));
      // bl.remove(Constants.THIS_NODE);

    } catch (Exception ex) {

      containersStarted = false;
      ex.printStackTrace();
      throw new DistributedException("Exception in DistributedManager: " + ex.getMessage());
    }

    // Return the first Web service.
    return qenodes[0];
  }
예제 #2
0
 /** Start the OpenNMS daemon. Never returns. */
 public void start() {
   Starter starter = new Starter();
   starter.startDaemon();
 }