Source Code Cross Referenced for RMIObjectTable.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » rmi » server » 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 » Apache Harmony Java SE » org package » org.apache.harmony.rmi.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        /**
020:         * @author  Mikhail A. Markov
021:         * @version $Revision: 1.1.2.2 $
022:         */package org.apache.harmony.rmi.server;
023:
024:        import java.util.Hashtable;
025:        import java.rmi.server.ObjID;
026:
027:        /**
028:         * Defines structure for storing RMIObjects and methods for finding them by
029:         * different separate keys, which are unique inside the table: ObjID and
030:         * RMIReference to the object's implementation.
031:         *
032:         * @author  Mikhail A. Markov
033:         * @version $Revision: 1.1.2.2 $
034:         */
035:        final class RMIObjectTable {
036:
037:            // Table where key is ObjID.
038:            private Hashtable idTable = new Hashtable();
039:
040:            // Table where key is RMIReference to the impl.
041:            private Hashtable refTable = new Hashtable();
042:
043:            /*
044:             * Object using for synchronization, because we should change
045:             * 2 tables simultaneously.
046:             */
047:            private class TablesLock {
048:            }
049:
050:            private Object tablesLock = new TablesLock();
051:
052:            /**
053:             * Adds specified info to the table if there are no elements with the
054:             * same ObjID or RMIReference to the impl there.
055:             *
056:             * @param info RMIObjectInfo to be added to the table
057:             *
058:             * @return true if the table did not contain the given info and the info
059:             *         was successfully added to the table and false otherwise
060:             *
061:             * @throws NullPointerException if info is null or info.id is null
062:             */
063:            public boolean add(RMIObjectInfo info) {
064:                synchronized (tablesLock) {
065:                    if (!idTable.containsKey(info.id)) {
066:                        idTable.put(info.id, info);
067:                        refTable.put(info.ref, info);
068:                        return true;
069:                    }
070:                }
071:                return false;
072:            }
073:
074:            /**
075:             * Returns true if the table contains element with specified RMIReference
076:             * and false otherwise.
077:             *
078:             * @param ref RMIReference to the remote object implementation to be used
079:             *        as a key
080:             *
081:             * @return true if the table contains element with specified ref and false
082:             *         otherwise
083:             */
084:            public boolean containsByRef(RMIReference ref) {
085:                synchronized (tablesLock) {
086:                    return refTable.containsKey(ref);
087:                }
088:            }
089:
090:            /**
091:             * Returns true if the table contains element with specified id and false
092:             * otherwise.
093:             *
094:             * @param id ObjID to be used as a key
095:             *
096:             * @return true if the table contains element with specified id and false
097:             *         otherwise
098:             */
099:            public boolean containsById(ObjID id) {
100:                synchronized (tablesLock) {
101:                    return idTable.containsKey(id);
102:                }
103:            }
104:
105:            /**
106:             * Returns true if the table contains element which is equal to the info
107:             * specified.
108:             *
109:             * @param info RMIObjectInfo to be used as a key
110:             *
111:             * @return true if the table contains element which is equal to the info
112:             *         specified
113:             */
114:            public boolean contains(RMIObjectInfo info) {
115:                if (info != null && info.id != null) {
116:                    synchronized (tablesLock) {
117:                        return containsById(info.id);
118:                    }
119:                }
120:                return false;
121:            }
122:
123:            /**
124:             * Finds and returns RMIObjectInfo found by specified reference to remote
125:             * object implementation or null if record has not been found.
126:             *
127:             * @param ref RMIReference to the remote object implementation to be used
128:             *        as a key
129:             *
130:             * @return RMIObjectInfo if found in the table or null if matching record
131:             *         has not been found
132:             */
133:            public RMIObjectInfo getByRef(RMIReference ref) {
134:                synchronized (tablesLock) {
135:                    return (RMIObjectInfo) refTable.get(ref);
136:                }
137:            }
138:
139:            /**
140:             * Finds and returns RMIObjectInfo found by specified ObjID or null
141:             * if record has not been found.
142:             *
143:             * @param id ObjID to use as a key
144:             *
145:             * @return RMIObjectInfo if found in the table or null if matching record
146:             *         has not been found
147:             */
148:            public RMIObjectInfo getById(ObjID id) {
149:                synchronized (tablesLock) {
150:                    return (RMIObjectInfo) idTable.get(id);
151:                }
152:            }
153:
154:            /**
155:             * Removes RMIObjectInfo found by specified reference to remote object
156:             * implementation from the table.
157:             *
158:             * @param ref RMIReference to the remote object implementation to be used
159:             *        as a key
160:             *
161:             * @return RMIObjectInfo if found in the table or null if matching record
162:             *         has not been found
163:             */
164:            public RMIObjectInfo removeByRef(RMIReference ref) {
165:                RMIObjectInfo info;
166:
167:                synchronized (tablesLock) {
168:                    info = (RMIObjectInfo) refTable.remove(ref);
169:
170:                    if (info != null) {
171:                        idTable.remove(info.id);
172:                    }
173:                }
174:                return info;
175:            }
176:
177:            /**
178:             * Removes RMIObjectInfo found by specified ObjID from the table.
179:             *
180:             * @param id ObjID to use as a key
181:             *
182:             * @return RMIObjectInfo if found in the table or null if matching record
183:             *         has not been found
184:             */
185:            public RMIObjectInfo removeById(ObjID id) {
186:                RMIObjectInfo info;
187:
188:                synchronized (tablesLock) {
189:                    info = (RMIObjectInfo) idTable.remove(id);
190:
191:                    if (info != null) {
192:                        refTable.remove(info.ref);
193:                    }
194:                }
195:                return info;
196:            }
197:
198:            /**
199:             * Returns true if this table contains no records and false otherwise.
200:             *
201:             * @return true if this table contains no records and false otherwise
202:             */
203:            public boolean isEmpty() {
204:                synchronized (tablesLock) {
205:                    return idTable.isEmpty();
206:                }
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.