Exemplo n.º 1
0
  public void doJoin() {
    NodeEngineImpl nodeEngine = null;
    synchronized (joinerLock) {
      for (Address address : joinAddresses) {
        NodeEngineImpl ne = nodes.get(address);
        if (ne != null && ne.isRunning() && ne.getNode().joined()) {
          nodeEngine = ne;
          break;
        }
      }
      Address master = null;
      if (nodeEngine != null) {
        if (nodeEngine.getNode().isMaster()) {
          master = nodeEngine.getThisAddress();
        } else {
          master = nodeEngine.getMasterAddress();
        }
      }
      if (master == null) {
        master = node.getThisAddress();
      }
      node.setMasterAddress(master);
      if (node.getMasterAddress().equals(node.getThisAddress())) {
        node.setJoined();
        node.setAsMaster();
      } else {
        final ClusterJoinManager clusterJoinManager = node.clusterService.getClusterJoinManager();

        for (int i = 0; !node.joined() && node.isRunning() && i < 2000; i++) {
          try {
            clusterJoinManager.sendJoinRequest(node.getMasterAddress(), true);
            Thread.sleep(50);
          } catch (InterruptedException e) {
            e.printStackTrace();
            break;
          }
        }
        if (!node.joined()) {
          logger.severe(
              "Node["
                  + node.getThisAddress()
                  + "] should have been joined to "
                  + node.getMasterAddress());
          node.shutdown(true);
        }
      }
    }
  }
Exemplo n.º 2
0
 public void doJoin(AtomicBoolean joined) {
   NodeEngineImpl nodeEngine = null;
   synchronized (joinerLock) {
     for (Address address : addresses) {
       NodeEngineImpl ne = nodes.get(address);
       if (ne != null && ne.getNode().isActive() && ne.getNode().joined()) {
         nodeEngine = ne;
         break;
       }
     }
     Address master = null;
     if (nodeEngine != null) {
       if (nodeEngine.getNode().isMaster()) {
         master = nodeEngine.getThisAddress();
       } else {
         master = nodeEngine.getMasterAddress();
       }
     }
     if (master == null) {
       master = node.getThisAddress();
     }
     node.setMasterAddress(master);
     if (node.getMasterAddress().equals(node.getThisAddress())) {
       node.setJoined();
     } else {
       for (int i = 0; !node.joined() && i < 1000; i++) {
         try {
           node.clusterService.sendJoinRequest(node.getMasterAddress(), true);
           Thread.sleep(50);
         } catch (InterruptedException e) {
           e.printStackTrace();
         }
       }
       if (!node.joined()) {
         throw new AssertionError(
             "Node["
                 + thisAddress
                 + "] should have been joined to "
                 + node.getMasterAddress());
       }
     }
   }
 }