def connect(host, port, index, priority = nil, force = false, &blk)
      identity = self.class.identity(host, port)
      existing = @brokers_hash[identity]
      if existing && existing.usable? && !force
        logger.info("Ignored request to reconnect #{identity} because already #{existing.status.to_s}")
        false
      else
        old_identity = identity
        @brokers.each do |b|
          if index == b.index
            # Changing host and/or port of existing broker client
            old_identity = b.identity
            break
          end
        end unless existing

        address = {:host => host, :port => port, :index => index}
        broker = BrokerClient.new(identity, address, @serializer, @exception_stats, @non_delivery_stats, @options, existing)
        p = priority(old_identity)
        if priority && priority < p
          @brokers.insert(priority, broker)
        elsif priority && priority > p
          logger.info("Reduced priority setting for broker #{identity} from #{priority} to #{p} to avoid gap in list")
          @brokers.insert(p, broker)
        else
          @brokers[p].close if @brokers[p]
          @brokers[p] = broker
        end
        @brokers_hash[identity] = broker
        yield broker.identity if block_given?
        true
      end
    end
def connect(host, port, index, priority = nil, force = false, &blk)
      identity = self.class.identity(host, port)
      existing = @brokers_hash[identity]
      if existing && existing.usable? && !force
        logger.info("Ignored request to reconnect #{identity} because already #{existing.status.to_s}")
        false
      else
        old_identity = identity
        @brokers.each do |b|
          if index == b.index
            # Changing host and/or port of existing broker client
            old_identity = b.identity
            break
          end
        end unless existing

        address = {:host => host, :port => port, :index => index}
        broker = BrokerClient.new(identity, address, @serializer, @exception_stats, @non_delivery_stats, @options, existing)
        p = priority(old_identity)
        if priority && priority < p
          @brokers.insert(priority, broker)
        elsif priority && priority > p
          logger.info("Reduced priority setting for broker #{identity} from #{priority} to #{p} to avoid gap in list")
          @brokers.insert(p, broker)
        else
          @brokers[p].close if @brokers[p]
          @brokers[p] = broker
        end
        @brokers_hash[identity] = broker
        yield broker.identity if block_given?
        true
      end
    end
Make new connection to broker at specified address unless already connected
 or currently connecting

 === Parameters
 host{String):: IP host name or address for individual broker
 port(Integer):: TCP port number for individual broker
 index(Integer):: Unique index for broker within set for use in forming alias
 priority(Integer|nil):: Priority position of this broker in set for use by this agent
   with nil or a value that would leave a gap in the list meaning add to end of list
 force(Boolean):: Reconnect even if already connected

 === Block
 Optional block with following parameters to be called after initiating the connection
 unless already connected to this broker:
   identity(String):: Broker serialized identity

 === Return
 (Boolean):: true if connected, false if no connect attempt made

 === Raise
 Exception:: If host and port do not match an existing broker but index does