Difference Analysis Generated by HtmlDiff on 1/9/2008 4:45 PM  

Base file: X:\carol_checkin_archive\carol-429\src\org\objectweb\carol\jndi\ns\JeremieRegistry.java

Modified file: X:\carol_checkin_archive\carol-430\src\org\objectweb\carol\jndi\ns\JeremieRegistry.java

 
1:  /**
2:   * Copyright (C) 2002,2004 - INRIA (www.inria.fr)
3:   *
4:   * CAROL: Common Architecture for RMI ObjectWeb Layer
5:   *
6:   * This library is developed inside the ObjectWeb Consortium,
7:   * http://www.objectweb.org
8:   *
9:   * This library is free software; you can redistribute it and/or
10:  * modify it under the terms of the GNU Lesser General Public
11:  * License as published by the Free Software Foundation; either
12:  * version 2.1 of the License, or any later version.
13:  *
14:  * This library is distributed in the hope that it will be useful,
15:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17:  * Lesser General Public License for more details.
18:  *
19:  * You should have received a copy of the GNU Lesser General Public
20:  * License along with this library; if not, write to the Free Software
21:  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
22:  * USA
23:  *
24:  * --------------------------------------------------------------------------
25:  * $Id: JeremieRegistry.java 397 2005-03-03 16:10:32Z430 2005-03-10 12:21:46Z benoitf $
26:  * --------------------------------------------------------------------------
27:  */
28: package org.objectweb.carol.jndi.ns;
29: 
30: import java.rmi.RemoteException;
31: import java.rmi.registry.Registry;
32: import java.util.Properties;
33: 
34: import org.objectweb.jeremie.binding.moa.UnicastRemoteObject;
35: import org.objectweb.jeremie.services.registry.LocateRegistry;
36: 
37: import org.objectweb.carol.rmi.util.PortNumber;
38: import org.objectweb.carol.util.configuration.CarolDefaultValues;
39: import org.objectweb.carol.util.configuration.TraceCarol;
40: 
41: /**
42:  * Class <code> JeremieRegistry </code>
43:  * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
44:  * @version 1.0, 15/01/2003
45:  * @author Florent Benoit (Refactoring)
46:  */

47: public class JeremieRegistry extends AbsRegistry implements NameService {
48: 
49:     /**
50:      * Hostname to useDefault port
51:      */
All host fields in the classes that implement NameService interface got deleted except LmiRegistry class. 
52:     private String host = null;
All DEFAULT_PORT_NUMBER fields are added fields except JacORBCosNaming class.
53:     private static final int DEFAULT_PORT_NUMBER = 12340;
54: 
55:     /**
56:      * port number ( 12340 for default)
57:      * Jeremie registry
58:      */
All port fields in the classes that implement NameService interface got deleted except LmiRegistry class.
59:     public int port = 12340;
60:     private Registry registry = null;
61: 
62:     /**
63:      * registryDefault constructor
64:      */
65:     public Registry registry = null;JeremieRegistry() {
66: 
67:     /**
68:      * Configuration properties (of carol.properties)
69:      */

All configurationProperties fields got deleted. 
70:     private Properties configurationProperties = null;
71:         super(DEFAULT_PORT_NUMBER);
72:     }
73: 
74:     /**
75:      * start Method, Start a new NameService or do nothing if the name service
76:      * is all ready start
77:      * @param int port is port number
78:      * @throws NameServiceException if a problem occure
79:      */
80:     public void start() throws NameServiceException {
81:         if (TraceCarol.isDebugJndiCarol()) {
82:             TraceCarol.debugJndiCarol("JeremieRegistry.start() on port:" + portgetPort());
83:         }
84: 
85:         // Fix jeremie port if running inside a server
86:         if (System.getProperty(CarolDefaultValues.SERVER_MODE, "false").equalsIgnoreCase("true")) {
87:             if (configurationPropertiesgetConfigProperties() != null) {
88:                 String propertyName = CarolDefaultValues.SERVER_JEREMIE_PORT;
89:                 int jeremiePort = PortNumber.strToint(configurationProperties.getConfigProperties().getProperty(propertyName, "0"), propertyName);
90:                         propertyName);
91:                 if (jeremiePort > 0) {
92:                     TraceCarol.infoCarol("Using Jeremie fixed server port number '" + jeremiePort + "'.");
93:                     System.setProperty("org.objectweb.jeremie.stub_factories.defaultport", String.valueOf(jeremiePort));
94:                 }
95:             } else {
96:                 TraceCarol.debugCarol("No properties '" + CarolDefaultValues.SERVER_IIOP_PORT + "' defined in carol.properties file.");
97:                         + "' defined in carol.properties file.");
98:             }
99:         }
100:    
101:    
102:    
103:    
104:    
105:            try {
106:                if (!isStarted()) {
107:                    if (portgetPort() >= 0) {
108:                        registry = LocateRegistry.createRegistry(portgetPort());
109:                        // add a shudown hook for this process
110:                        Runtime.getRuntime().addShutdownHook(new Thread() {
111:    
112:                            public void run() {
113:                                try {
114:                                    JeremieRegistry.this.stop();
115:                                } catch (Exception e) {
116:                                    TraceCarol.error("JeremieRegistry ShutdownHook problem", e);
117:                                }
118:                            }
119:                        });
120:                    } else {
121:                        if (TraceCarol.isDebugJndiCarol()) {
122:                            TraceCarol.debugJndiCarol("Can't start JeremieRegistry, port=" + portgetPort() + " is < 0");
123:                        }
124:                    }
125:    
126:                } else {
127:                    if (TraceCarol.isDebugJndiCarol()) {
128:                        TraceCarol.debugJndiCarol("JeremieRegistry is already start on port:" + portgetPort());
129:                    }
130:                }
131:            } catch (Exception e) {
132:                throw new NameServiceException("can not start jeremie registry: " + e);
133:            }
134:        }
135:    
136:        /**
137:         * stop Method, Stop a NameService or do nothing if the name service is all
138:         * ready stop
139:         * @throws NameServiceException if a problem occure
140:         */
141:        public void stop() throws NameServiceException {
142:            if (TraceCarol.isDebugJndiCarol()) {
143:                TraceCarol.debugJndiCarol("JeremieRegistry.stop()");
144:            }
145:            try {
146:                if (registry != null) {
147:                if (registry != null)    UnicastRemoteObject.unexportObject(registry, true);
148:                }
149:                registry = null;
150:            } catch (Exception e) {
151:                throw new NameServiceException("can not stop jeremie registry: " + e);
152:            }
153:        }
154:    
155:        /**
156:         * isStarted Method, check if a name service is started
157:         * @return boolean true if the name service is started
158:         */
159:        public boolean isStarted() {
160:    
161:            if (registry != null) return true;{
162:                return true;
163:            }
164:            try {
165:                LocateRegistry.getRegistry(portgetPort()).list();
166:            } catch (RemoteException re) {
167:                return false;
168:            }
169:            return true;
170:        }           
171:    
172:        /**
173:         * set port method, set the port for the name service
174:         * @param int port number
175:         */
All setPort methods in the classes that implement NameService interface got deleted except LmiRegistry class.
176:        public void setPort(int p) {
177:            if (TraceCarol.isDebugJndiCarol()) {
178:                TraceCarol.debugJndiCarol("JeremieRegistry.setPort(" + p + ")");
179:            }
180:            if (p != 0) {
181:                port = p;
182:            }
183:        }
184:    
185:        /*
186:         * (non-Javadoc)
187:         * @see org.objectweb.carol.jndi.ns.NameService#getPort()
188:         */
All getPort methods in the classes that implement NameService interface got deleted except LmiRegistry class.
189:        public int getPort() {
190:            return port;
191:        }
192:    
193:        /**
194:         * Set the address to use for bind
195:         * @param host hostname/ip address
196:         */
All setHost methods in the classes that implement NameService interface got deleted except LmiRegistry class.
197:        public void setHost(String host) {
198:            this.host = host;
199:        }
200:    
201:        /**
202:         * @return hostname/ip to use
203:         */
All getHost methods in the classes that implement NameService interface got deleted except LmiRegistry class.
204:         public String getHost() {
205:             return host;
206:         }
207:    
208:         /**
209:          * Set the configuration properties of the protocol
210:          * @param p configuration properties
211:          */
All setConfigProperties methods in the classes that implement NameService interface got deleted except LmiRegistry class. 
212:         public void setConfigProperties(Properties p) {
213:             this.configurationProperties = p;
214:         }
215:    }