61 /** |
61 /** |
62 * Deactivate an activated Activatable |
62 * Deactivate an activated Activatable |
63 */ |
63 */ |
64 public static void deactivate(Remote remote, |
64 public static void deactivate(Remote remote, |
65 ActivationID id) { |
65 ActivationID id) { |
66 for (int i = 0; i < 5; i ++) { |
66 // We do as much as 50 deactivation trials, each separated by |
|
67 // at least 100 milliseconds sleep time (max sleep time of 5 secs). |
|
68 final long deactivateSleepTime = 100; |
|
69 for (int i = 0; i < 50; i ++) { |
67 try { |
70 try { |
68 if (Activatable.inactive(id) == true) { |
71 if (Activatable.inactive(id) == true) { |
69 mesg("inactive successful"); |
72 mesg("inactive successful"); |
70 return; |
73 return; |
71 } else { |
74 } else { |
72 Thread.sleep(1000); |
75 mesg("inactive trial failed. Sleeping " + |
|
76 deactivateSleepTime + |
|
77 " milliseconds before next trial"); |
|
78 Thread.sleep(deactivateSleepTime); |
73 } |
79 } |
74 } catch (InterruptedException e) { |
80 } catch (InterruptedException e) { |
75 continue; |
81 Thread.currentThread().interrupt(); |
|
82 mesg("Thread interrupted while trying to deactivate activatable. Exiting deactivation"); |
|
83 return; |
76 } catch (Exception e) { |
84 } catch (Exception e) { |
77 try { |
85 try { |
78 // forcibly unexport the object |
86 // forcibly unexport the object |
|
87 mesg("Unexpected exception. Have to forcibly unexport the object." + |
|
88 " Exception was :"); |
|
89 e.printStackTrace(); |
79 Activatable.unexportObject(remote, true); |
90 Activatable.unexportObject(remote, true); |
80 } catch (NoSuchObjectException ex) { |
91 } catch (NoSuchObjectException ex) { |
81 } |
92 } |
82 return; |
93 return; |
83 } |
94 } |
97 * |
108 * |
98 * This method intentionally avoids performing a lookup on the |
109 * This method intentionally avoids performing a lookup on the |
99 * activation system. |
110 * activation system. |
100 */ |
111 */ |
101 public static boolean rmidRunning(int port) { |
112 public static boolean rmidRunning(int port) { |
102 int allowedNotReady = 10; |
113 int allowedNotReady = 50; |
103 int connectionRefusedExceptions = 0; |
114 int connectionRefusedExceptions = 0; |
104 |
115 |
105 for (int i = 0; i < 15 ; i++) { |
116 /* We wait as much as a total of 7.5 secs trying to see Rmid running. |
|
117 * We do this by pausing steps of 100 milliseconds (so up to 75 steps), |
|
118 * right after trying to lookup and find RMID running in the other vm. |
|
119 */ |
|
120 final long rmidWaitingStepTime = 100; |
|
121 for (int i = 0; i <= 74; i++) { |
106 |
122 |
107 try { |
123 try { |
108 Thread.sleep(500); |
|
109 LocateRegistry.getRegistry(port).lookup(SYSTEM_NAME); |
124 LocateRegistry.getRegistry(port).lookup(SYSTEM_NAME); |
|
125 mesg("Activation System available after " + |
|
126 (i * rmidWaitingStepTime) + " milliseconds"); |
110 return true; |
127 return true; |
111 |
128 |
112 } catch (java.rmi.ConnectException e) { |
129 } catch (java.rmi.ConnectException e) { |
|
130 mesg("Remote connection refused after " + |
|
131 (i * rmidWaitingStepTime) + " milliseconds"); |
|
132 |
113 // ignore connect exceptions until we decide rmid is not up |
133 // ignore connect exceptions until we decide rmid is not up |
114 |
|
115 if ((connectionRefusedExceptions ++) >= allowedNotReady) { |
134 if ((connectionRefusedExceptions ++) >= allowedNotReady) { |
116 return false; |
135 return false; |
117 } |
136 } |
118 |
137 |
|
138 } catch (java.rmi.NoSuchObjectException nsoe) { |
|
139 /* Activation System still unavailable. |
|
140 * Ignore this since we are just waiting for its availibility. |
|
141 * Just signal unavailibility. |
|
142 */ |
|
143 mesg("Activation System still unavailable after more than " + |
|
144 (i * rmidWaitingStepTime) + " milliseconds"); |
|
145 |
119 } catch (NotBoundException e) { |
146 } catch (NotBoundException e) { |
120 |
|
121 return false; |
147 return false; |
122 |
148 |
123 } catch (Exception e) { |
149 } catch (Exception e) { |
124 // print out other types of exceptions as an FYI. |
150 /* print out other types of exceptions as an FYI. |
125 // test should not fail as rmid is likely to be in an |
151 * test should not fail as rmid is likely to be in an |
126 // undetermined state at this point. |
152 * undetermined state at this point. |
127 |
153 */ |
128 mesg("caught an exception trying to" + |
154 mesg("caught an exception trying to" + |
129 " start rmid, last exception was: " + |
155 " start rmid, last exception was: " + |
130 e.getMessage()); |
156 e.getMessage()); |
131 e.printStackTrace(); |
157 e.printStackTrace(); |
|
158 } |
|
159 |
|
160 // Waiting for another 100 milliseconds. |
|
161 try { |
|
162 Thread.sleep(100); |
|
163 } catch (InterruptedException e) { |
|
164 Thread.currentThread().interrupt(); |
|
165 mesg("Thread interrupted while checking if Activation System is running. Exiting check"); |
|
166 return false; |
132 } |
167 } |
133 } |
168 } |
134 return false; |
169 return false; |
135 } |
170 } |
136 |
171 |