}
private void purgeCandidates(SourceSequence seq, boolean any) {
Collection<Long> purged = new ArrayList<Long>();
Collection<ResendCandidate> resends = new ArrayList<ResendCandidate>();
Identifier sid = seq.getIdentifier();
synchronized (this) {
LOG.fine("Start purging resend candidates.");
List<ResendCandidate> sequenceCandidates = getSequenceCandidates(seq);
if (null != sequenceCandidates) {
for (int i = sequenceCandidates.size() - 1; i >= 0; i--) {
ResendCandidate candidate = sequenceCandidates.get(i);
long m = candidate.getNumber();
if (any || seq.isAcknowledged(m)) {
sequenceCandidates.remove(i);
candidate.resolved();
unacknowledgedCount--;
purged.add(m);
resends.add(candidate);
}
}
if (sequenceCandidates.isEmpty()) {
candidates.remove(sid.getValue());
}
}
LOG.fine("Completed purging resend candidates.");
}
if (purged.size() > 0) {
RMStore store = manager.getStore();
if (null != store) {
store.removeMessages(sid, purged, true);
}
RMEndpoint rmEndpoint = seq.getSource().getReliableEndpoint();
for (ResendCandidate resend: resends) {
rmEndpoint.handleAcknowledgment(sid.getValue(), resend.getNumber(), resend.getMessage());
}
}
}