NameServer.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.impl.naming.pcosnaming;
27
28import java.io.File;
29import java.util.Properties;
30
31import com.sun.corba.se.impl.orbutil.ORBConstants;
32import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
33import com.sun.corba.se.spi.orb.ORB;
34import com.sun.corba.se.spi.activation.InitialNameService;
35import com.sun.corba.se.spi.activation.InitialNameServiceHelper;
36import org.omg.CosNaming.NamingContext;
37/**
38 * Class NameServer is a standalone application which
39 * implements a persistent and a transient name service.
40 * It uses the PersistentNameService and TransientNameService
41 * classes for the name service implementation.
42 *
43 * @author      Hemanth Puttaswamy
44 * @since       JDK1.2
45 */
46
47public class NameServer
48{
49    private ORB orb;
50
51    private File dbDir; // name server database directory
52
53    private final static String dbName = "names.db";
54
55    public static void main(String args[])
56    {
57        NameServer ns = new NameServer(args);
58        ns.run();
59    }
60
61    protected NameServer(String args[])
62    {
63        // create the ORB Object
64        java.util.Properties props = System.getProperties();
65        props.put( ORBConstants.SERVER_ID_PROPERTY, "1000" ) ;
66        props.put("org.omg.CORBA.ORBClass",
67                  "com.sun.corba.se.impl.orb.ORBImpl");
68        orb = (ORB) org.omg.CORBA.ORB.init(args,props);
69
70        // set up the database directory
71        String dbDirName = props.getProperty( ORBConstants.DB_DIR_PROPERTY ) +
72            props.getProperty("file.separator") + dbName +
73            props.getProperty("file.separator");
74
75        dbDir = new File(dbDirName);
76        if (!dbDir.exists()) dbDir.mkdir();
77    }
78
79    protected void run()
80    {
81        try {
82
83            // create the persistent name service
84            NameService ns = new NameService(orb, dbDir);
85
86            // add root naming context to initial naming
87            NamingContext rootContext = ns.initialNamingContext();
88            InitialNameService ins = InitialNameServiceHelper.narrow(
89                                     orb.resolve_initial_references(
90                                     ORBConstants.INITIAL_NAME_SERVICE_NAME ));
91            ins.bind( "NameService", rootContext, true);
92            System.out.println(CorbaResourceUtil.getText("pnameserv.success"));
93
94            // wait for invocations
95            orb.run();
96
97        } catch (Exception ex) {
98
99            ex.printStackTrace(System.err);
100        }
101    }
102
103}
104