4
|
1 |
/*
|
|
2 |
*
|
5555
|
3 |
* Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
|
4
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
5 |
*
|
|
6 |
* This code is free software; you can redistribute it and/or modify it
|
|
7 |
* under the terms of the GNU General Public License version 2 only, as
|
5555
|
8 |
* published by the Free Software Foundation. Oracle designates this
|
4
|
9 |
* particular file as subject to the "Classpath" exception as provided
|
5555
|
10 |
* by Oracle in the LICENSE file that accompanied this code.
|
4
|
11 |
*
|
|
12 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
16 |
* accompanied this code).
|
|
17 |
*
|
|
18 |
* You should have received a copy of the GNU General Public License version
|
|
19 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
20 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
21 |
*
|
5555
|
22 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
23 |
* or visit www.oracle.com if you need additional information or have any
|
|
24 |
* questions.
|
4
|
25 |
*
|
|
26 |
*/
|
|
27 |
|
|
28 |
package com.sun.corba.se.impl.activation;
|
|
29 |
|
|
30 |
import java.io.File;
|
|
31 |
import java.util.Properties;
|
|
32 |
|
|
33 |
import org.omg.CORBA.INITIALIZE;
|
|
34 |
import org.omg.CORBA.INTERNAL;
|
|
35 |
import org.omg.CORBA.CompletionStatus;
|
|
36 |
import org.omg.CosNaming.NamingContext;
|
|
37 |
import org.omg.PortableServer.POA;
|
|
38 |
|
|
39 |
import com.sun.corba.se.pept.transport.Acceptor;
|
|
40 |
|
|
41 |
import com.sun.corba.se.spi.activation.Repository;
|
|
42 |
import com.sun.corba.se.spi.activation.RepositoryPackage.ServerDef;
|
|
43 |
import com.sun.corba.se.spi.activation.Locator;
|
|
44 |
import com.sun.corba.se.spi.activation.LocatorHelper;
|
|
45 |
import com.sun.corba.se.spi.activation.Activator;
|
|
46 |
import com.sun.corba.se.spi.activation.ActivatorHelper;
|
|
47 |
import com.sun.corba.se.spi.activation.ServerAlreadyRegistered;
|
|
48 |
import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;
|
|
49 |
import com.sun.corba.se.spi.transport.SocketInfo;
|
|
50 |
import com.sun.corba.se.spi.orb.ORB;
|
|
51 |
|
|
52 |
import com.sun.corba.se.impl.legacy.connection.SocketFactoryAcceptorImpl;
|
|
53 |
import com.sun.corba.se.impl.naming.cosnaming.TransientNameService;
|
|
54 |
import com.sun.corba.se.impl.naming.pcosnaming.NameService;
|
|
55 |
import com.sun.corba.se.impl.orbutil.ORBConstants;
|
|
56 |
import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
|
|
57 |
import com.sun.corba.se.impl.transport.SocketOrChannelAcceptorImpl;
|
|
58 |
|
|
59 |
/**
|
|
60 |
*
|
|
61 |
* @author Rohit Garg
|
|
62 |
* @since JDK1.2
|
|
63 |
*/
|
|
64 |
public class ORBD
|
|
65 |
{
|
|
66 |
private int initSvcPort;
|
|
67 |
|
|
68 |
protected void initializeBootNaming(ORB orb)
|
|
69 |
{
|
|
70 |
// create a bootstrap server
|
|
71 |
initSvcPort = orb.getORBData().getORBInitialPort();
|
|
72 |
|
|
73 |
Acceptor acceptor;
|
|
74 |
// REVISIT: see ORBConfigurator. use factory in TransportDefault.
|
|
75 |
if (orb.getORBData().getLegacySocketFactory() == null) {
|
|
76 |
acceptor =
|
|
77 |
new SocketOrChannelAcceptorImpl(
|
|
78 |
orb,
|
|
79 |
initSvcPort,
|
|
80 |
LegacyServerSocketEndPointInfo.BOOT_NAMING,
|
|
81 |
SocketInfo.IIOP_CLEAR_TEXT);
|
|
82 |
} else {
|
|
83 |
acceptor =
|
|
84 |
new SocketFactoryAcceptorImpl(
|
|
85 |
orb,
|
|
86 |
initSvcPort,
|
|
87 |
LegacyServerSocketEndPointInfo.BOOT_NAMING,
|
|
88 |
SocketInfo.IIOP_CLEAR_TEXT);
|
|
89 |
}
|
|
90 |
orb.getCorbaTransportManager().registerAcceptor(acceptor);
|
|
91 |
}
|
|
92 |
|
|
93 |
protected ORB createORB(String[] args)
|
|
94 |
{
|
|
95 |
Properties props = System.getProperties();
|
|
96 |
|
|
97 |
// For debugging.
|
|
98 |
//props.put( ORBConstants.DEBUG_PROPERTY, "naming" ) ;
|
|
99 |
//props.put( ORBConstants.DEBUG_PROPERTY, "transport,giop,naming" ) ;
|
|
100 |
|
|
101 |
props.put( ORBConstants.SERVER_ID_PROPERTY, "1000" ) ;
|
|
102 |
props.put( ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY,
|
|
103 |
props.getProperty( ORBConstants.ORBD_PORT_PROPERTY,
|
|
104 |
Integer.toString(
|
|
105 |
ORBConstants.DEFAULT_ACTIVATION_PORT ) ) ) ;
|
|
106 |
|
|
107 |
// See Bug 4396928 for more information about why we are initializing
|
|
108 |
// the ORBClass to PIORB (now ORBImpl, but should check the bugid).
|
|
109 |
props.put("org.omg.CORBA.ORBClass",
|
|
110 |
"com.sun.corba.se.impl.orb.ORBImpl");
|
|
111 |
|
|
112 |
return (ORB) ORB.init(args, props);
|
|
113 |
}
|
|
114 |
|
|
115 |
private void run(String[] args)
|
|
116 |
{
|
|
117 |
try {
|
|
118 |
// parse the args and try setting the values for these
|
|
119 |
// properties
|
|
120 |
processArgs(args);
|
|
121 |
|
|
122 |
ORB orb = createORB(args);
|
|
123 |
|
|
124 |
if (orb.orbdDebugFlag)
|
|
125 |
System.out.println( "ORBD begins initialization." ) ;
|
|
126 |
|
|
127 |
boolean firstRun = createSystemDirs( ORBConstants.DEFAULT_DB_DIR );
|
|
128 |
|
|
129 |
startActivationObjects(orb);
|
|
130 |
|
|
131 |
if (firstRun) // orbd is being run the first time
|
|
132 |
installOrbServers(getRepository(), getActivator());
|
|
133 |
|
|
134 |
if (orb.orbdDebugFlag) {
|
|
135 |
System.out.println( "ORBD is ready." ) ;
|
|
136 |
System.out.println("ORBD serverid: " +
|
|
137 |
System.getProperty(ORBConstants.SERVER_ID_PROPERTY));
|
|
138 |
System.out.println("activation dbdir: " +
|
|
139 |
System.getProperty(ORBConstants.DB_DIR_PROPERTY));
|
|
140 |
System.out.println("activation port: " +
|
|
141 |
System.getProperty(ORBConstants.ORBD_PORT_PROPERTY));
|
|
142 |
|
|
143 |
String pollingTime = System.getProperty(
|
|
144 |
ORBConstants.SERVER_POLLING_TIME);
|
|
145 |
if( pollingTime == null ) {
|
|
146 |
pollingTime = Integer.toString(
|
|
147 |
ORBConstants.DEFAULT_SERVER_POLLING_TIME );
|
|
148 |
}
|
|
149 |
System.out.println("activation Server Polling Time: " +
|
|
150 |
pollingTime + " milli-seconds ");
|
|
151 |
|
|
152 |
String startupDelay = System.getProperty(
|
|
153 |
ORBConstants.SERVER_STARTUP_DELAY);
|
|
154 |
if( startupDelay == null ) {
|
|
155 |
startupDelay = Integer.toString(
|
|
156 |
ORBConstants.DEFAULT_SERVER_STARTUP_DELAY );
|
|
157 |
}
|
|
158 |
System.out.println("activation Server Startup Delay: " +
|
|
159 |
startupDelay + " milli-seconds " );
|
|
160 |
}
|
|
161 |
|
|
162 |
// The following two lines start the Persistent NameService
|
|
163 |
NameServiceStartThread theThread =
|
|
164 |
new NameServiceStartThread( orb, dbDir );
|
|
165 |
theThread.start( );
|
|
166 |
|
|
167 |
orb.run();
|
|
168 |
} catch( org.omg.CORBA.COMM_FAILURE cex ) {
|
|
169 |
System.out.println( CorbaResourceUtil.getText("orbd.commfailure"));
|
|
170 |
System.out.println( cex );
|
|
171 |
cex.printStackTrace();
|
|
172 |
} catch( org.omg.CORBA.INTERNAL iex ) {
|
|
173 |
System.out.println( CorbaResourceUtil.getText(
|
|
174 |
"orbd.internalexception"));
|
|
175 |
System.out.println( iex );
|
|
176 |
iex.printStackTrace();
|
|
177 |
} catch (Exception ex) {
|
|
178 |
System.out.println(CorbaResourceUtil.getText(
|
|
179 |
"orbd.usage", "orbd"));
|
|
180 |
System.out.println( ex );
|
|
181 |
ex.printStackTrace();
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
private void processArgs(String[] args)
|
|
186 |
{
|
|
187 |
Properties props = System.getProperties();
|
|
188 |
for (int i=0; i < args.length; i++) {
|
|
189 |
if (args[i].equals("-port")) {
|
|
190 |
if ((i+1) < args.length) {
|
|
191 |
props.put(ORBConstants.ORBD_PORT_PROPERTY, args[++i]);
|
|
192 |
} else {
|
|
193 |
System.out.println(CorbaResourceUtil.getText(
|
|
194 |
"orbd.usage", "orbd"));
|
|
195 |
}
|
|
196 |
} else if (args[i].equals("-defaultdb")) {
|
|
197 |
if ((i+1) < args.length) {
|
|
198 |
props.put(ORBConstants.DB_DIR_PROPERTY, args[++i]);
|
|
199 |
} else {
|
|
200 |
System.out.println(CorbaResourceUtil.getText(
|
|
201 |
"orbd.usage", "orbd"));
|
|
202 |
}
|
|
203 |
} else if (args[i].equals("-serverid")) {
|
|
204 |
if ((i+1) < args.length) {
|
|
205 |
props.put(ORBConstants.SERVER_ID_PROPERTY, args[++i]);
|
|
206 |
} else {
|
|
207 |
System.out.println(CorbaResourceUtil.getText(
|
|
208 |
"orbd.usage", "orbd"));
|
|
209 |
}
|
|
210 |
} else if (args[i].equals("-serverPollingTime")) {
|
|
211 |
if ((i+1) < args.length) {
|
|
212 |
props.put(ORBConstants.SERVER_POLLING_TIME, args[++i]);
|
|
213 |
} else {
|
|
214 |
System.out.println(CorbaResourceUtil.getText(
|
|
215 |
"orbd.usage", "orbd"));
|
|
216 |
}
|
|
217 |
} else if (args[i].equals("-serverStartupDelay")) {
|
|
218 |
if ((i+1) < args.length) {
|
|
219 |
props.put(ORBConstants.SERVER_STARTUP_DELAY, args[++i]);
|
|
220 |
} else {
|
|
221 |
System.out.println(CorbaResourceUtil.getText(
|
|
222 |
"orbd.usage", "orbd"));
|
|
223 |
}
|
|
224 |
}
|
|
225 |
}
|
|
226 |
}
|
|
227 |
|
|
228 |
/**
|
|
229 |
* Ensure that the Db directory exists. If not, create the Db
|
|
230 |
* and the log directory and return true. Otherwise return false.
|
|
231 |
*/
|
|
232 |
protected boolean createSystemDirs(String defaultDbDir)
|
|
233 |
{
|
|
234 |
boolean dirCreated = false;
|
|
235 |
Properties props = System.getProperties();
|
|
236 |
String fileSep = props.getProperty("file.separator");
|
|
237 |
|
|
238 |
// determine the ORB db directory
|
|
239 |
dbDir = new File (props.getProperty( ORBConstants.DB_DIR_PROPERTY,
|
|
240 |
props.getProperty("user.dir") + fileSep + defaultDbDir));
|
|
241 |
|
|
242 |
// create the db and the logs directories
|
|
243 |
dbDirName = dbDir.getAbsolutePath();
|
|
244 |
props.put(ORBConstants.DB_DIR_PROPERTY, dbDirName);
|
|
245 |
if (!dbDir.exists()) {
|
|
246 |
dbDir.mkdir();
|
|
247 |
dirCreated = true;
|
|
248 |
}
|
|
249 |
|
|
250 |
File logDir = new File (dbDir, ORBConstants.SERVER_LOG_DIR ) ;
|
|
251 |
if (!logDir.exists()) logDir.mkdir();
|
|
252 |
|
|
253 |
return dirCreated;
|
|
254 |
}
|
|
255 |
|
|
256 |
protected File dbDir;
|
|
257 |
protected File getDbDir()
|
|
258 |
{
|
|
259 |
return dbDir;
|
|
260 |
}
|
|
261 |
|
|
262 |
private String dbDirName;
|
|
263 |
protected String getDbDirName()
|
|
264 |
{
|
|
265 |
return dbDirName;
|
|
266 |
}
|
|
267 |
|
|
268 |
protected void startActivationObjects(ORB orb) throws Exception
|
|
269 |
{
|
|
270 |
// create Initial Name Service object
|
|
271 |
initializeBootNaming(orb);
|
|
272 |
|
|
273 |
// create Repository object
|
|
274 |
repository = new RepositoryImpl(orb, dbDir, orb.orbdDebugFlag );
|
|
275 |
orb.register_initial_reference( ORBConstants.SERVER_REPOSITORY_NAME, repository );
|
|
276 |
|
|
277 |
// create Locator and Activator objects
|
|
278 |
ServerManagerImpl serverMgr =
|
|
279 |
new ServerManagerImpl( orb,
|
|
280 |
orb.getCorbaTransportManager(),
|
|
281 |
repository,
|
|
282 |
getDbDirName(),
|
|
283 |
orb.orbdDebugFlag );
|
|
284 |
|
|
285 |
locator = LocatorHelper.narrow(serverMgr);
|
|
286 |
orb.register_initial_reference( ORBConstants.SERVER_LOCATOR_NAME, locator );
|
|
287 |
|
|
288 |
activator = ActivatorHelper.narrow(serverMgr);
|
|
289 |
orb.register_initial_reference( ORBConstants.SERVER_ACTIVATOR_NAME, activator );
|
|
290 |
|
|
291 |
// start Name Service
|
|
292 |
TransientNameService nameService = new TransientNameService(orb,
|
|
293 |
ORBConstants.TRANSIENT_NAME_SERVICE_NAME);
|
|
294 |
}
|
|
295 |
|
|
296 |
protected Locator locator;
|
|
297 |
protected Locator getLocator()
|
|
298 |
{
|
|
299 |
return locator;
|
|
300 |
}
|
|
301 |
|
|
302 |
protected Activator activator;
|
|
303 |
protected Activator getActivator()
|
|
304 |
{
|
|
305 |
return activator;
|
|
306 |
}
|
|
307 |
|
|
308 |
protected RepositoryImpl repository;
|
|
309 |
protected RepositoryImpl getRepository()
|
|
310 |
{
|
|
311 |
return repository;
|
|
312 |
}
|
|
313 |
|
|
314 |
/**
|
|
315 |
* Go through the list of ORB Servers and initialize and start
|
|
316 |
* them up.
|
|
317 |
*/
|
|
318 |
protected void installOrbServers(RepositoryImpl repository,
|
|
319 |
Activator activator)
|
|
320 |
{
|
|
321 |
int serverId;
|
|
322 |
String[] server;
|
|
323 |
ServerDef serverDef;
|
|
324 |
|
|
325 |
for (int i=0; i < orbServers.length; i++) {
|
|
326 |
try {
|
|
327 |
server = orbServers[i];
|
|
328 |
serverDef = new ServerDef(server[1], server[2],
|
|
329 |
server[3], server[4], server[5] );
|
|
330 |
|
|
331 |
serverId = Integer.valueOf(orbServers[i][0]).intValue();
|
|
332 |
|
|
333 |
repository.registerServer(serverDef, serverId);
|
|
334 |
|
|
335 |
activator.activate(serverId);
|
|
336 |
|
|
337 |
} catch (Exception ex) {}
|
|
338 |
}
|
|
339 |
}
|
|
340 |
|
|
341 |
public static void main(String[] args) {
|
|
342 |
ORBD orbd = new ORBD();
|
|
343 |
orbd.run(args);
|
|
344 |
}
|
|
345 |
|
|
346 |
/**
|
|
347 |
* List of servers to be auto registered and started by the ORBd.
|
|
348 |
*
|
|
349 |
* Each server entry is of the form {id, name, path, args, vmargs}.
|
|
350 |
*/
|
|
351 |
private static String[][] orbServers = {
|
|
352 |
{""}
|
|
353 |
};
|
|
354 |
}
|