FileDocCategorySizeDatePackage
AcknowledgementHandler.javaAPI DocExample6285Tue May 29 16:56:44 BST 2007com.sun.xml.ws.rm.protocol

AcknowledgementHandler

public class AcknowledgementHandler extends Object
Utility class that manages the acknowledgement of sequence messages. Methods return the values for AckRequested protocol requests as well as update Sequence contents based on SequenceAcknowledgement protocol elements.

Fields Summary
private static final Logger
logger
protected com.sun.xml.ws.rm.jaxws.runtime.SequenceConfig
config
Configuration for this sequence.
Constructors Summary
public AcknowledgementHandler(com.sun.xml.ws.rm.jaxws.runtime.SequenceConfig seqConfig)



       
        this.config = seqConfig;
    
Methods Summary
private voidacknowledgeIfValid(com.sun.xml.ws.rm.jaxws.runtime.OutboundSequence seq, int i)
We may receive an ack for an unknown message if we are restarting after a crash or if the RMD is broken. Allow processing to continue after logging.

        try {
            Message mess = seq.get(i);
            if (mess != null) {
                seq.acknowledge(i);
            }
        } catch (InvalidMessageNumberException e) {
            //this can happen if the sequence has been resurrected
            //after a restart.
            logger.fine(Messages.ACKNOWLEDGEMENT_MESSAGE.format(seq.getId(), i));
            
        }
    
public voidhandleAcknowledgement(com.sun.xml.ws.rm.jaxws.runtime.OutboundSequence sequence, SequenceAcknowledgementElement element)
Mark the messages in the sequence delivered according to the contents of the specified SequenceAcknowledgement element.

param
element The SequenceAcknowledgementElement

        
        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);
                    }
                }
            } 
        }