Пример #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
    private void prepareNode(int numNode) {

      try {

        long startingThreads = System.currentTimeMillis();

        BlackBoard bl = BlackBoard.getBlackBoard();
        String addressLocalWebService =
            SystemConfiguration.getSystemConfigInfo(Constants.LOCAL_WEB_SERVICE);

        // Initialize remote Web services.
        if (!containersStarted)
          qenodes[numNode] =
              (numNode == 0)
                  ? webServiceFactory.createService(addressLocalWebService)
                  : webServiceFactory.createService(serviceURI[numNode - 1]);

        // Initialize the service.
        if (!containersStarted) qenodes[numNode].initializeService(numNode);

        // Get the local blackBoard hashmap.
        // BlackBoard bl = BlackBoard.getBlackBoard();
        // long BBTime = System.currentTimeMillis();
        HashMap<String, Object> blackHash = bl.getHashtable();
        HashMap<String, Object> hash = new HashMap<String, Object>();
        hash.putAll(blackHash);

        // Get the set of keys.
        Set blackBoardStrings = hash.keySet();
        Iterator itt = blackBoardStrings.iterator();

        while (itt.hasNext()) {

          // Get the object corresponding to this key.
          String key1 = (String) itt.next();
          Object valueObj = (Object) bl.get(key1);
          String value1 = "";

          // if the object is a string one, it could be copied together with its key
          // to the remote blackBoard.
          if (valueObj instanceof String) {

            value1 = (String) valueObj;
            BlackBoardParams params = new BlackBoardParams(key1, value1);
            qenodes[numNode].copyToRemoteBlackBoard(params);

          } else if (valueObj instanceof String[]) {

            String[] newValueObj = (String[]) valueObj;

            for (int j = 0; j < newValueObj.length; j++) {
              value1 += newValueObj[j] + ",";
            }

            value1 = value1.substring(0, value1.length() - 1);
            BlackBoardParams params = new BlackBoardParams(key1, value1);
            qenodes[numNode].copyToRemoteBlackBoard(params);
          }
        }

        if (numNode != 0) {
          BlackBoardParams params = new BlackBoardParams(Constants.THIS_NODE, numNode + "");
          qenodes[numNode].copyToRemoteBlackBoard(params);
        }

        // Send the QEP.
        qenodes[numNode].initRemote((String) qepRemoteList.get(numNode));

        if (numNode == 0) {
          logger.debug("Local web service initialized.");
        } else {
          logger.debug("Remote node n� " + numNode + " initialized.");
        }

        if (numNode != 0) {
          logger.debug(
              "StartingThread time "
                  + serviceURI[numNode - 1]
                  + " : "
                  + (System.currentTimeMillis() - startingThreads));
        }
        startedWebServicesNumber++;

      } catch (RemoteException ex) {

        startedWebServicesNumber++;
        webServiceCrached = true;
        ex.printStackTrace();
      }
    }