FileDocCategorySizeDatePackage
Sequence.javaAPI DocExample8512Tue May 29 16:56:42 BST 2007com.sun.xml.ws.rm

Sequence

public class Sequence extends Object
A Sequence is a sparse array of messages corresponding to an RM Sequence. It is implemented as an ArrayList with nulls at unfilled indices.

Fields Summary
protected String
id
The sequence identifier.
protected ArrayList
list
The underlying list of messages
protected int
nextIndex
The smallest unfilled index.
protected boolean
last
Flag indicates that message with Sequence header containing Last element has been sent/received. If this is the case, SequenceAcknowledgements for the sequence may contain acks for a message is one greater than the index for the last message in the sequence.
protected int
maxMessages
Maximum number of stored messages. Used for server-side sequences for which flow control is enabled. The value -1 indicates that there is no limit.
protected int
storedMessages
Number of messages currently being stored awaiting completion.
protected long
lastActivityTime
Last accesse time.
protected boolean
allowDuplicates
protected RMConstants
rmConstants
RMConstants associated with each Sequence which will give information regarding addressing version, JAXBContext etc
protected int
firstKnownGap
Constructors Summary
public Sequence()

        
        list = new ArrayList<Message>();
        //fill in 0-th index that will never be used since
        //messageNumbers are 1-based and we will be keeping
        //messageNumbers in-sync with indices.
        list.add(null);
        allowDuplicates = false;
        firstKnownGap = 1;

	resetLastActivityTime();

    
Methods Summary
public synchronized Messageget(int index)
Gets the Message at the specified index.

param
index The index to access
return
The Message at the specified index
throws
InvalidMessageNumberException If the index is larger than the largest index used.

        
        if (index >= nextIndex) {
            throw new InvalidMessageNumberException(
                    Messages.INVALID_INDEX_MESSAGE.format(index));
        }
        return list.get(index);
    
public java.lang.StringgetId()
Gets the sequence identifier

return
The sequence identifier.

                 
       
        return id;
    
protected longgetLastActivityTime()
Accessor for lastActivityTime field.

return
The value of the field.

        return lastActivityTime;
    
public synchronized intgetNextIndex()
Accessor for the nextIndex field.

return
The value of the nextIndex field

        return nextIndex;
    
protected booleanisGettingClose(long elapsedTime, long timeLimit)
Return value determines whether elapsed time is close enough to time limit to pull the trigger and send an ackRequested to keep the sequence alive.

param
elapsedTime Elapsed time since last reset.
param
timeLimit Maximum time to wait

        //for now
        return elapsedTime > timeLimit / 2; 
    
public synchronized booleanisLast()

        return last;
    
public voidresetLastActivityTime()
Resets lastActivityTime field to current time.

        lastActivityTime = System.currentTimeMillis();
    
public synchronized intset(int i, Message m)
Adds a Message to the Sequence at a specified indes. The index must be positive. If the index is larger than the nextIndex field, nulls are inserted between the largest index used and the index, and the index becomes the new value of the nextIndex field

param
i The index at which to insert the message.
param
m The message to insert
return
The new value of nextIndex.

       
        //record the index and sequence in the message
        m.setMessageNumber(i);
        m.setSequence(this);
        
        if (i <= 0) {
            throw new InvalidMessageNumberException();
        }
        
        if (storedMessages == maxMessages) {
            throw new BufferFullException(this);
        }
        
        if (i < nextIndex) {
            Message mess = null;
            if (null != (mess = list.get(i))  && !allowDuplicates) {
                //Store the original message in the exception so
                //that exception handling can use it.
                throw new DuplicateMessageException(mess);
            }
            
            list.set(i, m);
        } else if (i == nextIndex) {
            list.add( m);
            nextIndex++;
        } else {
            //fill in nulls between nextIndex an new nextIndex.
            for (int j = nextIndex; j < i; j++) {
                list.add(null);
            }
            list.add( m);
            nextIndex = i + 1;
        }
       
        storedMessages++;
        
        return i;
    
public voidsetId(java.lang.String id)
Sets the sequence identifier.

param
id The sequence identifier.

        this.id = id;
    
public synchronized voidsetLast()
Sets the last flag.

        last = true;