Exemple #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);
        }
      }
    }
  }
  @Override
  public void afterRun() throws Exception {
    if (!valid || !sync || getCallId() == 0 || originalCaller == null) {
      return;
    }

    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    long callId = getCallId();
    OperationServiceImpl operationService = (OperationServiceImpl) nodeEngine.getOperationService();

    if (nodeEngine.getThisAddress().equals(originalCaller)) {
      operationService.getInvocationsRegistry().notifyBackupComplete(callId);
    } else {
      BackupResponse backupResponse = new BackupResponse(callId, backupOp.isUrgent());
      operationService.send(backupResponse, originalCaller);
    }
  }
 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());
       }
     }
   }
 }
  public void start() {
    logger.finest("Starting OperationService");

    ManagedExecutorService asyncExecutor =
        nodeEngine
            .getExecutionService()
            .register(
                ExecutionService.ASYNC_EXECUTOR,
                Runtime.getRuntime().availableProcessors(),
                ASYNC_QUEUE_CAPACITY,
                ExecutorType.CONCRETE);

    this.invocationContext =
        new Invocation.Context(
            asyncExecutor,
            nodeEngine.getClusterService().getClusterClock(),
            nodeEngine.getClusterService(),
            node.connectionManager,
            node.nodeEngine.getExecutionService(),
            nodeEngine.getProperties().getMillis(OPERATION_CALL_TIMEOUT_MILLIS),
            invocationRegistry,
            invocationMonitor,
            nodeEngine.getLocalMember().getUuid(),
            nodeEngine.getLogger(Invocation.class),
            node,
            nodeEngine,
            nodeEngine.getPartitionService(),
            this,
            operationExecutor,
            retryCount,
            serializationService,
            nodeEngine.getThisAddress());

    invocationMonitor.start();
    operationExecutor.start();
    asyncResponseHandler.start();
    slowOperationDetector.start();
  }