FileDocCategorySizeDatePackage
OutboundSequence.javaAPI DocExample14326Tue May 29 16:56:42 BST 2007com.sun.xml.ws.rm.jaxws.runtime

OutboundSequence

public abstract class OutboundSequence extends Sequence

Fields Summary
private static final Logger
logger
protected URI
destination
Common destination for all application messages in the sequence.
protected URI
acksTo
Endpoint for protocol responses. May be the WS-Addressing anonymous endpoint. There are several variations depending on whether this EPR is the same as the one used by application messages in the companion InboundSequence
protected InboundSequence
inboundSequence
Companion InboundSequence
protected com.sun.xml.ws.rm.protocol.SequenceAcknowledgementElement
sequenceAcknowledgement
Sequence acknowledgement to be sent back to client on next available message to the AcksTo endpoint.
protected SequenceConfig
config
Configuration for this sequence.
protected com.sun.xml.ws.rm.protocol.AcknowledgementHandler
ackHandler
Instance of helper class that processes SequnceAcknowledgement headers.
public boolean
saveMessages
Flag determines whether messages will be saved. Will only be false in the case of companions to ServerInboundSequences for endpoints with no two-way operations.
private com.sun.xml.ws.rm.jaxws.util.ProcessingFilter
filter
Processing filter whose handleRequestHeaders method can access headers before they are marshalled.
protected int
bufferRemaining
Space available in receiving buffer at destination, if this can be determined.
Constructors Summary
Methods Summary
public synchronized voidacknowledge(int i)
Sets the state of the message at the specified index to complete, and discards a com.sun.xml.ws.api.message.Message.

param
i Index to set.

        
        Message mess;
        if (i >= nextIndex || (null == (mess = get(i)))) {
            throw new InvalidMessageNumberException();
        }
       
        if (!mess.isComplete()) {
            
            --storedMessages;
            if (storedMessages == 0) {
                //A thread on which waitForAcks() has been called
                //may be waiting for all the acks to arrive.
                notifyAll();
            }
            
            mess.complete();
        }
    
protected com.sun.xml.ws.api.message.HeadercreateHeader(java.lang.Object obj)

        return Headers.create(
                config.getRMConstants().getJAXBRIContextHeaders(),
                obj);
    
public voidensureAckRequested(Message mess, javax.xml.bind.Marshaller marshaller)
Add AckRequested element to an existing message if one is not already present. This is used to ensure that an AckRequested header is included on every resend.

param
mess The message
param
marshaller

        if (mess.getAckRequestedElement() == null) {
            
            AckRequestedElement ack = new AckRequestedElement();
            ack.setId(this.getId());      
            mess.setAckRequestedElement(ack);
           /*
            mess.addHeader(Headers.create(getVersion(), 
                               marshaller,
                               mess.getAckRequestedElement()));
            */
            mess.addHeader(createHeader(mess.getAckRequestedElement()));
        }
    
public java.net.URIgetAcksTo()
Accessor for the value of the Destination URI.

return
The destination String.

       
        return acksTo;
    
public intgetBufferRemaining()
Accessor for bufferRemaining field.

        return bufferRemaining;
    
public java.net.URIgetDestination()
Accessor for the value of the Destination URI.

return
The destination URI.

    
                      
       
     
        return destination;
    
public InboundSequencegetInboundSequence()
Accessor for the inboundSequence field.

return
The inboundSequence field.

        return inboundSequence;
    
private com.sun.xml.ws.api.SOAPVersiongetVersion()

        return config.getSoapVersion();
    
public voidhandleAckResponse(com.sun.xml.ws.rm.protocol.SequenceAcknowledgementElement element)
Removes acked messages from list. (For anonymous client, need to widen definition of acked to include the requirement that responses have arrived.)

param
element The SequenceAcknowledgementElement containing the ranges of messages to be removed.


        if (ackHandler == null) {
            ackHandler = new AcknowledgementHandler(config);
        }
        ackHandler.handleAcknowledgement(this, element);
    
protected booleanisAckRequested()

         //For oneway messages it does not make sense to send
         // AckRequestedElement on the ServerOutbound messages
         //saveMessages will be true in case of two way messages
         // for AckRequestedElement will be generated then
         //otherwise it will return false
         return saveMessages;
     
protected booleanisResendDue()

         return true;
     
public synchronized voidprocessAcknowledgement(Message mess, javax.xml.bind.Marshaller marshaller)
Add a pending acknowledgement to a message without adding message to sequence. Used for sending final ack on a TerminateSequence message if necessary.

param
mess The OutboundMessage.
param
marshaller The Marshaller to use

        //if companion Inbound sequence is returning an acknowledgement, add the
        //SequenceAcknowledgement header
        if (sequenceAcknowledgement != null) {
            //mess.addHeader(Headers.create(getVersion(), marshaller,sequenceAcknowledgement));
            mess.addHeader(createHeader(sequenceAcknowledgement));
            
            sequenceAcknowledgement = null;
        }       
    
public voidprocessOutboundMessage(Message mess, javax.xml.bind.Marshaller marshaller)
Handles an OutboundMessage.
  • Store the message
  • If ackRequested flag is set, add an AckRequestedElement header to the message.
  • If complanion ClientInboundSequence has queued an acknowledgement, add a SequenceAcknowledgementElement header to the message.

param
mess The OutboundMessage.
param
marshaller The Marshaller to use

        
        if (saveMessages && !mess.isOneWayResponse ) {
            //Add the message to the sequence unless this has been done previously
            int messageNumber = mess.getMessageNumber();

            if (messageNumber == 0) {
                messageNumber = set(getNextIndex(), mess);
            } else {
                set(messageNumber, mess);
            }

            SequenceElement element = new SequenceElement();
            element.setNumber(messageNumber);
            element.setId(this.getId());
            
            //mess.addHeader(Headers.create(getVersion(),marshaller,element));
            
            mess.setSequenceElement(element);
            
             //if it is time to request an ack for this sequence, add AckRequestedHeader
            if (isAckRequested()) {
                AckRequestedElement ack = new AckRequestedElement();
                ack.setId(this.getId());      
                mess.setAckRequestedElement(ack);
            }
        }
        
        //if companion Inbound sequence is returning an acknowledgement, add the
        //SequenceAcknowledgement header
        if (sequenceAcknowledgement != null) {
            //mess.addHeader(Headers.create(getVersion(), marshaller,sequenceAcknowledgement));
            
            mess.setSequenceAcknowledgementElement(sequenceAcknowledgement);
            
            sequenceAcknowledgement = null;
        }     
        
        if (filter != null) {
            filter.handleOutboundHeaders(mess);
        }
        
        if (mess.getSequenceElement() != null) {
            /*
            mess.addHeader(Headers.create(getVersion(),
                            marshaller,
                            mess.getSequenceElement()));
             */
            mess.addHeader(createHeader(mess.getSequenceElement()));
        }
        
        if (mess.getAckRequestedElement() != null) {
            /*
            mess.addHeader(Headers.create(getVersion(), 
                           marshaller,
                           mess.getAckRequestedElement()));
             */
             mess.addHeader(createHeader(mess.getAckRequestedElement()));
        }
        
        if (mess.getSequenceAcknowledgementElement() != null) {
            /*
            mess.addHeader(Headers.create(getVersion(), 
                           marshaller,
                           mess.getSequenceAcknowledgementElement()));
             */
             mess.addHeader( createHeader(mess.getSequenceAcknowledgementElement()));
        }   
    
public voidsetBufferRemaining(int value)
Mutator for bufferRemaining field.

        bufferRemaining = value;
    
public voidsetProcessingFilter(com.sun.xml.ws.rm.jaxws.util.ProcessingFilter filter)

        this.filter = filter;
    
public voidsetSequenceAcknowledgement(com.sun.xml.ws.rm.protocol.SequenceAcknowledgementElement element)
Invoked by Incoming message processor to post Sequence Acknowledgement from companion Incoming Sequence for transmission on next OutboundMessage.l

        this.sequenceAcknowledgement = element;
    
public synchronized voidwaitForAcks()
Called by disconnect before sending Last and Terminate sequence. Blocks until all messages have been acked. The notifyAll method is called by OutboundSequence.acknowledge when stored message count reaches 0.

    
        while (storedMessages != 0) {
            try {
                //wait for the specified timeout or a notify(), which is called
                //whenever a message is acked.
                long timeout = config.getCloseTimeout();
                wait(timeout);
                
                if (storedMessages > 0) {      
                    logger.severe(Messages.TIMEOUT_IN_WAITFORACKS_STRING
                            .format(timeout / 1000 , storedMessages));
                    break;
                }
            } catch (InterruptedException e) {
                //allow preDestroy to continue
                break;
            }
        }