Source Code Cross Referenced for ImRServerInfo.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:        /*
002:         *        JacORB - a free Java ORB
003:         *
004:         *   Copyright (C) 1999-2004 Gerald Brose
005:         *
006:         *   This library is free software; you can redistribute it and/or
007:         *   modify it under the terms of the GNU Library General Public
008:         *   License as published by the Free Software Foundation; either
009:         *   version 2 of the License, or (at your option) any later version.
010:         *
011:         *   This library is distributed in the hope that it will be useful,
012:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         *   Library General Public License for more details.
015:         *
016:         *   You should have received a copy of the GNU Library General Public
017:         *   License along with this library; if not, write to the Free
018:         *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019:         *
020:         */
021:
022:        package org.jacorb.imr;
023:
024:        import java.util.*;
025:
026:        import org.jacorb.imr.AdminPackage.*;
027:
028:        /**
029:         * This class contains the information about a logical server.
030:         * It has methods for managing the associated POAs, holding and
031:         * releasing the server, and, for the "client side", a method
032:         * that blocks until the server is released.
033:         *
034:         * @author Nicolas Noffke
035:         * @version $Id: ImRServerInfo.java,v 1.14 2006/07/14 11:41:38 alphonse.bendt Exp $
036:         */
037:        public class ImRServerInfo implements  java.io.Serializable {
038:            public static final long serialVersionUID = 1l;
039:
040:            protected String command;
041:            protected boolean holding = false;
042:            protected String host;
043:            protected String name;
044:            protected boolean active;
045:            protected boolean restarting = false;
046:
047:            private final List poas = new ArrayList();
048:            private ResourceLock poas_lock = null;
049:
050:            /**
051:             * The Constructor. It sets up the internal attributes.
052:             *
053:             * @param name the logical server name
054:             * @param host the name of the host on which the server should be restarted
055:             * (ignored when no startup command is specified).
056:             * @param command the startup command for this server, passed to the
057:             * server startup daemon on <code>host</code> (in case there is one active).
058:             * @exception IllegalServerName thrown when <code>name</code> is
059:             * <code>null</code> or of length zero.
060:             */
061:
062:            public ImRServerInfo(String name, String host, String command)
063:                    throws IllegalServerName {
064:                if (name == null || name.length() == 0) {
065:                    throw new IllegalServerName(name);
066:                }
067:
068:                this .name = name;
069:                this .host = host;
070:                this .command = command;
071:                active = false;
072:                poas_lock = new ResourceLock();
073:            }
074:
075:            /**
076:             * "Converts" this Object to a <code>ServerInfo</code> instance containing
077:             * the same info as this object.
078:             *
079:             * @return a <code>ServerInfo</code> object.
080:             */
081:
082:            public ServerInfo toServerInfo() {
083:                poas_lock.gainExclusiveLock();
084:
085:                // The ServerInfo class stores its POAs in an array, therefore
086:                // the vector has to copied. Because of backward compatibility
087:                // issues we decided not to use toArray() from the jdk1.2
088:
089:                // build array
090:                final POAInfo[] _info;
091:                synchronized (poas) {
092:                    ImRPOAInfo[] _poas = (ImRPOAInfo[]) poas
093:                            .toArray(new ImRPOAInfo[poas.size()]);
094:
095:                    _info = new POAInfo[_poas.length];
096:                    for (int i = 0; i < _info.length; i++) {
097:                        _info[i] = _poas[i].toPOAInfo();
098:                    }
099:                }
100:
101:                poas_lock.releaseExclusiveLock();
102:
103:                return new ServerInfo(name, command, _info, host, active,
104:                        holding);
105:            }
106:
107:            /**
108:             * Adds a POA to this server.
109:             *
110:             * @param poa the POA to add.
111:             */
112:
113:            public void addPOA(ImRPOAInfo poa) {
114:                if (!active) {
115:                    active = true;
116:                }
117:
118:                poas_lock.gainSharedLock();
119:                synchronized (poas) {
120:                    poas.add(poa);
121:                }
122:                poas_lock.releaseSharedLock();
123:            }
124:
125:            /**
126:             * Builds an array of of the names of the POAs associated with this server.
127:             * <br> This method is needed for deleting a server since its POAs have to be
128:             * as well removed from the central storage.
129:             * @return an array of POA names
130:             */
131:
132:            protected String[] getPOANames() {
133:                // build array
134:                final String[] names;
135:                synchronized (poas) {
136:                    ImRPOAInfo[] _poas = (ImRPOAInfo[]) poas
137:                            .toArray(new POAInfo[poas.size()]);
138:
139:                    names = new String[_poas.length];
140:                    for (int i = 0; i < names.length; i++) {
141:                        names[i] = _poas[i].name;
142:                    }
143:                }
144:
145:                return names;
146:            }
147:
148:            /**
149:             * Sets the server down, i.e. not active. If a request for a POA
150:             * of this server is received, the repository tries to restart the server.
151:             * <br>The server is automatically set back to active when the first of
152:             * its POAs gets reregistered.
153:             */
154:
155:            public void setDown() {
156:                synchronized (poas) {
157:                    // sets all associated to not active.
158:                    for (int _i = 0; _i < poas.size(); _i++) {
159:                        ((ImRPOAInfo) poas.get(_i)).active = false;
160:                    }
161:                }
162:
163:                active = false;
164:                restarting = false;
165:            }
166:
167:            /**
168:             * This method blocks until the server is released, i.e. set
169:             * to not holding. <br> This will not time out since holding a
170:             * server is only done by administrators.
171:             */
172:
173:            public synchronized void awaitRelease() {
174:                while (holding) {
175:                    try {
176:                        wait();
177:                    } catch (InterruptedException e) {
178:                        // ignored
179:                    }
180:                }
181:            }
182:
183:            /**
184:             * Release the server and unblock all waiting threads.
185:             */
186:
187:            public synchronized void release() {
188:                holding = false;
189:                notifyAll();
190:            }
191:
192:            /**
193:             * Tests if this server should be restarted. That is the
194:             * case if the server is not active and nobody else is currently
195:             * trying to restart it. <br>
196:             * If true is returned the server is set to restarting. That means
197:             * the thread calling this method has to restart the server,
198:             * otherwise it will stay down indefinetly.
199:             *
200:             * @return true, if the server should be restarted by the calling thread.
201:             */
202:
203:            public synchronized boolean shouldBeRestarted() {
204:                boolean _restart = !(active || restarting);
205:                if (_restart) {
206:                    restarting = true;
207:                }
208:
209:                return _restart;
210:            }
211:
212:            public void setNotRestarting() {
213:                restarting = false;
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.