19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
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 |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
|
24 import java.rmi.NotBoundException; |
24 import java.rmi.RemoteException; |
25 import java.rmi.RemoteException; |
25 import java.rmi.registry.Registry; |
26 import java.rmi.registry.Registry; |
26 import java.rmi.registry.LocateRegistry; |
27 import java.rmi.registry.LocateRegistry; |
27 import java.util.logging.Logger; |
28 import java.util.logging.Logger; |
28 import java.util.logging.Level; |
29 import java.util.logging.Level; |
58 |
59 |
59 /* |
60 /* |
60 * On initialization, export remote objects and register |
61 * On initialization, export remote objects and register |
61 * them with server. |
62 * them with server. |
62 */ |
63 */ |
|
64 @Override |
63 public void run() { |
65 public void run() { |
64 try { |
66 try { |
65 int i = 0; |
67 int i = 0; |
66 |
68 |
67 /* |
69 /* |
68 * Locate apple user object in registry. The lookup will |
70 * Locate apple user object in registry. The lookup will occur |
69 * occur until it is successful or fails LOOKUP_ATTEMPTS times. |
71 * every 5 seconds until it is successful or timeout 50 seconds. |
70 * These repeated attempts allow the ApplicationServer |
72 * These repeated attempts allow the ApplicationServer |
71 * to be started before the AppleUserImpl. |
73 * to be started before the AppleUserImpl. |
72 */ |
74 */ |
73 Exception exc = null; |
75 Exception exc = null; |
74 for (i = 0; i < LOOKUP_ATTEMPTS; i++) { |
76 long stopTime = System.currentTimeMillis() + LOOKUP_ATTEMPTS * 10000; |
|
77 while (System.currentTimeMillis() < stopTime) { |
75 try { |
78 try { |
76 Registry registry = LocateRegistry.getRegistry( |
79 Registry registry = LocateRegistry.getRegistry( |
77 registryHost, registryPort); |
80 registryHost, registryPort); |
78 user = (AppleUser) registry.lookup("AppleUser"); |
81 user = (AppleUser) registry.lookup("AppleUser"); |
79 user.startTest(); |
82 user.startTest(); |
80 break; //successfully obtained AppleUser |
83 break; //successfully obtained AppleUser |
81 } catch (Exception e) { |
84 } catch (RemoteException | NotBoundException e) { |
82 exc = e; |
85 exc = e; |
83 Thread.sleep(10000); //sleep 10 seconds and try again |
86 Thread.sleep(5000); //sleep 5 seconds and try again |
84 } |
87 } |
85 } |
88 } |
86 if (user == null) { |
89 if (user == null) { |
87 logger.log(Level.SEVERE, "Failed to lookup AppleUser:", exc); |
90 logger.log(Level.SEVERE, "Failed to lookup AppleUser:", exc); |
88 return; |
91 return; |
111 } |
114 } |
112 } catch (RemoteException e) { |
115 } catch (RemoteException e) { |
113 logger.log(Level.SEVERE, |
116 logger.log(Level.SEVERE, |
114 "Failed to register callbacks for " + apples[i] + ":", e); |
117 "Failed to register callbacks for " + apples[i] + ":", e); |
115 user.reportException(e); |
118 user.reportException(e); |
116 return; |
|
117 } |
119 } |
118 } catch (Exception e) { |
120 } catch (InterruptedException | RemoteException e) { |
119 logger.log(Level.SEVERE, "Unexpected exception:", e); |
121 logger.log(Level.SEVERE, "Unexpected exception:", e); |
120 } |
122 } |
121 } |
123 } |
122 |
124 |
123 private static void usage() { |
125 private static void usage() { |
141 |
143 |
142 // parse command line args |
144 // parse command line args |
143 try { |
145 try { |
144 for (int i = 0; i < args.length ; i++ ) { |
146 for (int i = 0; i < args.length ; i++ ) { |
145 String arg = args[i]; |
147 String arg = args[i]; |
146 if (arg.equals("-numApples")) { |
148 switch (arg) { |
147 i++; |
149 case "-numApples": |
148 num = Integer.parseInt(args[i]); |
150 i++; |
149 } else if (arg.equals("-registryHost")) { |
151 num = Integer.parseInt(args[i]); |
150 i++; |
152 break; |
151 host = args[i]; |
153 case "-registryHost": |
152 } else if (arg.equals("-registryPort")) { |
154 i++; |
153 i++; |
155 host = args[i]; |
154 port = Integer.parseInt(args[i]); |
156 break; |
155 } else { |
157 case "-registryPort": |
156 usage(); |
158 i++; |
|
159 port = Integer.parseInt(args[i]); |
|
160 break; |
|
161 default: |
|
162 usage(); |
|
163 break; |
157 } |
164 } |
158 } |
165 } |
159 |
166 |
160 if (port == -1) { |
167 if (port == -1) { |
161 usage(); |
168 usage(); |