Source Code Cross Referenced for TransactionAccountImpl.java in  » Net » Terracotta » com » tc » objectserver » tx » 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.objectserver.tx 
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.objectserver.tx;
006:
007:        import com.tc.net.groups.NodeID;
008:        import com.tc.object.tx.ServerTransactionID;
009:        import com.tc.object.tx.TransactionID;
010:        import com.tc.util.Assert;
011:
012:        import java.util.Collections;
013:        import java.util.HashMap;
014:        import java.util.HashSet;
015:        import java.util.Iterator;
016:        import java.util.Map;
017:        import java.util.Set;
018:        import java.util.Map.Entry;
019:
020:        /**
021:         * An account of the state of a given transaction. Keeps track of the initiating client, the state of the transaction
022:         * (applied, committed, etc), clients the transaction has been broadcast to, and clients that have ACKed the
023:         * transaction.
024:         */
025:        public class TransactionAccountImpl implements  TransactionAccount {
026:            final NodeID sourceID;
027:            private final Map waitees = Collections
028:                    .synchronizedMap(new HashMap());
029:            private boolean dead = false;
030:            private CallBackOnComplete callBack;
031:
032:            public TransactionAccountImpl(NodeID source) {
033:                this .sourceID = source;
034:            }
035:
036:            public String toString() {
037:                return "TransactionAccount[" + sourceID + ": waitees="
038:                        + waitees + "]\n";
039:            }
040:
041:            public NodeID getNodeID() {
042:                return sourceID;
043:            }
044:
045:            public void incommingTransactions(Set txnIDs) {
046:                Assert.assertFalse(dead);
047:                for (Iterator i = txnIDs.iterator(); i.hasNext();) {
048:                    ServerTransactionID stxnID = (ServerTransactionID) i.next();
049:                    createRecord(stxnID.getClientTransactionID());
050:                }
051:            }
052:
053:            private void createRecord(TransactionID txnID) {
054:                Object old = waitees.put(txnID, new TransactionRecord());
055:                Assert.assertNull(old);
056:            }
057:
058:            /*
059:             * returns true if completed, false if not completed or if the client has sent a duplicate ACK.
060:             */
061:            public boolean removeWaitee(NodeID waitee, TransactionID requestID) {
062:                TransactionRecord transactionRecord = getRecord(requestID);
063:
064:                if (transactionRecord == null)
065:                    return false;
066:                synchronized (transactionRecord) {
067:                    transactionRecord.remove(waitee);
068:                    return checkCompletedAndRemove(requestID, transactionRecord);
069:                }
070:            }
071:
072:            public void addWaitee(NodeID waitee, TransactionID requestID) {
073:                TransactionRecord record = getRecord(requestID);
074:                synchronized (record) {
075:                    boolean added = record.addWaitee(waitee);
076:                    Assert.eval(added);
077:                }
078:            }
079:
080:            private TransactionRecord getRecord(TransactionID requestID) {
081:                return (TransactionRecord) waitees.get(requestID);
082:            }
083:
084:            public boolean skipApplyAndCommit(TransactionID requestID) {
085:                TransactionRecord transactionRecord = getRecord(requestID);
086:                synchronized (transactionRecord) {
087:                    transactionRecord.applyAndCommitSkipped();
088:                    return checkCompletedAndRemove(requestID, transactionRecord);
089:                }
090:            }
091:
092:            public boolean applyCommitted(TransactionID requestID) {
093:                TransactionRecord transactionRecord = getRecord(requestID);
094:                synchronized (transactionRecord) {
095:                    transactionRecord.applyCommitted();
096:                    return checkCompletedAndRemove(requestID, transactionRecord);
097:                }
098:            }
099:
100:            public boolean broadcastCompleted(TransactionID requestID) {
101:                TransactionRecord transactionRecord = getRecord(requestID);
102:                synchronized (transactionRecord) {
103:                    transactionRecord.broadcastCompleted();
104:                    return checkCompletedAndRemove(requestID, transactionRecord);
105:                }
106:            }
107:
108:            public boolean relayTransactionComplete(TransactionID requestID) {
109:                TransactionRecord transactionRecord = getRecord(requestID);
110:                synchronized (transactionRecord) {
111:                    transactionRecord.relayTransactionComplete();
112:                    return checkCompletedAndRemove(requestID, transactionRecord);
113:                }
114:            }
115:
116:            public boolean hasWaitees(TransactionID requestID) {
117:                TransactionRecord record = getRecord(requestID);
118:                if (record == null)
119:                    return false;
120:                synchronized (record) {
121:                    return !record.isEmpty();
122:                }
123:            }
124:
125:            public Set requestersWaitingFor(NodeID waitee) {
126:                Set requesters = new HashSet();
127:                synchronized (waitees) {
128:                    for (Iterator i = waitees.entrySet().iterator(); i
129:                            .hasNext();) {
130:                        Entry e = (Entry) i.next();
131:                        TransactionRecord record = (TransactionRecord) e
132:                                .getValue();
133:                        if (record.contains(waitee)) {
134:                            TransactionID requester = (TransactionID) e
135:                                    .getKey();
136:                            requesters.add(requester);
137:                        }
138:                    }
139:                }
140:                return requesters;
141:            }
142:
143:            private boolean checkCompletedAndRemove(TransactionID requestID,
144:                    TransactionRecord record) {
145:                synchronized (waitees) {
146:                    if (record.isComplete()) {
147:                        waitees.remove(requestID);
148:                        invokeCallBackOnCompleteIfNecessary();
149:                        return !dead;
150:                    }
151:                    return false;
152:                }
153:            }
154:
155:            public void addAllPendingServerTransactionIDsTo(HashSet txnIDs) {
156:                synchronized (waitees) {
157:                    for (Iterator i = waitees.keySet().iterator(); i.hasNext();) {
158:                        TransactionID txnID = (TransactionID) i.next();
159:                        txnIDs.add(new ServerTransactionID(sourceID, txnID));
160:                    }
161:                }
162:            }
163:
164:            public void nodeDead(CallBackOnComplete cb) {
165:                synchronized (waitees) {
166:                    this .callBack = cb;
167:                    this .dead = true;
168:                    invokeCallBackOnCompleteIfNecessary();
169:                }
170:            }
171:
172:            private void invokeCallBackOnCompleteIfNecessary() {
173:                if (dead && waitees.isEmpty()) {
174:                    callBack.onComplete(sourceID);
175:                }
176:            }
177:
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.