Source Code Cross Referenced for Sequence.java in  » 6.0-JDK-Modules-com.sun » wsit » com » sun » xml » ws » rm » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules com.sun » wsit » com.sun.xml.ws.rm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: Sequence.java,v 1.12 2007/09/20 18:47:07 bhaktimehta Exp $
003:         */
004:
005:        /*
006:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
007:         * 
008:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
009:         * 
010:         * The contents of this file are subject to the terms of either the GNU
011:         * General Public License Version 2 only ("GPL") or the Common Development
012:         * and Distribution License("CDDL") (collectively, the "License").  You
013:         * may not use this file except in compliance with the License. You can obtain
014:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
015:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
016:         * language governing permissions and limitations under the License.
017:         * 
018:         * When distributing the software, include this License Header Notice in each
019:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
020:         * Sun designates this particular file as subject to the "Classpath" exception
021:         * as provided by Sun in the GPL Version 2 section of the License file that
022:         * accompanied this code.  If applicable, add the following below the License
023:         * Header, with the fields enclosed by brackets [] replaced by your own
024:         * identifying information: "Portions Copyrighted [year]
025:         * [name of copyright owner]"
026:         * 
027:         * Contributor(s):
028:         * 
029:         * If you wish your version of this file to be governed by only the CDDL or
030:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
031:         * elects to include this software in this distribution under the [CDDL or GPL
032:         * Version 2] license."  If you don't indicate a single choice of license, a
033:         * recipient has the option to distribute your version of this file under
034:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
035:         * its licensees as provided above.  However, if you add GPL Version 2 code
036:         * and therefore, elected the GPL Version 2 license, then the option applies
037:         * only if the new code is made subject to such option by the copyright
038:         * holder.
039:         */
040:
041:        package com.sun.xml.ws.rm;
042:
043:        import com.sun.xml.ws.rm.jaxws.runtime.SequenceConfig;
044:
045:        import java.util.ArrayList;
046:
047:        /**
048:         *  A Sequence is a sparse array of messages corresponding to an RM Sequence.  It
049:         *  is implemented as an ArrayList with nulls at unfilled indices.
050:         */
051:
052:        public class Sequence {
053:
054:            /**
055:             * The sequence identifier.
056:             */
057:            protected String id;
058:
059:            /**
060:             * The underlying list of messages
061:             */
062:            protected ArrayList<Message> list;
063:
064:            /**
065:             * The smallest unfilled index.
066:             */
067:            protected int nextIndex = 1;
068:
069:            /**
070:             * Flag indicates that message with Sequence header containing
071:             * Last element has been sent/received.  If this is the case,
072:             * SequenceAcknowledgements for the sequence may contain acks
073:             * for a message is one greater than the index for the last
074:             * message in the sequence.
075:             */
076:            protected boolean last = false;
077:
078:            /**
079:             * Flag that indicates if the CloseSequence message has been sent/received
080:             * If this is the case then the Sequence needs to be closed and no more messages
081:             * with that Sequence Id should be accepted
082:             */
083:            protected boolean closed = false;
084:
085:            /**
086:             * Maximum number of stored messages.  Used for server-side sequences
087:             * for which flow control is enabled.  The value -1 indicates that
088:             * there is no limit.
089:             */
090:            protected int maxMessages = -1;
091:
092:            /**
093:             * Number of messages currently being stored awaiting completion.
094:             */
095:            protected int storedMessages = 0;
096:
097:            /**
098:             * Last accesse time.
099:             */
100:            protected long lastActivityTime;
101:
102:            protected boolean allowDuplicates;
103:
104:            /**
105:             * RMConstants associated with each Sequence which
106:             * will give information regarding addressing version, JAXBContext etc
107:             *
108:             */
109:            protected RMConstants rmConstants;
110:
111:            protected SequenceConfig config;
112:
113:            protected int firstKnownGap;
114:
115:            /**
116:             * Gets the sequence identifier
117:             * @return The sequence identifier.
118:             */
119:            public String getId() {
120:                return id;
121:            }
122:
123:            /**
124:             * Sets the sequence identifier.
125:             * @param id The sequence identifier.
126:             */
127:            public void setId(String id) {
128:                this .id = id;
129:            }
130:
131:            public Sequence() {
132:
133:                list = new ArrayList<Message>();
134:                //fill in 0-th index that will never be used since
135:                //messageNumbers are 1-based and we will be keeping
136:                //messageNumbers in-sync with indices.
137:                list.add(null);
138:                allowDuplicates = false;
139:                firstKnownGap = 1;
140:
141:                resetLastActivityTime();
142:
143:            }
144:
145:            /**
146:             * Accessor for SequenceConfig field.
147:             */
148:            public SequenceConfig getSequenceConfig() {
149:                return config;
150:            }
151:
152:            /**
153:             * Accessor for the nextIndex field.
154:             * @return The value of the nextIndex field
155:             */
156:            public synchronized int getNextIndex() {
157:                return nextIndex;
158:            }
159:
160:            /**
161:             * Gets the Message at the specified index.
162:             * @param index The index to access
163:             * @return The Message at the specified index
164:             * @throws InvalidMessageNumberException If the index is larger than the largest
165:             * index used.
166:             */
167:            public synchronized Message get(int index)
168:                    throws InvalidMessageNumberException {
169:
170:                if (index >= nextIndex) {
171:                    throw new InvalidMessageNumberException(
172:                            Messages.INVALID_INDEX_MESSAGE.format(index));
173:                }
174:                return list.get(index);
175:            }
176:
177:            /**
178:             * Adds a Message to the Sequence at a specified indes.  The index must be
179:             * positive.  If the index is larger than the nextIndex field, nulls are inserted 
180:             * between the largest index used and the index, and the index becomes the new
181:             * value of the nextIndex field
182:             * @param i The index at which to insert the message.
183:             * @param m The message to insert
184:             *
185:             * @return The new value of nextIndex.
186:             */
187:            public synchronized int set(int i, Message m)
188:                    throws InvalidMessageNumberException, BufferFullException,
189:                    DuplicateMessageException {
190:
191:                //record the index and sequence in the message
192:                m.setMessageNumber(i);
193:                m.setSequence(this );
194:
195:                if (i <= 0) {
196:                    throw new InvalidMessageNumberException();
197:                }
198:
199:                if (storedMessages == maxMessages) {
200:                    throw new BufferFullException(this );
201:                }
202:
203:                if (i < nextIndex) {
204:                    Message mess = null;
205:                    if (null != (mess = list.get(i)) && !allowDuplicates) {
206:                        //Store the original message in the exception so
207:                        //that exception handling can use it.
208:                        throw new DuplicateMessageException(mess);
209:                    }
210:
211:                    list.set(i, m);
212:                } else if (i == nextIndex) {
213:                    list.add(m);
214:                    nextIndex++;
215:                } else {
216:                    //fill in nulls between nextIndex an new nextIndex.
217:                    for (int j = nextIndex; j < i; j++) {
218:                        list.add(null);
219:                    }
220:                    list.add(m);
221:                    nextIndex = i + 1;
222:                }
223:
224:                storedMessages++;
225:
226:                return i;
227:            }
228:
229:            /**
230:             * Sets the last flag.
231:             */
232:            public synchronized void setLast() {
233:                last = true;
234:            }
235:
236:            /**
237:             * Sets the last flag.
238:             */
239:            public synchronized void setClosed() {
240:                closed = true;
241:            }
242:
243:            /*
244:             * Gets the value of the last flag.
245:             *
246:             * @return The value of the flag.
247:             */
248:            public synchronized boolean isLast() {
249:                return last;
250:            }
251:
252:            /*
253:             * Gets the value of the last flag.
254:             *
255:             * @return The value of the flag.
256:             */
257:            public synchronized boolean isClosed() {
258:                return closed;
259:            }
260:
261:            /////////////////////////////////////////////////////////////////////////////
262:            /*
263:             *             InactivityTimeout management helpers
264:             *             used by ClientOutboundSequence and ServerInboundSequence
265:             *
266:             *////////////////////////////////////////////////////////////////////////////
267:
268:            /**
269:             * Resets lastActivityTime field to current time.
270:             */
271:            public void resetLastActivityTime() {
272:                lastActivityTime = System.currentTimeMillis();
273:            }
274:
275:            /**
276:             * Accessor for lastActivityTime field.
277:             *
278:             * @return The value of the field.
279:             */
280:            protected long getLastActivityTime() {
281:                return lastActivityTime;
282:            }
283:
284:            /**
285:             * Return value determines whether elapsed time is close enough to
286:             * time limit to pull the trigger and send an ackRequested to keep the
287:             * sequence alive.
288:             *
289:             * @param elapsedTime Elapsed time since last reset.
290:             * @param timeLimit Maximum time to wait
291:             */
292:            protected boolean isGettingClose(long elapsedTime, long timeLimit) {
293:                //for now
294:                return elapsedTime > timeLimit / 2;
295:            }
296:
297:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.