Exemplo n.º 1
0
  protected JoinMessage sendSplitBrainJoinMessage(Address target) {
    if (logger.isFinestEnabled()) {
      logger.finest(node.getThisAddress() + " is connecting to " + target);
    }

    Connection conn = node.connectionManager.getOrConnect(target, true);
    long timeout = SPLIT_BRAIN_CONN_TIMEOUT;
    while (conn == null) {
      timeout -= SPLIT_BRAIN_SLEEP_TIME;
      if (timeout < 0) {
        return null;
      }
      try {
        //noinspection BusyWait
        Thread.sleep(SPLIT_BRAIN_SLEEP_TIME);
      } catch (InterruptedException e) {
        EmptyStatement.ignore(e);
        return null;
      }
      conn = node.connectionManager.getConnection(target);
    }

    NodeEngine nodeEngine = node.nodeEngine;
    Future future =
        nodeEngine
            .getOperationService()
            .createInvocationBuilder(
                ClusterServiceImpl.SERVICE_NAME,
                new JoinCheckOperation(node.createSplitBrainJoinMessage()),
                target)
            .setTryCount(1)
            .invoke();
    try {
      return (JoinMessage) future.get(SPLIT_BRAIN_JOIN_CHECK_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    } catch (TimeoutException e) {
      logger.finest("Timeout during join check!", e);
    } catch (Exception e) {
      logger.warning("Error during join check!", e);
    }
    return null;
  }