Search in sources :

Example 1 with AcknowledgementRange

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);
        }
    }
}
Also used : AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)

Example 2 with AcknowledgementRange

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);
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) InputStream(java.io.InputStream) RMStore(org.apache.cxf.ws.rm.persistence.RMStore) Fault(org.apache.cxf.interceptor.Fault) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)

Example 3 with AcknowledgementRange

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();
}
Also used : Timer(java.util.Timer) Message(org.apache.cxf.message.Message) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange) Test(org.junit.Test)

Example 4 with AcknowledgementRange

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();
}
Also used : Timer(java.util.Timer) Message(org.apache.cxf.message.Message) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange) Test(org.junit.Test)

Example 5 with AcknowledgementRange

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();
}
Also used : Timer(java.util.Timer) Message(org.apache.cxf.message.Message) AcknowledgementRange(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange) Test(org.junit.Test)

Aggregations

AcknowledgementRange (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement.AcknowledgementRange)14 Test (org.junit.Test)10 Message (org.apache.cxf.message.Message)5 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)5 ArrayList (java.util.ArrayList)4 Timer (java.util.Timer)4 InputStream (java.io.InputStream)2 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)2 ManagedOperation (org.apache.cxf.management.annotation.ManagedOperation)2 ManagedOperationParameters (org.apache.cxf.management.annotation.ManagedOperationParameters)2 RMProperties (org.apache.cxf.ws.rm.RMProperties)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Fault (org.apache.cxf.interceptor.Fault)1 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)1 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)1 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)1 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)1