def update_status(broker, connected_before)
      after = connected
      before = after.clone
      before.delete(broker.identity) if broker.connected? && !connected_before
      before.push(broker.identity) if !broker.connected? && connected_before
      unless before == after
        logger.info("[status] Broker #{broker.alias} is now #{broker.status}, " +
                    "connected brokers: [#{aliases(after).join(", ")}]")
      end
      @connection_status.reject! do |k, v|
        reject = false
        if v[:brokers].nil? || v[:brokers].include?(broker.identity)
          b, a, n, f = if v[:brokers].nil?
            [before, after, @brokers.size, all]
          else
            [before & v[:brokers], after & v[:brokers], v[:brokers].size, v[:brokers]]
          end
          update = if v[:boundary] == :all
            if b.size < n && a.size == n
              :connected
            elsif (f - failed).empty?
              :failed
            elsif b.size == n && a.size < n
              :disconnected
            end
          else
            if b.size == 0 && a.size > 0
              :connected
            elsif (f - failed).empty?
              :failed
            elsif b.size > 0 && a.size == 0
              :disconnected
            end
          end
          if update
            v[:callback].call(update)
            if v[:timer]
              v[:timer].cancel
              reject = true
            end
          end
        end
        reject
      end
      true
    end
def update_status(broker, connected_before)
      after = connected
      before = after.clone
      before.delete(broker.identity) if broker.connected? && !connected_before
      before.push(broker.identity) if !broker.connected? && connected_before
      unless before == after
        logger.info("[status] Broker #{broker.alias} is now #{broker.status}, " +
                    "connected brokers: [#{aliases(after).join(", ")}]")
      end
      @connection_status.reject! do |k, v|
        reject = false
        if v[:brokers].nil? || v[:brokers].include?(broker.identity)
          b, a, n, f = if v[:brokers].nil?
            [before, after, @brokers.size, all]
          else
            [before & v[:brokers], after & v[:brokers], v[:brokers].size, v[:brokers]]
          end
          update = if v[:boundary] == :all
            if b.size < n && a.size == n
              :connected
            elsif (f - failed).empty?
              :failed
            elsif b.size == n && a.size < n
              :disconnected
            end
          else
            if b.size == 0 && a.size > 0
              :connected
            elsif (f - failed).empty?
              :failed
            elsif b.size > 0 && a.size == 0
              :disconnected
            end
          end
          if update
            v[:callback].call(update)
            if v[:timer]
              v[:timer].cancel
              reject = true
            end
          end
        end
        reject
      end
      true
    end
Callback from broker client with connection status update
 Makes client callback with :connected or :disconnected status if boundary crossed,
 or with :failed if all selected brokers or all brokers have failed

 === Parameters
 broker(BrokerClient):: Broker client reporting status update
 connected_before(Boolean):: Whether client was connected before this update

 === Return
 true:: Always return true