-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathClient.java
More file actions
161 lines (139 loc) · 5.16 KB
/
Client.java
File metadata and controls
161 lines (139 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
* v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License v2.0
* w/Classpath exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause OR GPL-2.0 WITH
* Classpath-exception-2.0
*/
//
// Created : 2003 Dec 11 (Thu) 11:03:27 by Harold Carr.
// Last Modified : 2003 Dec 18 (Thu) 11:34:37 by Harold Carr.
//
package corba.legacybootstrapserver;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import org.omg.CORBA.ORB;
import corba.framework.Controller;
public class Client
{
public static final String baseMsg = Client.class.getName();
public static final String main = baseMsg + ".main";
public static final String bootstrapFilename = "boostrapData";
public static final String orbInitialPort = "4444";
public static final String initialEntryName = "InitialEntry";
public static ORB orb;
public static void main(String av[])
{
try {
System.out.println(main + " starting");
System.out.println(main + " " + getBootstrapFilePathAndName());
/* This doesn't work in test framework. Bug 4970599
Properties props = new Properties();
props.setProperty(ORBConstants.INITIAL_PORT_PROPERTY, orbInitialPort);
*/
String[] args = { "-ORBInitialPort",
getORBInitialPort() };
orb = ORB.init(args, (Properties)null);
lookup(false, "foo");
org.omg.CORBA.Object o = lookup(true, initialEntryName);
update(true, "foo", o);
lookup(true, "foo");
// NOTE: without this wait the test fails.
// Wait a second before removing it so that
// the file modified time looks diferent to the server
// from the last update.
Thread.sleep(1000);
update(false, "foo", null);
lookup(false, "foo");
System.out.println(main + ": Test complete.");
} catch (Throwable t) {
System.out.println(main + ": unexpected exception: " + t);
t.printStackTrace(System.out);
System.exit(1);
}
System.out.println(main + ": PASSED");
System.exit(Controller.SUCCESS);
}
public static org.omg.CORBA.Object lookup(boolean shouldBeThere,
String name)
throws
Exception
{
String filename = getBootstrapFilePathAndName();
System.out.println(filename
+ " lookup("
+ (shouldBeThere ? "shouldFind" : "shouldNotFind") + ", "
+ name + ")");
org.omg.CORBA.Object o = null;
try {
o = orb.resolve_initial_references(name);
if (! shouldBeThere) {
throw new Exception("Should not have found: " + name);
}
// Use the reference to make sure it works.
o._non_existent();
o._is_a("foo");
} catch (org.omg.CORBA.ORBPackage.InvalidName e) {
if (shouldBeThere) {
throw e;
}
}
return o;
}
public static String getORBInitialPort()
{
return orbInitialPort;
}
public static String getBootstrapFilePathAndName()
{
return
//Options.getOutputDirectory()
System.getProperty("output.dir")
+ System.getProperty("file.separator")
+ Client.bootstrapFilename;
}
public static void update(boolean shouldAdd,
String name,
org.omg.CORBA.Object o)
throws
Exception
{
String filename = getBootstrapFilePathAndName();
System.out.println(filename
+ " update("
+ (shouldAdd ? "add" : "remove") + ", "
+ name + ", "
+ (o == null ? "null" : "IOR") + ")");
FileInputStream is = new FileInputStream(filename);
Properties props = new Properties();
props.load(is);
is.close();
if (shouldAdd) {
props.put(name, orb.object_to_string(o));
} else {
props.remove(name);
}
writeProperties(props, getBootstrapFilePathAndName());
}
public static void writeProperties(Properties props, String filename)
throws
Exception
{
FileOutputStream os = new FileOutputStream(filename);
props.store(os, null);
os.close();
}
}
// End of file.