OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [tools/] [gnu/] [classpath/] [tools/] [orbd/] [Main.java] - Blame information for rev 779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 779 jeremybenn
/* NamingServicePersistent.java -- The persistent naming service.
2
   Copyright (C) 2006, 2008, 2009, 2010, 2011, 2012
3
   Free Software Foundation, Inc.
4
 
5
This file is part of GNU Classpath.
6
 
7
GNU Classpath is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2, or (at your option)
10
any later version.
11
 
12
GNU Classpath is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with GNU Classpath; see the file COPYING.  If not, write to the
19
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
02110-1301 USA.
21
 
22
Linking this library statically or dynamically with other modules is
23
making a combined work based on this library.  Thus, the terms and
24
conditions of the GNU General Public License cover the whole
25
combination.
26
 
27
As a special exception, the copyright holders of this library give you
28
permission to link this library with independent modules to produce an
29
executable, regardless of the license terms of these independent
30
modules, and to copy and distribute the resulting executable under
31
terms of your choice, provided that you also meet, for each linked
32
independent module, the terms and conditions of the license of that
33
module.  An independent module is a module which is not derived from
34
or based on this library.  If you modify this library, you may extend
35
this exception to your version of the library, but you are not
36
obligated to do so.  If you do not wish to do so, delete this
37
exception statement from your version. */
38
 
39
package gnu.classpath.tools.orbd;
40
 
41
import gnu.CORBA.OrbFunctional;
42
import gnu.CORBA.IOR;
43
import gnu.CORBA.NamingService.Ext;
44
import gnu.classpath.tools.common.ClasspathToolParser;
45
import gnu.classpath.tools.getopt.Option;
46
import gnu.classpath.tools.getopt.OptionException;
47
import gnu.classpath.tools.getopt.Parser;
48
 
49
import org.omg.CosNaming.NamingContextExt;
50
 
51
import java.io.File;
52
import java.io.FileOutputStream;
53
import java.io.FileNotFoundException;
54
import java.io.PrintStream;
55
import java.io.UnsupportedEncodingException;
56
 
57
/**
58
 * The server for the GNU Classpath persistent naming service.
59
 *
60
 * GNU Classpath currently works with this naming service and is also
61
 * interoperable with the Sun Microsystems naming services from releases 1.3 and
62
 * 1.4, both transient <i>tnameserv</i> and persistent <i>orbd</i>.
63
 *
64
 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
65
 */
66
public class Main
67
{
68
  /**
69
   * The default port (900), on that the naming service starts if no
70
   * -ORBInitialPort is specified in the command line.
71
   */
72
  public static final int PORT = 900;
73
 
74
  private int port = PORT;
75
  private String iorf;
76
  private boolean cold;
77
  private String directory = "";
78
 
79
  /**
80
   * Get the object key for the naming service. The default key is the string
81
   * "NameService" in ASCII.
82
   *
83
   * @return the byte array.
84
   */
85
  public static byte[] getDefaultKey()
86
  {
87
    try
88
      { // NameService
89
        return "NameService".getBytes("UTF-8");
90
      }
91
    catch (UnsupportedEncodingException ex)
92
      {
93
        throw new InternalError("UTF-8 unsupported");
94
      }
95
  }
96
 
97
  private Parser initializeParser()
98
  {
99
    Parser parser = new ClasspathToolParser("orbd", true); //$NON-NLS-1$
100
    parser.setHeader(Messages.getString("Main.Usage")); //$NON-NLS-1$
101
 
102
    parser.add(new Option("ORBInitialPort", //$NON-NLS-1$
103
                          Messages.getString("Main.ORBInitialPort"), //$NON-NLS-1$
104
                          Messages.getString("Main.Port")) //$NON-NLS-1$
105
      {
106
        public void parsed(String portArgument) throws OptionException
107
        {
108
          port = Integer.parseInt(portArgument);
109
        }
110
      });
111
 
112
    parser.add(new Option("ior", //$NON-NLS-1$
113
                          Messages.getString("Main.IOR"), //$NON-NLS-1$
114
                          Messages.getString("Main.IORFile")) //$NON-NLS-1$
115
      {
116
        public void parsed(String fileArgument) throws OptionException
117
        {
118
          iorf = fileArgument;
119
        }
120
      });
121
    parser.add(new Option("directory", //$NON-NLS-1$
122
                          Messages.getString("Main.Directory"), //$NON-NLS-1$
123
                          Messages.getString("Main.DirectoryArgument")) //$NON-NLS-1$
124
      {
125
        public void parsed(String argument) throws OptionException
126
        {
127
          directory = argument;
128
        }
129
      });
130
    parser.add(new Option("restart", //$NON-NLS-1$
131
                          Messages.getString("Main.Restart")) //$NON-NLS-1$
132
      {
133
        public void parsed(String argument) throws OptionException
134
        {
135
          cold = true;
136
        }
137
      });
138
 
139
    return parser;
140
  }
141
 
142
  private void run(String[] args)
143
  {
144
    Parser parser = initializeParser();
145
    parser.parse(args);
146
 
147
    try
148
      {
149
        // Create and initialize the ORB
150
        final OrbFunctional orb = new OrbFunctional();
151
        OrbFunctional.setPort(port);
152
 
153
        // Create the servant and register it with the ORB
154
        File dataDirectory = new File(directory);
155
        System.out.println("Persistent data stored at "
156
                           + dataDirectory.getAbsolutePath());
157
        dataDirectory.mkdirs();
158
 
159
        // / TODO support more starting modes.
160
        NamingContextExt namer = new Ext(
161
                                         new PersistentContext(
162
                                                               orb,
163
                                                               dataDirectory,
164
                                                               cold));
165
 
166
        // Case with the key "NameService".
167
        orb.connect(namer, "NameService".getBytes());
168
 
169
        // Storing the IOR reference.
170
        String ior = orb.object_to_string(namer);
171
        IOR iorr = IOR.parse(ior);
172
        if (iorf != null)
173
          {
174
            FileOutputStream f = new FileOutputStream(iorf);
175
            PrintStream p = new PrintStream(f);
176
            p.print(ior);
177
            p.close();
178
          }
179
 
180
        System.out.println("GNU Classpath persistent naming service "
181
                           + "started at " + iorr.Internet.host + ":"
182
                           + iorr.Internet.port + " key 'NameService'.\n\n"
183
                           + "Copyright (C) 2012 Free Software Foundation\n"
184
                           + "This tool comes with ABSOLUTELY NO WARRANTY. "
185
                           + "This is free software, and you are\nwelcome to "
186
                           + "redistribute it under conditions, defined in "
187
                           + "GNU Classpath license.\n\n" + ior);
188
 
189
        new Thread()
190
        {
191
          public void run()
192
          {
193
            // Wait for invocations from clients.
194
            orb.run();
195
          }
196
        }.start();
197
      }
198
    catch (FileNotFoundException e)
199
      {
200
        throw new RuntimeException(e);
201
      }
202
    finally
203
      {
204
        // Restore the default value for allocating ports for the subsequent
205
        // objects.
206
        OrbFunctional.setPort(OrbFunctional.DEFAULT_INITIAL_PORT);
207
      }
208
  }
209
 
210
  /**
211
   * The persistent naming service entry point.
212
   */
213
  public static void main(String[] args)
214
  {
215
    Main orbdprogram = new Main();
216
    try
217
      {
218
        orbdprogram.run(args);
219
      }
220
    catch (Exception e)
221
      {
222
        System.err.println(Messages.getString("Main.InternalError")); //$NON-NLS-1$
223
        e.printStackTrace(System.err);
224
        System.exit(1);
225
      }
226
  }
227
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.