Determine the RDY value, and set it. It can either be a static value
        a callback, or None. If it's None, we'll calculate the value based on
        our limits and connection counts.

        The documentation recommends starting with (1), but since we are always
        dealing directly with *nsqd* servers by now, we'll always have a valid
        count to work with. Since we derive this count off a set of servers 
        that will always be up-to-date, we have everything we need, here, going
        forward.

def __send_rdy(self, connection, command):
        """Determine the RDY value, and set it. It can either be a static value
        a callback, or None. If it's None, we'll calculate the value based on
        our limits and connection counts.

        The documentation recommends starting with (1), but since we are always
        dealing directly with *nsqd* servers by now, we'll always have a valid
        count to work with. Since we derive this count off a set of servers 
        that will always be up-to-date, we have everything we need, here, going
        forward.
        """

        if self.__consumer.original_rdy is None:
            node_count = self.__consumer.get_node_count_for_topic(
                            connection.context.topic)

            self.__logger_rdy.debug("Calculating RDY: max_in_flight=(%d) "
                                    "node_count=(%d)", 
                                    self.__consumer.max_in_flight, node_count)

            if self.__consumer.max_in_flight >= node_count:
                # Calculate the RDY based on the max_in_flight and total number 
                # of servers. We always round up, or else we'd run the risk of 
                # not facilitating some servers.
                rdy_this = int(math.ceil(
                                        float(self.__consumer.max_in_flight) /
                                        float(node_count)))

                self.__logger_rdy.debug("Assigning RDY based on max_in_flight "
                                        "(%d) and node count (%d) (optimal): "
                                        "(%d)", 
                                        self.__consumer.max_in_flight, 
                                        node_count, rdy_this)
            else:
                # We have two possible scenarios:
                # (1) The client is starting up, and the total RDY count is 
                #     already accounted for.
                # (2) The client is already started, and another connection has
                #     a (0) RDY count.
                #
                # In the case of (1), we'll take an RDY of (0). In the case of
                # (2) We'll send an RDY of (1) on their behalf, before we 
                # assume a (0) for ourself.

                # Look for existing connections that have a (0) RDY (which 
                # would've only been set to (0) intentionally).

                self.__logger_rdy.debug("(max_in_flight > nodes). Doing RDY "
                                        "election.")

                sleeping_connections = [
                    c \
                    for (c, info) \
                    in self.__consumer.connection_context.items() \
                    if info['rdy_count'] == 0]

                self.__logger_rdy.debug("Current sleeping_connections: %s", 
                                        sleeping_connections)

                if sleeping_connections:
                    elected_connection = random.choice(sleeping_connections)
                    self.__logger_rdy.debug("Sending RDY of (1) on: [%s]", 
                                            elected_connection)

                    command_elected = nsq.command.Command(elected_connection)
                    command_elected.rdy(1)
                else:
                    self.__logger.debug("No sleeping connections. We got the "
                                        "short stick: [%s]", connection)

                rdy_this = 0
        else:
            try:
                rdy_this = self.__consumer.original_rdy(
                            connection.node, 
                            self.__consumer.connection_count, 
                            self.__consumer)

                self.__logger_rdy.debug("Using RDY from callback: (%d)", 
                                        rdy_this)
            except TypeError:
                rdy_this = self.__consumer.original_rdy
                self.__logger_rdy.debug("Using static RDY: (%d)", rdy_this)

        # Make sure that the aggregate set of RDY counts doesn't exceed the 
        # max. This constrains the previous value, above.
        rdy_this = min(rdy_this + \
                        self.__get_total_rdy_count(), 
                       self.__consumer.max_in_flight)

        # Make sure we don't exceed the maximum specified by the server. This 
        # only works because we're running greenlets, not threads. At any given 
        # time, only one greenlet is running, and we can make sure to 
        # distribute the remainder of (max_in_flight / nodes) across a subset 
        # of the nodes (they don't all have to have an even slice of 
        # max_in_flight).

        server_features = self.__consumer.identify.server_features
        max_rdy_count = server_features['max_rdy_count']
        rdy_this = min(max_rdy_count, rdy_this)

        self.__logger_rdy.debug("Final RDY (max_in_flight=(%d) "
                                "max_rdy_count=(%d)): (%d)", 
                                self.__consumer.max_in_flight, max_rdy_count, 
                                rdy_this)

        if rdy_this > 0:
            command.rdy(rdy_this)
        else:
            self.__logger_rdy.info("This connection will go to sleep (not "
                                   "enough RDY to go around).")

        return rdy_this