public SequenceManager(SequenceStore store) {
sequenceStore = store;
}
public SequenceAcknowledgement assertValid(SequenceType sequence) {
Identifier identifier = sequence.getIdentifier();
Sequence s = sequenceStore.retrieve(identifier);
if (s == null) {
throw new SoapFault("The value of wsrm:Identifier is not a known Sequence identifier", "Sender",
"wsrm:UnknownSequence", identifier.toString());
}
// Is the message number out of range?
BigInteger value = sequence.getMessageNumber();
if (value.compareTo(BigInteger.ZERO) <= 0 || value.compareTo(MAX_INTEGER) > 0) {
// We must terminate the sequence now.
sequenceStore.delete(identifier);
throw new SoapFault("The maximum value for wsrm:MessageNumber has been exceeded", "Sender",
"wsrm:MessageNumberRollover", identifier.toString());
}
int intValue = value.intValue();
// If we received the last message, then check to see if the message
// being
// processed exceeds it's sequence.
if (s.lastMessageNumber > 0 && intValue > s.lastMessageNumber) {
throw new SoapFault(
"The value for wsrm:MessageNumber exceeds the value of the MessageNumber accompanying a LastMessage element in this Sequence.",
"Sender", "wsrm:LastMessageNumberExceeded", identifier.toString());
}
// Is this message comming out of order??
if (intValue != s.lastMessageAcked + 1) {
// This implementation is really simple and just drops out of order