Source Code Cross Referenced for ServerTable.java in  » Collaboration » JacORB » org » jacorb » imr » 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 » Collaboration » JacORB » org.jacorb.imr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jacorb.imr;
002:
003:        /*
004:         *        JacORB - a free Java ORB
005:         *
006:         *   Copyright (C) 1997-2004 Gerald Brose.
007:         *
008:         *   This library is free software; you can redistribute it and/or
009:         *   modify it under the terms of the GNU Library General Public
010:         *   License as published by the Free Software Foundation; either
011:         *   version 2 of the License, or (at your option) any later version.
012:         *
013:         *   This library is distributed in the hope that it will be useful,
014:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         *   Library General Public License for more details.
017:         *
018:         *   You should have received a copy of the GNU Library General Public
019:         *   License along with this library; if not, write to the Free
020:         *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         */
022:
023:        import java.util.*;
024:        import java.io.*;
025:        import org.jacorb.imr.RegistrationPackage.*;
026:        import org.jacorb.imr.AdminPackage.*;
027:
028:        /**
029:         * This class represents the server table of the implementation repository.
030:         * It contains all servers, POAs and hosts, and is serialized on shutdown,
031:         * deserialized on startup.
032:         * <br> It provides methods for adding, deleting and listing servers, 
033:         * POAs and hosts.
034:         *
035:         * @author Nicolas Noffke
036:         * 
037:         * $Id: ServerTable.java,v 1.10 2004/05/06 12:39:59 nicolas Exp $
038:         */
039:
040:        public class ServerTable implements  Serializable {
041:            private Hashtable servers;
042:            private transient ResourceLock servers_lock;
043:            private Hashtable poas;
044:            private transient ResourceLock poas_lock;
045:            private Hashtable hosts;
046:            private transient ResourceLock hosts_lock;
047:
048:            public transient ResourceLock table_lock;
049:
050:            public ServerTable() {
051:                servers = new Hashtable();
052:                poas = new Hashtable();
053:                hosts = new Hashtable();
054:
055:                initTransient();
056:            }
057:
058:            /**
059:             * This method initializes all transient attributes.
060:             */
061:
062:            private void initTransient() {
063:                // The table lock is a special case. It is used to gain
064:                // exclusive access to the server table on serialization. That
065:                // means the exclusive lock is set on serialization and, if it
066:                // was not transient, would be serialized as well.  On startup
067:                // of the repository, if the table is deserialized, the lock
068:                // is still set, und must be realeased. That means that we
069:                // have to distinguish between a new table and a deserialized
070:                // one. So its cheaper to instanciate the lock on
071:                // deserialization time again.
072:                table_lock = new ResourceLock();
073:
074:                // The locks are needed, because the hashtables have to be
075:                // copied to arrays sometimes (usually on command of the
076:                // user), and that is done via Enumerations.  Unfortunately
077:                // Enumerations get messed up when altering the underlying
078:                // structure while reading from them.
079:                servers_lock = new ResourceLock();
080:                poas_lock = new ResourceLock();
081:                hosts_lock = new ResourceLock();
082:            }
083:
084:            /**
085:             * This method tests, if a server is known.
086:             *
087:             * @param name the servers name.
088:             * @return true, if a server with the specified name has already
089:             * been registered.
090:             */
091:
092:            public boolean hasServer(String name) {
093:                return servers.containsKey(name);
094:            }
095:
096:            /**
097:             * This method gets a server for a specified name.
098:             *
099:             * @param name the servers name.
100:             * @return ImRServerInfo the ImRServerInfo object with name <code>name</code>.
101:             * @exception UnknownServerName thrown if the table does not contain 
102:             * an entry for <code>name</code>.
103:             */
104:
105:            public ImRServerInfo getServer(String name)
106:                    throws UnknownServerName {
107:                ImRServerInfo _tmp = (ImRServerInfo) servers.get(name);
108:                if (_tmp == null)
109:                    throw new UnknownServerName(name);
110:
111:                return _tmp;
112:            }
113:
114:            /**
115:             * Adds a server to the server table.
116:             *
117:             * @param name the servers name.
118:             * @param server the servers corresponding ImRServerInfo object.
119:             * @exception DuplicateServerName thrown if <code>name</code> is already
120:             * in the table.
121:             */
122:
123:            public void putServer(String name, ImRServerInfo server)
124:                    throws DuplicateServerName {
125:                if (servers.containsKey(name))
126:                    throw new DuplicateServerName(name);
127:
128:                table_lock.gainSharedLock();
129:                servers_lock.gainSharedLock();
130:
131:                servers.put(name, server);
132:
133:                servers_lock.releaseSharedLock();
134:                table_lock.releaseSharedLock();
135:            }
136:
137:            /**
138:             * Remove a server from the server table.
139:             *
140:             * @param name the servers name.
141:             * @exception UnknownServerName thrown if no server with <code>name</code>
142:             * is found in the table.
143:             */
144:
145:            public void removeServer(String name) throws UnknownServerName {
146:                table_lock.gainSharedLock();
147:                servers_lock.gainSharedLock();
148:
149:                Object _obj = servers.remove(name);
150:
151:                servers_lock.releaseSharedLock();
152:                table_lock.releaseSharedLock();
153:
154:                if (_obj == null)
155:                    throw new UnknownServerName(name);
156:            }
157:
158:            /**
159:             * Get the ImRPOAInfo object of a POA.
160:             *
161:             * @param name the POAs name.
162:             * @return the ImRPOAInfo object for <code>name</code>, 
163:             * null if <code>name</code> not in the table.
164:             */
165:
166:            public ImRPOAInfo getPOA(String name) {
167:                return (ImRPOAInfo) poas.get(name);
168:            }
169:
170:            /**
171:             * Add a POA to the server table.
172:             *
173:             * @param name the POAs name.
174:             * @param poa the POAs ImRPOAInfo object.
175:             */
176:
177:            public void putPOA(String name, ImRPOAInfo poa) {
178:                table_lock.gainSharedLock();
179:                poas_lock.gainSharedLock();
180:
181:                poas.put(name, poa);
182:
183:                poas_lock.releaseSharedLock();
184:                table_lock.releaseSharedLock();
185:            }
186:
187:            /**
188:             * Remove a POA from the server table.
189:             *
190:             * @param name the POAs name.
191:             */
192:
193:            public void removePOA(String name) {
194:                table_lock.gainSharedLock();
195:                poas_lock.gainSharedLock();
196:
197:                poas.remove(name);
198:
199:                poas_lock.releaseSharedLock();
200:                table_lock.releaseSharedLock();
201:            }
202:
203:            /**
204:             * List all servers in the table.
205:             *
206:             * @return a ServerInfo array containing all servers.
207:             * Used by the CORBA interface of the repository.
208:             */
209:
210:            public ServerInfo[] getServers() {
211:                table_lock.gainSharedLock();
212:                servers_lock.gainExclusiveLock();
213:
214:                //build array
215:                ServerInfo[] _servers = new ServerInfo[servers.size()];
216:                Enumeration _server_enum = servers.elements();
217:
218:                //copy elements from vector to array
219:                int _i = 0;
220:                while (_server_enum.hasMoreElements())
221:                    _servers[_i++] = ((ImRServerInfo) _server_enum
222:                            .nextElement()).toServerInfo();
223:
224:                servers_lock.releaseExclusiveLock();
225:                table_lock.releaseSharedLock();
226:
227:                return _servers;
228:            }
229:
230:            /**
231:             * List all hosts in the table.
232:             *
233:             * @return a HostInfo array containing all hosts.
234:             * Used by the CORBA interface of the repository.
235:             */
236:
237:            public HostInfo[] getHosts() {
238:                table_lock.gainSharedLock();
239:                hosts_lock.gainExclusiveLock();
240:
241:                //build array
242:                HostInfo[] _hosts = new HostInfo[hosts.size()];
243:                Enumeration _host_enum = hosts.elements();
244:
245:                //copy elements from vector to array
246:                int _i = 0;
247:                while (_host_enum.hasMoreElements())
248:                    _hosts[_i++] = ((ImRHostInfo) _host_enum.nextElement())
249:                            .toHostInfo();
250:
251:                hosts_lock.releaseExclusiveLock();
252:                table_lock.releaseSharedLock();
253:
254:                return _hosts;
255:            }
256:
257:            /**
258:             * List all POAs in the table.
259:             *
260:             * @return a POAInfo array containing all POAs.
261:             * Used by the CORBA interface of the repository.
262:             */
263:
264:            public POAInfo[] getPOAs() {
265:                table_lock.gainSharedLock();
266:                poas_lock.gainExclusiveLock();
267:
268:                //build array
269:                POAInfo[] _poas = new POAInfo[poas.size()];
270:                Enumeration _poa_enum = poas.elements();
271:
272:                //copy elements from vector to array
273:                int _i = 0;
274:                while (_poa_enum.hasMoreElements())
275:                    _poas[_i++] = ((ImRPOAInfo) _poa_enum.nextElement())
276:                            .toPOAInfo();
277:
278:                poas_lock.releaseExclusiveLock();
279:                table_lock.releaseSharedLock();
280:
281:                return _poas;
282:            }
283:
284:            /**
285:             * Add a host to the table. If an entry for <code>name</code> is already
286:             * in the table it is overwritten.
287:             *
288:             * @param name the hosts name.
289:             * @param host the hosts ImRHostInfo object.
290:             */
291:
292:            public void putHost(String name, ImRHostInfo host) {
293:                table_lock.gainSharedLock();
294:                hosts_lock.gainSharedLock();
295:
296:                hosts.put(name, host);
297:
298:                hosts_lock.releaseSharedLock();
299:                table_lock.releaseSharedLock();
300:            }
301:
302:            /**
303:             * Remove a host from the table.
304:             *
305:             * @param name the hosts name.
306:             */
307:
308:            public Object removeHost(String name) {
309:                return hosts.remove(name);
310:            }
311:
312:            /**
313:             * Get the ImRHostInfo object of a host.
314:             *
315:             * @param name the hosts name.
316:             * @return the ImRHostInfo object for <code>name</code>, null 
317:             * if <code>name</code> not in the table.
318:             */
319:
320:            public ImRHostInfo getHost(String name) {
321:                return (ImRHostInfo) hosts.get(name);
322:            }
323:
324:            /**
325:             * Implemented from the Serializable interface. For 
326:             * automatic initializing after deserialization.
327:             */
328:
329:            private void readObject(java.io.ObjectInputStream in)
330:                    throws java.io.IOException, java.io.NotActiveException,
331:                    ClassNotFoundException {
332:                in.defaultReadObject();
333:                initTransient();
334:            }
335:        } // ServerTable
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.