corba/src/share/classes/com/sun/corba/se/internal/CosNaming/BootstrapServer.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.internal.CosNaming;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.util.Enumeration;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.util.Properties;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.io.File;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import java.io.FileInputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import com.sun.corba.se.spi.orb.ORB ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import com.sun.corba.se.spi.resolver.Resolver ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import com.sun.corba.se.spi.resolver.LocalResolver ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import com.sun.corba.se.spi.resolver.ResolverDefault ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import com.sun.corba.se.impl.orbutil.CorbaResourceUtil;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import com.sun.corba.se.impl.orbutil.ORBConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
 * Class BootstrapServer is the main entry point for the bootstrap server
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
 * implementation.  The BootstrapServer makes all object references
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 * defined in a configurable file available using the old
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
 * naming bootstrap protocol.
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
public class BootstrapServer
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
    private ORB orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
     /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
     * Main startup routine for the bootstrap server.
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
     * It first determines the port on which to listen, checks that the
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
     * specified file is available, and then creates the resolver
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
     * that will be used to service the requests in the
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
     * BootstrapServerRequestDispatcher.
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
     * @param args the command-line arguments to the main program.
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    public static final void main(String[] args)
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
        String propertiesFilename = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
        int initialPort = ORBConstants.DEFAULT_INITIAL_PORT;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
        // Process arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        for (int i=0;i<args.length;i++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
            // Look for the filename
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
            if (args[i].equals("-InitialServicesFile") && i < args.length -1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
                propertiesFilename = args[i+1];
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
            // Was the initial port specified? If so, override
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
            // This property normally is applied for the client side
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
            // configuration of resolvers.  Here we are using it to
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
            // define the server port that the with which the resolvers
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
            // communicate.
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
            if (args[i].equals("-ORBInitialPort") && i < args.length-1) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
                initialPort = java.lang.Integer.parseInt(args[i+1]);
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        if (propertiesFilename == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            System.out.println( CorbaResourceUtil.getText("bootstrap.usage",
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
                "BootstrapServer"));
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        // Create a file
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
        File file = new File(propertiesFilename);
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
        // Verify that if it exists, it is readable
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        if (file.exists() == true && file.canRead() == false) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
            System.err.println(CorbaResourceUtil.getText(
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
                "bootstrap.filenotreadable", file.getAbsolutePath()));
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
            return;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
        // Success: start up
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
        System.out.println(CorbaResourceUtil.getText(
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
            "bootstrap.success", Integer.toString(initialPort),
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
            file.getAbsolutePath()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
        Properties props = new Properties() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
        // Use the SERVER_PORT to create an Acceptor using the
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
        // old legacy code in ORBConfiguratorImpl.  When (if?)
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
        // the legacy support is removed, this code will need
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        // to create an Acceptor directly.
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        props.put( ORBConstants.SERVER_PORT_PROPERTY,
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
            Integer.toString( initialPort ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        ORB orb = (ORB) org.omg.CORBA.ORB.init(args,props);
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        LocalResolver lres = orb.getLocalResolver() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        Resolver fres = ResolverDefault.makeFileResolver( orb, file ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
        Resolver cres = ResolverDefault.makeCompositeResolver( fres, lres ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        LocalResolver sres = ResolverDefault.makeSplitLocalResolver( cres, lres ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        orb.setLocalResolver( sres ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
            // This causes the acceptors to start listening.
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
            orb.resolve_initial_references(ORBConstants.ROOT_POA_NAME);
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            RuntimeException rte = new RuntimeException("This should not happen");
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
            rte.initCause(e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            throw rte;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
        orb.run() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
}