Source Code Cross Referenced for InMemoryManagedObjectStore.java in  » Net » Terracotta » com » tc » objectserver » impl » 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.impl 
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.impl;
006:
007:        import com.tc.object.ObjectID;
008:        import com.tc.objectserver.api.ShutdownError;
009:        import com.tc.objectserver.core.api.ManagedObject;
010:        import com.tc.objectserver.managedobject.ManagedObjectStateFactory;
011:        import com.tc.objectserver.persistence.api.ManagedObjectStore;
012:        import com.tc.objectserver.persistence.api.PersistenceTransaction;
013:        import com.tc.text.PrettyPrinter;
014:        import com.tc.util.Assert;
015:        import com.tc.util.ObjectIDSet2;
016:
017:        import java.util.Collection;
018:        import java.util.HashMap;
019:        import java.util.HashSet;
020:        import java.util.Iterator;
021:        import java.util.Map;
022:        import java.util.Set;
023:
024:        public class InMemoryManagedObjectStore implements  ManagedObjectStore {
025:
026:            private long objectIDSequence = 1000;
027:            private final Map roots = new HashMap();
028:            private final Map managed;
029:            private boolean inShutdown = false;
030:
031:            public InMemoryManagedObjectStore(Map managed) {
032:                this .managed = managed;
033:            }
034:
035:            public synchronized boolean containsObject(ObjectID id) {
036:                assertNotInShutdown();
037:                return this .managed.containsKey(id);
038:            }
039:
040:            public synchronized void addNewObject(ManagedObject managedObject) {
041:                assertNotInShutdown();
042:                localPut(managedObject);
043:            }
044:
045:            private void localPut(ManagedObject managedObject) {
046:                this .managed.put(managedObject.getID(), managedObject);
047:            }
048:
049:            public synchronized void commitObject(PersistenceTransaction tx,
050:                    ManagedObject managedObject) {
051:                assertNotInShutdown();
052:                assertContains(managedObject);
053:            }
054:
055:            public synchronized void commitAllObjects(
056:                    PersistenceTransaction tx, Collection managedObjects) {
057:                assertNotInShutdown();
058:                for (Iterator i = managedObjects.iterator(); i.hasNext();) {
059:                    assertContains((ManagedObject) i.next());
060:                }
061:            }
062:
063:            private void removeObjectByID(PersistenceTransaction tx, ObjectID id) {
064:                this .managed.remove(id);
065:            }
066:
067:            public synchronized void removeAllObjectsByID(
068:                    PersistenceTransaction tx, Collection ids) {
069:                assertNotInShutdown();
070:                for (Iterator i = ids.iterator(); i.hasNext();) {
071:                    removeObjectByID(tx, (ObjectID) i.next());
072:                }
073:            }
074:
075:            public void removeAllObjectsByIDNow(PersistenceTransaction tx,
076:                    Collection objectIds) {
077:                removeAllObjectsByID(tx, objectIds);
078:            }
079:
080:            public synchronized ObjectIDSet2 getAllObjectIDs() {
081:                assertNotInShutdown();
082:                return new ObjectIDSet2(managed.keySet());
083:            }
084:
085:            public synchronized int getObjectCount() {
086:                return managed.size();
087:            }
088:
089:            public synchronized ManagedObject getObjectByID(ObjectID id) {
090:                assertNotInShutdown();
091:                return (ManagedObject) this .managed.get(id);
092:            }
093:
094:            public synchronized PrettyPrinter prettyPrint(PrettyPrinter out) {
095:                out.println(getClass().getName()).duplicateAndIndent().print(
096:                        "managed: ").visit(managed).println();
097:                return out;
098:            }
099:
100:            public synchronized void shutdown() {
101:                assertNotInShutdown();
102:                this .inShutdown = true;
103:            }
104:
105:            public synchronized boolean inShutdown() {
106:                return this .inShutdown;
107:            }
108:
109:            private synchronized void assertNotInShutdown() {
110:                if (inShutdown)
111:                    throw new ShutdownError();
112:            }
113:
114:            private synchronized void assertContains(ManagedObject managedObject) {
115:                if (!containsObject(managedObject.getID()))
116:                    throw new AssertionError("Object store does not contain "
117:                            + managedObject);
118:            }
119:
120:            public ObjectID getRootID(String name) {
121:                return (ObjectID) (roots.containsKey(name) ? roots.get(name)
122:                        : ObjectID.NULL_ID);
123:            }
124:
125:            public Set getRoots() {
126:                return new HashSet(roots.values());
127:            }
128:
129:            public Set getRootNames() {
130:                return roots.keySet();
131:            }
132:
133:            public void addNewRoot(PersistenceTransaction tx, String rootName,
134:                    ObjectID id) {
135:                roots.put(rootName, id);
136:            }
137:
138:            public synchronized long nextObjectIDBatch(int batchSize) {
139:                long rv = objectIDSequence;
140:                objectIDSequence += batchSize;
141:                return rv;
142:            }
143:
144:            public void setNextAvailableObjectID(long startID) {
145:                Assert.assertTrue(startID >= objectIDSequence);
146:                objectIDSequence = startID;
147:            }
148:
149:            public void setTransientData(ManagedObjectStateFactory stateFactory) {
150:                assertNotInShutdown();
151:            }
152:
153:            public Map getRootNamesToIDsMap() {
154:                return roots;
155:            }
156:
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.