Source Code Cross Referenced for LockLevel.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 java.util.ArrayList;
008:        import java.util.Iterator;
009:
010:        /**
011:         * Lock level constants
012:         */
013:        public class LockLevel {
014:            /** NOTE: The NIL level isn't a valid lock level. It used to indicate the absence of a defined/valid lock level */
015:            public final static int NIL_LOCK_LEVEL = 0;
016:
017:            /** READ bit */
018:            public final static int READ = 1;
019:            /** WRITE bit */
020:            public final static int WRITE = 2;
021:            /** CONCURRENT bit */
022:            public final static int CONCURRENT = 4;
023:
024:            /** GREEDY bit */
025:            private final static int GREEDY = 0x80;
026:            /** SYNCHRONOUS bit, used with WRITE as SYNCHRONOUS_WRITE */
027:            private final static int SYNCHRONOUS = 0X40;
028:
029:            /** Combination of WRITE with SYNCHRONOUS flag */
030:            public final static int SYNCHRONOUS_WRITE = WRITE | SYNCHRONOUS;
031:
032:            private LockLevel() {
033:                // not to be instantiated
034:            }
035:
036:            /**
037:             * @param level Level
038:             * @return Is lock level READ?
039:             */
040:            public static boolean isRead(int level) {
041:                if (level <= 0)
042:                    return false;
043:                return (level & READ) == READ;
044:            }
045:
046:            /**
047:             * @param level Level
048:             * @return Is lock level WRITE?
049:             */
050:            public static boolean isWrite(int level) {
051:                if (level <= 0)
052:                    return false;
053:                return (level & WRITE) == WRITE;
054:            }
055:
056:            /**
057:             * @param level Level
058:             * @return Is lock level CONCURRENT?
059:             */
060:            public static boolean isConcurrent(int level) {
061:                if (level <= 0)
062:                    return false;
063:                return (level & CONCURRENT) == CONCURRENT;
064:            }
065:
066:            /**
067:             * @param level Level
068:             * @return Is lock level SYNCHRONOUS_WRITE?
069:             */
070:            public static boolean isSynchronousWrite(int level) {
071:                if (level <= 0)
072:                    return false;
073:                return (level & SYNCHRONOUS_WRITE) == SYNCHRONOUS_WRITE;
074:            }
075:
076:            /**
077:             * @param level Level
078:             * @return Is lock level GREEDY?
079:             */
080:            public static boolean isGreedy(int level) {
081:                if (level <= 0)
082:                    return false;
083:                return (level & GREEDY) == GREEDY;
084:            }
085:
086:            /**
087:             * @param level Level
088:             * @return Is SYNCHRONOUS?
089:             */
090:            public static boolean isSynchronous(int level) {
091:                if (level <= 0)
092:                    return false;
093:                return (level & SYNCHRONOUS) == SYNCHRONOUS;
094:            }
095:
096:            /**
097:             * @param level Lock level
098:             * @return String representation
099:             */
100:            public static String toString(int level) {
101:                ArrayList levels = new ArrayList();
102:                StringBuffer rv = new StringBuffer();
103:
104:                if (isRead(level)) {
105:                    levels.add("READ");
106:                }
107:
108:                if (isWrite(level)) {
109:                    levels.add("WRITE");
110:                }
111:
112:                if (isConcurrent(level)) {
113:                    levels.add("CONCURRENT");
114:                }
115:
116:                if (isSynchronousWrite(level)) {
117:                    levels.add("SYNCHRONOUS_WRITE");
118:                }
119:
120:                if (levels.size() == 0) {
121:                    levels.add("UNKNOWN:" + level);
122:                }
123:
124:                for (Iterator iter = levels.iterator(); iter.hasNext();) {
125:                    rv.append(iter.next()).append(' ');
126:                }
127:
128:                rv.append('(').append(level).append(')');
129:
130:                return rv.toString();
131:
132:            }
133:
134:            /**
135:             * Is this a discrete lock level? A lock level which is a combination (like READ+WRITE) is non-discreet
136:             * @return True if discrete
137:             */
138:            public static boolean isDiscrete(int lockLevel) {
139:                switch (lockLevel) {
140:                case READ:
141:                case WRITE:
142:                case CONCURRENT:
143:                    return true;
144:                default:
145:                    return false;
146:                }
147:            }
148:
149:            /** 
150:             * Make lock greedy
151:             * @param level Start
152:             * @return Greedy version of level
153:             */
154:            public static int makeGreedy(int level) {
155:                return level | GREEDY;
156:            }
157:
158:            /** 
159:             * Make lock not greedy
160:             * @param level Start
161:             * @return Not greedy version of level
162:             */
163:            public static int makeNotGreedy(int level) {
164:                return level & (~GREEDY);
165:            }
166:
167:            /** 
168:             * Make lock synchronous
169:             * @param level Start
170:             * @return Synchronous version of level
171:             */
172:            public static int makeSynchronous(int level) {
173:                return level | SYNCHRONOUS;
174:            }
175:
176:            /** 
177:             * Make not synchronous
178:             * @param level Start
179:             * @return Not synchronous version of level
180:             */
181:            public static int makeNotSynchronous(int level) {
182:                return level & (~SYNCHRONOUS);
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.