public RequestStatus trySendMore()

in accord-core/src/main/java/accord/coordinate/tracking/ReadTracker.java [285:336]


    public <T1> RequestStatus trySendMore(BiConsumer<T1, Id> contact, T1 with)
    {
        ShardSelection toRead;
        {
            ShardSelection tmp = null;
            for (int i = 0 ; i < trackers.length ; ++i)
            {
                ReadShardTracker tracker = trackers[i];
                if (tracker == null || !tracker.shouldRead() || !tracker.canRead())
                    continue;

                if (tmp == null)
                    tmp = new ShardSelection(); // determinism

                tmp.set(i);
            }
            toRead = tmp;
        }

        Invariants.checkState(toRead != null, "We were asked to read more, but found no shards in need of reading more");

        // TODO (desired, consider): maybe for each additional candidate do one linear compare run to find better secondary match
        //       OR at least discount candidates that do not contribute additional knowledge beyond those additional
        //       candidates already contacted, since implementations are likely to sort primarily by health
        candidates.sort((a, b) -> topologies().compare(a, b, toRead));
        int i = candidates.size() - 1;
        while (i >= 0)
        {
            Id candidate = candidates.get(i);
            topologies().forEach((topology, ti) -> {
                int offset = topologyOffset(ti);
                topology.forEachOn(candidate, (s, si) -> toRead.clear(offset + si));
            });

            if (toRead.isEmpty())
                break;

            --i;
        }

        if (!toRead.isEmpty())
            return RequestStatus.NoChange;

        for (int j = candidates.size() - 1; j >= i; --j)
        {
            Id candidate = candidates.get(j);
            recordInFlightRead(candidate);
            contact.accept(with, candidate);
            candidates.remove(j);
        }
        return RequestStatus.NoChange;
    }