use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange in project cxf by apache.
the class DestinationSequence method mergeRanges.
void mergeRanges() {
List<AcknowledgementRange> ranges = acknowledgement.getAcknowledgementRange();
for (int i = ranges.size() - 1; i > 0; i--) {
AcknowledgementRange current = ranges.get(i);
AcknowledgementRange previous = ranges.get(i - 1);
if (current.getLower().longValue() - previous.getUpper().longValue() == 1) {
previous.setUpper(current.getUpper());
ranges.remove(i);
}
}
}
use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange in project cxf by apache.
the class DestinationSequence method acknowledge.
public void acknowledge(Message message) throws SequenceFault {
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
SequenceType st = rmps.getSequence();
long messageNumber = st.getMessageNumber().longValue();
LOG.fine("Acknowledging message: " + messageNumber);
if (0 != lastMessageNumber && messageNumber > lastMessageNumber) {
RMConstants consts = getProtocol().getConstants();
SequenceFaultFactory sff = new SequenceFaultFactory(consts);
throw sff.createSequenceTerminatedFault(st.getIdentifier(), false);
}
monitor.acknowledgeMessage();
boolean updated = false;
synchronized (this) {
boolean done = false;
int i = 0;
for (; i < acknowledgement.getAcknowledgementRange().size(); i++) {
AcknowledgementRange r = acknowledgement.getAcknowledgementRange().get(i);
if (r.getLower().compareTo(messageNumber) <= 0 && r.getUpper().compareTo(messageNumber) >= 0) {
done = true;
break;
}
long diff = r.getLower() - messageNumber;
if (diff == 1) {
r.setLower(messageNumber);
updated = true;
done = true;
} else if (diff > 0) {
break;
} else if (messageNumber - r.getUpper().longValue() == 1) {
r.setUpper(messageNumber);
updated = true;
done = true;
break;
}
}
if (!done) {
// need new acknowledgement range
AcknowledgementRange range = new AcknowledgementRange();
range.setLower(messageNumber);
range.setUpper(messageNumber);
updated = true;
acknowledgement.getAcknowledgementRange().add(i, range);
if (acknowledgement.getAcknowledgementRange().size() > 1) {
// acknowledge out-of-order at first opportunity
scheduleImmediateAcknowledgement();
}
}
mergeRanges();
}
if (updated) {
RMStore store = destination.getManager().getStore();
if (null != store && !MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY)) {
try {
RMMessage msg = new RMMessage();
CachedOutputStream cos = (CachedOutputStream) message.get(RMMessageConstants.SAVED_CONTENT);
msg.setMessageNumber(st.getMessageNumber());
msg.setCreatedTime(rmps.getCreatedTime());
// in case no attachments are available, cos can be saved directly
if (message.getAttachments() == null) {
msg.setContent(cos);
msg.setContentType((String) message.get(Message.CONTENT_TYPE));
} else {
InputStream is = cos.getInputStream();
PersistenceUtils.encodeRMContent(msg, message, is);
}
store.persistIncoming(this, msg);
} catch (IOException e) {
throw new Fault(e);
}
}
}
deliveringMessageNumbers.add(messageNumber);
RMEndpoint reliableEndpoint = destination.getReliableEndpoint();
RMConfiguration cfg = reliableEndpoint.getConfiguration();
if (null == rmps.getCloseSequence()) {
scheduleAcknowledgement(cfg.getAcknowledgementIntervalTime());
}
long inactivityTimeout = cfg.getInactivityTimeoutTime();
scheduleSequenceTermination(inactivityTimeout);
}
use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange in project cxf by apache.
the class DestinationSequenceTest method testAcknowledgeInsertRange.
@Test
public void testAcknowledgeInsertRange() throws SequenceFault {
Timer timer = control.createMock(Timer.class);
setUpDestination(timer, null);
Message[] messages = new Message[] { setUpMessage("1"), setUpMessage("2"), setUpMessage("9"), setUpMessage("10"), setUpMessage("4"), setUpMessage("9"), setUpMessage("2") };
control.replay();
DestinationSequence seq = new DestinationSequence(id, ref, destination, ProtocolVariation.RM10WSA200408);
List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange();
for (int i = 0; i < messages.length; i++) {
seq.acknowledge(messages[i]);
}
assertEquals(3, ranges.size());
AcknowledgementRange r = ranges.get(0);
assertEquals(1, r.getLower().intValue());
assertEquals(2, r.getUpper().intValue());
r = ranges.get(1);
assertEquals(4, r.getLower().intValue());
assertEquals(4, r.getUpper().intValue());
r = ranges.get(2);
assertEquals(9, r.getLower().intValue());
assertEquals(10, r.getUpper().intValue());
control.verify();
}
use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange in project cxf by apache.
the class DestinationSequenceTest method testAcknowledgeBasic.
@Test
public void testAcknowledgeBasic() throws SequenceFault {
Timer timer = control.createMock(Timer.class);
setUpDestination(timer, null);
Message message1 = setUpMessage("1");
Message message2 = setUpMessage("2");
control.replay();
DestinationSequence seq = new DestinationSequence(id, ref, destination, ProtocolVariation.RM10WSA200408);
List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange();
assertEquals(0, ranges.size());
seq.acknowledge(message1);
assertEquals(1, ranges.size());
AcknowledgementRange r1 = ranges.get(0);
assertEquals(1, r1.getLower().intValue());
assertEquals(1, r1.getUpper().intValue());
seq.acknowledge(message2);
assertEquals(1, ranges.size());
r1 = ranges.get(0);
assertEquals(1, r1.getLower().intValue());
assertEquals(2, r1.getUpper().intValue());
control.verify();
}
use of org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange in project cxf by apache.
the class DestinationSequenceTest method testAcknowledgePrependRange.
@Test
public void testAcknowledgePrependRange() throws SequenceFault {
Timer timer = control.createMock(Timer.class);
setUpDestination(timer, null);
Message[] messages = new Message[] { setUpMessage("4"), setUpMessage("5"), setUpMessage("6"), setUpMessage("4"), setUpMessage("2"), setUpMessage("2") };
control.replay();
DestinationSequence seq = new DestinationSequence(id, ref, destination, ProtocolVariation.RM10WSA200408);
List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange();
for (int i = 0; i < messages.length; i++) {
seq.acknowledge(messages[i]);
}
assertEquals(2, ranges.size());
AcknowledgementRange r = ranges.get(0);
assertEquals(2, r.getLower().intValue());
assertEquals(2, r.getUpper().intValue());
r = ranges.get(1);
assertEquals(4, r.getLower().intValue());
assertEquals(6, r.getUpper().intValue());
control.verify();
}
Aggregations