コード例 #1
0
  public boolean failoverAllowed() {
    // We allow to Failover provided
    // our broker list is not empty and
    // we haven't gone through all of them

    boolean b =
        _connectionDetails.getBrokerCount() > 0
            && _failedAttemps <= _connectionDetails.getBrokerCount();

    _logger.info("============================================================");
    _logger.info(toString());
    _logger.info("FailoverAllowed " + b);
    _logger.info("============================================================");

    return b;
  }
コード例 #2
0
  public BrokerDetails getNextBrokerDetails() {
    BrokerDetails broker = null;

    synchronized (_brokerListLock) {
      if (_currentBrokerIndex == (_connectionDetails.getBrokerCount() - 1)) {
        _currentBrokerIndex = 0;
      } else {
        _currentBrokerIndex++;
      }

      broker = _connectionDetails.getBrokerDetails(_currentBrokerIndex);

      // When the broker list is updated it will include the current broker as well
      // There is no point trying it again, so trying the next one.
      if (_currentBrokerDetail != null
          && broker.getHost().equals(_currentBrokerDetail.getHost())
          && broker.getPort() == _currentBrokerDetail.getPort()) {
        if (_connectionDetails.getBrokerCount() > 1) {
          return getNextBrokerDetails();
        } else {
          _failedAttemps++;
          return null;
        }
      }
    }

    String delayStr = broker.getProperty(BrokerDetails.OPTIONS_CONNECT_DELAY);
    if (delayStr != null) {
      Long delay = Long.parseLong(delayStr);
      _logger.info("Delay between connect retries:" + delay);
      try {
        Thread.sleep(delay);
      } catch (InterruptedException ie) {
        return null;
      }
    } else {
      _logger.info(
          "No delay between connect retries, use tcp://host:port?connectdelay='value' to enable.");
    }

    _failedAttemps++;
    _currentBrokerDetail = broker;

    return broker;
  }
コード例 #3
0
  public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("FailoverExchange:\n");
    sb.append("\n Current Broker Index:");
    sb.append(_currentBrokerIndex);
    sb.append("\n Failed Attempts:");
    sb.append(_failedAttemps);
    sb.append("\n Orignal broker details:");
    sb.append(_originalBrokerDetail).append("\n");
    sb.append("\n -------- Broker List -----------\n");
    for (int i = 0; i < _connectionDetails.getBrokerCount(); i++) {
      if (i == _currentBrokerIndex) {
        sb.append(">");
      }

      sb.append(_connectionDetails.getBrokerDetails(i));
      sb.append("\n");
    }
    sb.append("--------------------------------\n");
    return sb.toString();
  }