(Back To Overview)
1: /**
2: * Copyright (C) 2002,2005 - 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: JRMPRegistry.java 398 2005-03-03 16:11:03Z430 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.LocateRegistry;
32: import java.rmi.registry.Registry;
33: import java.rmi.server.UnicastRemoteObject;
34: import java.util.Properties;
35:
36: import org.objectweb.carol.jndi.registry.ManageableRegistry;
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> JRMPRegistry </code>
43: * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
44: * @version 1.0, 15/01/2003
45: */
46: public class JRMPRegistry extends AbsRegistry implements NameService {
47:
48: /**
49: * Hostname to useDefault port
50: */
All host fields in the classes that implement NameService interface got deleted except LmiRegistry class.
51: private String host = null;
52:
53: /**
54: * port number (1099 for default)
55: */
All port fields in the classes that implement NameService interface got deleted except LmiRegistry class.
56: public static int port = 1099;
All DEFAULT_PORT_NUMBER fields are added fields except JacORBCosNaming class.
57: private static final int DEFAULT_PORT_NUMBER = 1099;
58:
59: /**
60: * Instance port number (firewall)
61: */
62: private static int objectPort = 0;
63:
64: /**
65: * Configuration properties (of carol.properties)
66: * registry
67: */
All configurationProperties fields got deleted.
68: private Properties configurationPropertiesstatic Registry registry = null;
69:
70: /**
71: * registryDefault constructor
72: */
73: public static Registry registry = null;JRMPRegistry() {
74: super(DEFAULT_PORT_NUMBER);
75: }
76:
77: /**
78: * start Method, Start a new NameService or do nothing if the name service
79: * is all ready start
80: * @param int port is port number
81: * @throws NameServiceException if a problem occure
82: */
83: public void start() throws NameServiceException {
84: if (TraceCarol.isDebugJndiCarol()) {
85: TraceCarol.debugJndiCarol("JRMPRegistry.start() on port:" + portgetPort());
86: }
87: try {
88: if (!isStarted()) {
89:
90: // Fix jrmp port if running inside a server
91: if (System.getProperty(CarolDefaultValues.SERVER_MODE, "false").equalsIgnoreCase("true")) {
92: if (configurationPropertiesgetConfigProperties() != null) {
93: String propertyName = CarolDefaultValues.SERVER_JRMP_PORT;
94: int jrmpPort = PortNumber.strToint(configurationProperties.getConfigProperties().getProperty(propertyName, "0"), propertyName);
95: propertyName);
96: if (jrmpPort > 0) {
97: TraceCarol.infoCarol("Using JRMP fixed server port number '" + jrmpPort + "'.");
98: objectPort = jrmpPort;
99: }
100: } else {
101: TraceCarol.debugCarol("No properties '" + CarolDefaultValues.SERVER_IIOP_PORT + "' defined in carol.properties file.");
102: + "' defined in carol.properties file.");
103: }
104: }
105:
106:
107: if (portgetPort() >= 0) {
108: registry = ManageableRegistry.createManagableRegistry(portgetPort(), objectPort);
109: // add a shudown hook for this process
110: Runtime.getRuntime().addShutdownHook(new Thread() {
111:
112: public void run() {
113: try {
114: JRMPRegistry.this.stop();
115: } catch (Exception e) {
116: TraceCarol.error("JRMPRegistry ShutdownHook problem", e);
117: }
118: }
119: });
120: } else {
121: if (TraceCarol.isDebugJndiCarol()) {
122: TraceCarol.debugJndiCarol("Can't start JRMPRegistry, port=" + portgetPort() + " is < 0");
123: }
124: }
125: } else {
126: if (TraceCarol.isDebugJndiCarol()) {
127: TraceCarol.debugJndiCarol("JRMPRegistry is already start on port:" + portgetPort());
128: }
129: }
130: } catch (Exception e) {
131: throw new NameServiceException("can not start rmi registry: " + e);
132: }
133: }
134:
135: /**
136: * stop Method, Stop a NameService or do nothing if the name service is all
137: * ready stop
138: * @throws NameServiceException if a problem occure
139: */
140: public void stop() throws NameServiceException {
141: if (TraceCarol.isDebugJndiCarol()) {
142: TraceCarol.debugJndiCarol("JRMPRegistry.stop()");
143: }
144: try {
145: if (registry != null) {
146: if (registry != null) UnicastRemoteObject.unexportObject(registry, true);
147: }
148: registry = null;
149: } catch (Exception e) {
150: throw new NameServiceException("can not stop rmi registry: " + e);
151: }
152: }
153:
154: /**
155: * isStarted Method, check if a name service is local
156: * @return boolean true if the name service is local
157: */
158: public static boolean isLocal() {
159: if (registry != null) {
160: return truereturn (registry != null);
161: } else {
162: return false;
163: }
164: }
165:
166: /**
167: * isStarted Method, check if a name service is started
168: * @return boolean true if the name service is started
169: */
170: public boolean isStarted() {
171: if (registry != null) return true;{
172: return true;
173: }
174: try {
175: //TODO: Warning LocateRegistry Problem we are not in case of local
176: // computer registry ....
177: LocateRegistry.getRegistry(portgetPort()).list();
178: } catch (RemoteException re) {
179: return false;
180: }
181: return true;
182: }
183:
184: /**
185: * set port method, set the port for the name service
186: * @param int port number
187: */
All setPort methods in the classes that implement NameService interface got deleted except LmiRegistry class.
188: public void setPort(int p) {
189: if (TraceCarol.isDebugJndiCarol()) {
190: TraceCarol.debugJndiCarol("JRMPRegistry.setPort(" + p + ")");
191: }
192: if (p != 0) {
193: port = p;
194: }
195: }
196:
197: /*
198: * (non-Javadoc)
199: * @see org.objectweb.carol.jndi.ns.NameService#getPort()
200: */
All getPort methods in the classes that implement NameService interface got deleted except LmiRegistry class.
201: public int getPort() {
202: return port;
203: }
204:
205: /**
206: * Set the address to use for bind
207: * @param host hostname/ip address
208: */
All setHost methods in the classes that implement NameService interface got deleted except LmiRegistry class.
209: public void setHost(String host) {
210: this.host = host;
211: }
212:
213: /**
214: * @return hostname/ip to use
215: */
All getHost methods in the classes that implement NameService interface got deleted except LmiRegistry class.
216: public String getHost() {
217: return host;
218: }
219:
220: /**
221: * Set the configuration properties of the protocol
222: * @param p configuration properties
223: */
All setConfigProperties methods in the classes that implement NameService interface got deleted except LmiRegistry class.
224: public void setConfigProperties(Properties p) {
225: this.configurationProperties = p;
226: public static Registry getRegistry() {
227: return registry;
228: }
229: }