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\CmiRegistry.java

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

 
1:  /**
2:   * IIOPCosNaming.java 1.0 02/07/15 Copyright (C) 2002 - INRIA
3:   * * Copyright (C) 2003 - Simon Nieuviarts
4:   *
5:   * CAROL: Common Architecture for RMI ObjectWeb Layer
6:   *
7:   * This library is developed inside the ObjectWeb Consortium,
8:   * http://www.objectweb.org
9:   *
10:  * This library is free software; you can redistribute it and/or
11:  * modify it under the terms of the GNU Lesser General Public
12:  * License as published by the Free Software Foundation; either
13:  * version 2.1 of the License, or any later version.
14:  *
15:  * This library is distributed in the hope that it will be useful,
16:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18:  * Lesser General Public License for more details.
19:  *
20:  * You should have received a copy of the GNU Lesser General Public
21:  * License along with this library; if not, write to the Free Software
22:  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
23:  * USA
24:  *
25:  */
26: package org.objectweb.carol.jndi.ns;
27: 
28: import java.util.Properties;
29: 
30: import org.objectweb.carol.cmi.ClusterRegistry;
31: import org.objectweb.carol.cmi.ClusterRegistryImpl;
32: import org.objectweb.carol.cmi.ClusterRegistryKiller;
33: import org.objectweb.carol.cmi.DistributedEquiv;
34: import org.objectweb.carol.util.configuration.TraceCarol;
35: 
36: /**
37:  * Class <code>CmiRegistry</code>
38:  * @author Simon Nieuviarts (Simon.Nieuviarts@inrialpes.fr)
37:  * @author Florent Benoit (Refactoring)
39:  */  
40: public class CmiRegistry extends AbsRegistry implements NameService {
   
41: 
42:     /**
43:      * URL
44:      */   
All port fields in the classes that implement NameService interface got deleted except LmiRegistry class. 
45:     private int port = ClusterRegistry.DEFAULT_PORT;
46: 
47:     /**
48:      * Hostname to use
49:      */   
All host fields in the classes that implement NameService interface got deleted except LmiRegistry class. 
50:     private String host = null; 
51: 
52:     /**
53:      * Cluster equivalence system
54:      */
55:     private DistributedEquiv de = null;
56: 
57:     /**
58:      * To kill the registry server
59:      */
60:     private ClusterRegistryKiller cregk = null;
61: 
62:     /**
52:      * Default constructor
53:      */
54:     public CmiRegistry() {
55:         super(ClusterRegistry.DEFAULT_PORT);
56:     }
57: 
58: 
59:     /**
63:      * start Method, Start a new NameService or do nothing if the name service
64:      * is all ready start
65:      * @throws NameServiceException if a problem occure
66:      */
67:     public void start() throws NameServiceException {
68:         if (TraceCarol.isDebugJndiCarol()) {
69:             TraceCarol.debugJndiCarol("CmiRegistry.start() on port:" + portgetPort());
70:         }
71:         try {
72:             if (!isStarted()) {
73:                 if (portgetPort() >= 0) {
74:                     de = DistributedEquiv.start();
75:                     cregk = ClusterRegistryImpl.start(portgetPort());
76:                     // add a shudown hook for this process
77:                     Runtime.getRuntime().addShutdownHook(new Thread() {
78: 
79:                         public void run() {
80:                             try {
81:                                 CmiRegistry.this.stop();
82:                             } catch (Exception e) {
83:                                 TraceCarol.error("CmiRegistry ShutdownHook problem", e);
84:                             }
85:                         }
86:                     });
87:                 } else {
88:                     if (TraceCarol.isDebugJndiCarol()) {
89:                         TraceCarol.debugJndiCarol("Can't start CmiRegistry, port=" + portgetPort() + " is < 0");
90:                     }
91:                 }
92:             } else {
93:                 if (TraceCarol.isDebugJndiCarol()) {
94:                     TraceCarol.debugJndiCarol("CmiRegistry is already start on port:" + portgetPort());
95:                 }
96:             }
97:         } catch (Exception e) {
98:             String msg = "can not start cluster registry: " + e;
99:             TraceCarol.error(msg);
100:                throw new NameServiceException(msg);
101:            }
102:        }
103:    
104:        /**
105:         * stop Method, Stop a NameService or do nothing if the name service is
106:         * already stop
107:         * @throws NameServiceException if a problem occure
108:         */
109:        public void stop() throws NameServiceException {
110:            if (TraceCarol.isDebugJndiCarol()) {
111:                TraceCarol.debugJndiCarol("CmiRegistry.stop()");
112:            }
113:            try {
114:                if (cregk != null) {
115:                    cregk.stop();
116:                    de.stop();
117:                    cregk = null;
118:                }
119:            } catch (Exception e) {
120:                throw new NameServiceException("can not stop cluster registry: " + e);
121:            }
122:        }
123:    
124:        /**
125:         * isStarted Method, check if a name service is started
126:         * @return boolean true if the name service is started
127:         */
128:        public boolean isStarted() {
129:            if (cregk != null) {
130:                return true;
131:            }
132:            /*
133:             * try { LocateRegistry.getRegistry(port).list(); } catch
134:             * (RemoteException re) { return false; } return true;
135:             */
136:            return false;
137:        }
138:          
139:        /**
140:         * set port method, set the port for the name service
141:         * @param p port
142:         */ 
All setPort methods in the classes that implement NameService interface got deleted except LmiRegistry class.  
 143:        public void setPort(int p) {
144:            if (TraceCarol.isDebugJndiCarol()) {
145:                TraceCarol.debugJndiCarol("CmiRegistry.setPort(" + p + ")");
146:            }
147:            if (p != 0) {
148:                this.port = p;
149:            }
150:        }
151:    
152:        /*
153:         * (non-Javadoc)
154:         * @see org.objectweb.carol.jndi.ns.NameService#getPort()
155:         */ 
All getPort methods in the classes that implement NameService interface got deleted except LmiRegistry class. 
 156:        public int getPort() {
157:            return port;
158:        }
159:    
160:        /**
161:         * Set the address to use for bind
162:         * @param host hostname/ip address
163:         */
All setHost methods in the classes that implement NameService interface got deleted except LmiRegistry class. 
 164:        public void setHost(String host) {
165:            this.host = host;
166:        }
167:    
168:        /**
169:         * @return hostname/ip to use
170:         */ 
All getHost methods in the classes that implement NameService interface got deleted except LmiRegistry class. 
 171:         public String getHost() {
172:             return host;
173:         }
174:    
175:         /**
176:          * Set the configuration properties of the protocol
177:          * @param p configuration properties
178:          */ 
All setConfigProperties methods in the classes that implement NameService interface got deleted except LmiRegistry class. 
 179:         public void setConfigProperties(Properties p) {
180:    
181:         }

182:    }