1 /*
2 * Copyright (c) 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.rmi.RemoteException;
25 import java.rmi.Naming;
26 import java.rmi.server.UnicastRemoteObject;
27 import java.rmi.registry.LocateRegistry;
28 import java.util.Random;
29 import java.util.ArrayList;
30 import java.util.Date;
31 import java.util.logging.Logger;
32 import java.util.logging.Level;
33
34 /**
35 * The AppleUserImpl class implements the behavior of the remote
36 * "apple user" objects exported by the server. The application server
37 * passes each of its remote "apple" objects to an apple user, and an
38 * AppleUserThread is created for each apple.
39 */
40 public class AppleUserImpl
41 extends UnicastRemoteObject
42 implements AppleUser
43 {
44 private static Logger logger = Logger.getLogger("reliability.appleuser");
45 private static int threadNum = 0;
46 private static long testDuration = 0;
47 private static int maxLevel = 7;
232 maxLevel = Integer.parseInt(args[i]);
233 } else {
234 usage();
235 }
236 }
237 if (durationString == null) {
238 durationString = testDuration + " milliseconds";
239 }
240 } catch (Throwable t) {
241 usage();
242 }
243
244 AppleUserImpl user = null;
245 try {
246 user = new AppleUserImpl();
247 } catch (RemoteException e) {
248 //TestLibrary.bomb("Failed to create AppleUser", e);
249 }
250
251 synchronized (user) {
252 // create new registry and bind new AppleUserImpl in registry
253 try {
254 LocateRegistry.createRegistry(1099); //TestLibrary.REGISTRY_PORT);
255 Naming.rebind("rmi://localhost:1099/AppleUser",user);
256 //TestLibrary.REGISTRY_PORT + "/AppleUser", user);
257 } catch (RemoteException e) {
258 //TestLibrary.bomb("Failed to bind AppleUser", e);
259 } catch (java.net.MalformedURLException e) {
260 //TestLibrary.bomb("Failed to bind AppleUser", e);
261 }
262
263 // start the other server if available
264 try {
265 Class app = Class.forName("ApplicationServer");
266 server = new Thread((Runnable) app.newInstance());
267 logger.log(Level.INFO, "Starting application server " +
268 "in same process");
269 server.start();
270 } catch (ClassNotFoundException e) {
271 // assume the other server is running in a separate process
272 logger.log(Level.INFO, "Application server must be " +
273 "started in separate process");
274 } catch (Exception ie) {
275 //TestLibrary.bomb("Could not instantiate server", ie);
276 }
277
278 // wait for other server to call startTest method
279 try {
280 logger.log(Level.INFO, "Waiting for application server " +
281 "process to start");
282 user.wait();
283 } catch (InterruptedException ie) {
284 //TestLibrary.bomb("AppleUserImpl interrupted", ie);
285 }
286 }
287
288 startTime = System.currentTimeMillis();
289 logger.log(Level.INFO, "Test starting");
|
1 /*
2 * Copyright (c) 2003, 2012, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.rmi.RemoteException;
25 import java.rmi.Naming;
26 import java.rmi.server.UnicastRemoteObject;
27 import java.rmi.registry.LocateRegistry;
28 import java.rmi.registry.Registry;
29 import java.util.Random;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.logging.Logger;
33 import java.util.logging.Level;
34
35 /**
36 * The AppleUserImpl class implements the behavior of the remote
37 * "apple user" objects exported by the server. The application server
38 * passes each of its remote "apple" objects to an apple user, and an
39 * AppleUserThread is created for each apple.
40 */
41 public class AppleUserImpl
42 extends UnicastRemoteObject
43 implements AppleUser
44 {
45 private static Logger logger = Logger.getLogger("reliability.appleuser");
46 private static int threadNum = 0;
47 private static long testDuration = 0;
48 private static int maxLevel = 7;
233 maxLevel = Integer.parseInt(args[i]);
234 } else {
235 usage();
236 }
237 }
238 if (durationString == null) {
239 durationString = testDuration + " milliseconds";
240 }
241 } catch (Throwable t) {
242 usage();
243 }
244
245 AppleUserImpl user = null;
246 try {
247 user = new AppleUserImpl();
248 } catch (RemoteException e) {
249 //TestLibrary.bomb("Failed to create AppleUser", e);
250 }
251
252 synchronized (user) {
253 int port = -1;
254 // create new registry and bind new AppleUserImpl in registry
255 try {
256 Registry registry = TestLibrary.createRegistryOnUnusedPort();
257 port = TestLibrary.getRegistryPort(registry);
258 Naming.rebind("rmi://localhost:" + port + "/AppleUser",user);
259 } catch (RemoteException e) {
260 //TestLibrary.bomb("Failed to bind AppleUser", e);
261 } catch (java.net.MalformedURLException e) {
262 //TestLibrary.bomb("Failed to bind AppleUser", e);
263 }
264
265 // start the other server if available
266 try {
267 Class app = Class.forName("ApplicationServer");
268 java.lang.reflect.Constructor appConstructor =
269 app.getDeclaredConstructor(new Class[] {Integer.TYPE});
270 server = new Thread((Runnable) appConstructor.newInstance(port));
271 } catch (ClassNotFoundException e) {
272 // assume the other server is running in a separate process
273 logger.log(Level.INFO, "Application server must be " +
274 "started in separate process");
275 } catch (Exception ie) {
276 //TestLibrary.bomb("Could not instantiate server", ie);
277 }
278
279 // wait for other server to call startTest method
280 try {
281 logger.log(Level.INFO, "Waiting for application server " +
282 "process to start");
283 user.wait();
284 } catch (InterruptedException ie) {
285 //TestLibrary.bomb("AppleUserImpl interrupted", ie);
286 }
287 }
288
289 startTime = System.currentTimeMillis();
290 logger.log(Level.INFO, "Test starting");
|