Mark the messages in the sequence delivered according to the contents
of the specified SequenceAcknowledgement
element.
synchronized (sequence) {
sequence.setBufferRemaining(element.getBufferRemaining());
List<SequenceAcknowledgementElement.AcknowledgementRange> ranges =
element.getAcknowledgementRange();
List<BigInteger> nacks = element.getNack();
//TODO - error checking
//either nacks or ranges must be null or protocol element is malformed.
if (nacks != null && !nacks.isEmpty()) {
int size = sequence.getNextIndex() + 1;
ArrayList<Boolean> list = new ArrayList<Boolean>();
for (int i = 1; i < sequence.getNextIndex(); i++) {
list.set(i, true);
}
for (BigInteger big : nacks) {
int index = (int)big.longValue();
list.set(index, false);
}
for (int i = 1; i < sequence.getNextIndex();i++) {
Message mess = sequence.get(i);
if (list.get(i)) {
acknowledgeIfValid(sequence, i);
}
}
} else {
for (SequenceAcknowledgementElement.AcknowledgementRange range : ranges) {
int lower = range.getLower().intValue();
int upper = range.getUpper().intValue();
//if a SequenceHeader with Last elemet has been sent, we may
//receive acks for that "Message" although one was never stored
//at the index.
if (sequence.isLast() && upper == sequence.getNextIndex()) {
upper--;
}
for (int i = lower; i <= upper; i++) {
acknowledgeIfValid(sequence, i);
}
}
}
}