Source Code Cross Referenced for SyncList.java in  » Ajax » Laszlo-4.0.10 » EDU » oswego » cs » dl » util » concurrent » 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 » Ajax » Laszlo 4.0.10 » EDU.oswego.cs.dl.util.concurrent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          File: SyncList.java
003:
004:          Originally written by Doug Lea and released into the public domain.
005:          This may be used for any purposes whatsoever without acknowledgment.
006:          Thanks for the assistance and support of Sun Microsystems Labs,
007:          and everyone contributing, testing, and using this code.
008:
009:          History:
010:          Date       Who                What
011:           1Aug1998  dl               Create public version
012:         */
013:
014:        package EDU.oswego.cs.dl.util.concurrent;
015:
016:        import java.util.*;
017:
018:        /**
019:         * SyncLists wrap Sync-based control around java.util.Lists.
020:         * They support the following additional reader operations over
021:         * SyncCollection: hashCode, equals, get, indexOf, lastIndexOf,
022:         * subList. They support additional writer operations remove(int),
023:         * set(int), add(int), addAll(int). The corresponding listIterators
024:         * and are similarly extended.
025:         * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
026:         * @see SyncCollection
027:         **/
028:
029:        public class SyncList extends SyncCollection implements  List {
030:
031:            /**
032:             * Create a new SyncList protecting the given collection,
033:             * and using the given sync to control both reader and writer methods.
034:             * Common, reasonable choices for the sync argument include
035:             * Mutex, ReentrantLock, and Semaphores initialized to 1.
036:             **/
037:            public SyncList(List list, Sync sync) {
038:                super (list, sync);
039:            }
040:
041:            /**
042:             * Create a new SyncList protecting the given list,
043:             * and using the given ReadWriteLock to control reader and writer methods.
044:             **/
045:            public SyncList(List list, ReadWriteLock rwl) {
046:                super (list, rwl.readLock(), rwl.writeLock());
047:            }
048:
049:            /**
050:             * Create a new SyncList protecting the given list,
051:             * and using the given pair of locks to control reader and writer methods.
052:             **/
053:            public SyncList(List list, Sync readLock, Sync writeLock) {
054:                super (list, readLock, writeLock);
055:            }
056:
057:            protected List baseList() {
058:                return (List) c_;
059:            }
060:
061:            public int hashCode() {
062:                boolean wasInterrupted = beforeRead();
063:                try {
064:                    return c_.hashCode();
065:                } finally {
066:                    afterRead(wasInterrupted);
067:                }
068:            }
069:
070:            public boolean equals(Object o) {
071:                boolean wasInterrupted = beforeRead();
072:                try {
073:                    return c_.equals(o);
074:                } finally {
075:                    afterRead(wasInterrupted);
076:                }
077:            }
078:
079:            public Object get(int index) {
080:                boolean wasInterrupted = beforeRead();
081:                try {
082:                    return baseList().get(index);
083:                } finally {
084:                    afterRead(wasInterrupted);
085:                }
086:            }
087:
088:            public int indexOf(Object o) {
089:                boolean wasInterrupted = beforeRead();
090:                try {
091:                    return baseList().indexOf(o);
092:                } finally {
093:                    afterRead(wasInterrupted);
094:                }
095:            }
096:
097:            public int lastIndexOf(Object o) {
098:                boolean wasInterrupted = beforeRead();
099:                try {
100:                    return baseList().lastIndexOf(o);
101:                } finally {
102:                    afterRead(wasInterrupted);
103:                }
104:            }
105:
106:            public List subList(int fromIndex, int toIndex) {
107:                boolean wasInterrupted = beforeRead();
108:                try {
109:                    return new SyncList(baseList().subList(fromIndex, toIndex),
110:                            rd_, wr_);
111:                } finally {
112:                    afterRead(wasInterrupted);
113:                }
114:            }
115:
116:            public Object set(int index, Object o) {
117:                try {
118:                    wr_.acquire();
119:                    try {
120:                        return baseList().set(index, o);
121:                    } finally {
122:                        wr_.release();
123:                    }
124:                } catch (InterruptedException ex) {
125:                    Thread.currentThread().interrupt();
126:                    throw new UnsupportedOperationException();
127:                }
128:            }
129:
130:            public Object remove(int index) {
131:                try {
132:                    wr_.acquire();
133:                    try {
134:                        return baseList().remove(index);
135:                    } finally {
136:                        wr_.release();
137:                    }
138:                } catch (InterruptedException ex) {
139:                    Thread.currentThread().interrupt();
140:                    throw new UnsupportedOperationException();
141:                }
142:            }
143:
144:            public void add(int index, Object o) {
145:                try {
146:                    wr_.acquire();
147:                    try {
148:                        baseList().add(index, o);
149:                    } finally {
150:                        wr_.release();
151:                    }
152:                } catch (InterruptedException ex) {
153:                    Thread.currentThread().interrupt();
154:                    throw new UnsupportedOperationException();
155:                }
156:            }
157:
158:            public boolean addAll(int index, Collection coll) {
159:                try {
160:                    wr_.acquire();
161:                    try {
162:                        return baseList().addAll(index, coll);
163:                    } finally {
164:                        wr_.release();
165:                    }
166:                } catch (InterruptedException ex) {
167:                    Thread.currentThread().interrupt();
168:                    throw new UnsupportedOperationException();
169:                }
170:            }
171:
172:            public ListIterator unprotectedListIterator() {
173:                boolean wasInterrupted = beforeRead();
174:                try {
175:                    return baseList().listIterator();
176:                } finally {
177:                    afterRead(wasInterrupted);
178:                }
179:            }
180:
181:            public ListIterator listIterator() {
182:                boolean wasInterrupted = beforeRead();
183:                try {
184:                    return new SyncCollectionListIterator(baseList()
185:                            .listIterator());
186:                } finally {
187:                    afterRead(wasInterrupted);
188:                }
189:            }
190:
191:            public ListIterator unprotectedListIterator(int index) {
192:                boolean wasInterrupted = beforeRead();
193:                try {
194:                    return baseList().listIterator(index);
195:                } finally {
196:                    afterRead(wasInterrupted);
197:                }
198:            }
199:
200:            public ListIterator listIterator(int index) {
201:                boolean wasInterrupted = beforeRead();
202:                try {
203:                    return new SyncCollectionListIterator(baseList()
204:                            .listIterator(index));
205:                } finally {
206:                    afterRead(wasInterrupted);
207:                }
208:            }
209:
210:            public class SyncCollectionListIterator extends
211:                    SyncCollectionIterator implements  ListIterator {
212:
213:                SyncCollectionListIterator(Iterator baseIterator) {
214:                    super (baseIterator);
215:                }
216:
217:                protected ListIterator baseListIterator() {
218:                    return (ListIterator) (baseIterator_);
219:                }
220:
221:                public boolean hasPrevious() {
222:                    boolean wasInterrupted = beforeRead();
223:                    try {
224:                        return baseListIterator().hasPrevious();
225:                    } finally {
226:                        afterRead(wasInterrupted);
227:                    }
228:                }
229:
230:                public Object previous() {
231:                    boolean wasInterrupted = beforeRead();
232:                    try {
233:                        return baseListIterator().previous();
234:                    } finally {
235:                        afterRead(wasInterrupted);
236:                    }
237:                }
238:
239:                public int nextIndex() {
240:                    boolean wasInterrupted = beforeRead();
241:                    try {
242:                        return baseListIterator().nextIndex();
243:                    } finally {
244:                        afterRead(wasInterrupted);
245:                    }
246:                }
247:
248:                public int previousIndex() {
249:                    boolean wasInterrupted = beforeRead();
250:                    try {
251:                        return baseListIterator().previousIndex();
252:                    } finally {
253:                        afterRead(wasInterrupted);
254:                    }
255:                }
256:
257:                public void set(Object o) {
258:                    try {
259:                        wr_.acquire();
260:                        try {
261:                            baseListIterator().set(o);
262:                        } finally {
263:                            wr_.release();
264:                        }
265:                    } catch (InterruptedException ex) {
266:                        Thread.currentThread().interrupt();
267:                        throw new UnsupportedOperationException();
268:                    }
269:                }
270:
271:                public void add(Object o) {
272:                    try {
273:                        wr_.acquire();
274:                        try {
275:                            baseListIterator().add(o);
276:                        } finally {
277:                            wr_.release();
278:                        }
279:                    } catch (InterruptedException ex) {
280:                        Thread.currentThread().interrupt();
281:                        throw new UnsupportedOperationException();
282:                    }
283:                }
284:
285:            }
286:
287:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.