Source Code Cross Referenced for TestRemoteLockManager.java in  » Net » Terracotta » com » tc » object » lockmanager » api » 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 » Net » Terracotta » com.tc.object.lockmanager.api 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.object.lockmanager.api;
006:
007:        import com.tc.exception.ImplementMe;
008:        import com.tc.object.session.SessionProvider;
009:        import com.tc.object.tx.TransactionID;
010:        import com.tc.object.tx.WaitInvocation;
011:        import com.tc.util.concurrent.NoExceptionLinkedQueue;
012:
013:        import java.util.Arrays;
014:        import java.util.Collection;
015:        import java.util.HashMap;
016:        import java.util.Iterator;
017:        import java.util.LinkedList;
018:        import java.util.Map;
019:
020:        /**
021:         * @author steve
022:         */
023:        public class TestRemoteLockManager implements  RemoteLockManager {
024:            public final LockResponder LOOPBACK_LOCK_RESPONDER = new LoopbackLockResponder();
025:            public final LockResponder NULL_LOCK_RESPONDER = new LockResponder() {
026:                public void respondToLockRequest(LockRequest request) {
027:                    return;
028:                }
029:            };
030:            private ClientLockManager lockManager;
031:            private Map locks = new HashMap();
032:            private int lockRequests = 0;
033:            private int unlockRequests = 0;
034:            private int flushCount = 0;
035:            private boolean isGreedy = false;
036:            public LockResponder lockResponder = LOOPBACK_LOCK_RESPONDER;
037:
038:            public final NoExceptionLinkedQueue lockRequestCalls = new NoExceptionLinkedQueue();
039:            private final SessionProvider sessionProvider;
040:
041:            public TestRemoteLockManager(SessionProvider sessionProvider) {
042:                this .sessionProvider = sessionProvider;
043:            }
044:
045:            public void setClientLockManager(ClientLockManager lockManager) {
046:                this .lockManager = lockManager;
047:            }
048:
049:            public synchronized int getLockRequestCount() {
050:                return this .lockRequests;
051:            }
052:
053:            public synchronized int getUnlockRequestCount() {
054:                return this .unlockRequests;
055:            }
056:
057:            // *************************
058:            // This manager doesn't implement lock upgrades correctly. Lock
059:            // upgrades/downgrades are always awarded. Locks held
060:            // by other transactions are not taken into consideration
061:            // *************************
062:
063:            public synchronized void requestLock(LockID lockID,
064:                    ThreadID threadID, int lockType) {
065:                lockRequests++;
066:                lockRequestCalls.put(new Object[] { lockID, threadID,
067:                        new Integer(lockType) });
068:
069:                LockRequest request;
070:                if (isGreedy) {
071:                    request = new LockRequest(lockID, ThreadID.VM_ID, LockLevel
072:                            .makeGreedy(lockType));
073:                } else {
074:                    request = new LockRequest(lockID, threadID, lockType);
075:                }
076:
077:                if (!locks.containsKey(lockID)) {
078:                    locks.put(lockID, new LinkedList(
079:                            Arrays.asList(new Object[] { new Lock(threadID,
080:                                    lockType) })));
081:                    lockResponder.respondToLockRequest(request);
082:                    return;
083:                }
084:
085:                LinkedList myLocks = (LinkedList) locks.get(lockID);
086:                for (Iterator iter = myLocks.iterator(); iter.hasNext();) {
087:                    // allow lock upgrades/downgrades
088:                    Lock lock = (Lock) iter.next();
089:                    if (lock.threadID.equals(threadID)) {
090:                        lock.upCount();
091:                        lockResponder.respondToLockRequest(request);
092:                        return;
093:                    }
094:                }
095:
096:                myLocks.addLast(new Lock(request.threadID(), request
097:                        .lockLevel()));
098:            }
099:
100:            public synchronized void makeLocksGreedy() {
101:                isGreedy = true;
102:            }
103:
104:            public synchronized void makeLocksNotGreedy() {
105:                isGreedy = false;
106:            }
107:
108:            public synchronized void releaseLock(LockID lockID,
109:                    ThreadID threadID) {
110:                unlockRequests++;
111:
112:                LinkedList myLocks = (LinkedList) locks.get(lockID);
113:
114:                Lock current = (Lock) myLocks.getFirst();
115:                if (current.threadID.equals(threadID)) {
116:                    int count = current.downCount();
117:                    if (count == 0) {
118:                        myLocks.removeFirst();
119:                    } else {
120:                        return;
121:                    }
122:                }
123:
124:                if (myLocks.isEmpty()) {
125:                    locks.remove(lockID);
126:                    return;
127:                }
128:
129:                Lock lock = (Lock) myLocks.remove(0);
130:                lockResponder.respondToLockRequest(new LockRequest(lockID,
131:                        lock.threadID, lock.type));
132:            }
133:
134:            public void releaseLockWait(LockID lockID, ThreadID threadID,
135:                    WaitInvocation call) {
136:                return;
137:            }
138:
139:            public void recallCommit(LockID lockID, Collection lockContext,
140:                    Collection waitContext, Collection pendingRequests,
141:                    Collection pendingTryLockRequests) {
142:                return;
143:            }
144:
145:            public synchronized void flush(LockID lockID) {
146:                flushCount++;
147:            }
148:
149:            public synchronized void resetFlushCount() {
150:                flushCount = 0;
151:            }
152:
153:            public synchronized int getFlushCount() {
154:                return flushCount;
155:            }
156:
157:            public boolean isTransactionsForLockFlushed(LockID lockID,
158:                    LockFlushCallback callback) {
159:                return true;
160:            }
161:
162:            public void notify(LockID lockID, TransactionID transactionID,
163:                    boolean all) {
164:                // TODO: this really should get called by a test at some point. At such
165:                // time, you probably want to record the
166:                // request and return
167:                throw new ImplementMe();
168:            }
169:
170:            public interface LockResponder {
171:                void respondToLockRequest(LockRequest request);
172:            }
173:
174:            private class LoopbackLockResponder implements  LockResponder {
175:                public void respondToLockRequest(LockRequest request) {
176:                    lockManager.awardLock(sessionProvider.getSessionID(),
177:                            request.lockID(), request.threadID(), request
178:                                    .lockLevel());
179:                }
180:            }
181:
182:            private static class Lock {
183:                final ThreadID threadID;
184:                final int type;
185:                int count = 1;
186:
187:                Lock(ThreadID threadID, int type) {
188:                    this .threadID = threadID;
189:                    this .type = type;
190:                }
191:
192:                int upCount() {
193:                    return ++count;
194:                }
195:
196:                int downCount() {
197:                    return --count;
198:                }
199:            }
200:
201:            public void queryLock(LockID lockID, ThreadID threadID) {
202:                throw new ImplementMe();
203:            }
204:
205:            public void interrruptWait(LockID lockID, ThreadID threadID) {
206:                throw new ImplementMe();
207:            }
208:
209:            public void tryRequestLock(LockID lockID, ThreadID threadID,
210:                    WaitInvocation timeout, int lockType) {
211:                //
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.