38 |
|
|
39 |
package gnu.CORBA.Poa; |
package gnu.CORBA.Poa; |
40 |
|
|
41 |
|
import gnu.CORBA.GIOP.ReplyHeader; |
42 |
import gnu.CORBA.IOR_Delegate; |
import gnu.CORBA.IOR_Delegate; |
43 |
import gnu.CORBA.IOR_contructed_object; |
import gnu.CORBA.IOR_contructed_object; |
44 |
|
import gnu.CORBA.Interceptor.gnuServerRequestInfo; |
45 |
|
import gnu.CORBA.ObjectCreator; |
46 |
|
import gnu.CORBA.Unexpected; |
47 |
|
import gnu.CORBA.bufferedResponseHandler; |
48 |
|
import gnu.CORBA.recordTypeCode; |
49 |
|
import gnu.CORBA.streamReadyHolder; |
50 |
|
|
51 |
|
import org.omg.CORBA.Any; |
52 |
import org.omg.CORBA.BAD_OPERATION; |
import org.omg.CORBA.BAD_OPERATION; |
53 |
import org.omg.CORBA.BAD_PARAM; |
import org.omg.CORBA.BAD_PARAM; |
54 |
import org.omg.CORBA.CompletionStatus; |
import org.omg.CORBA.CompletionStatus; |
56 |
import org.omg.CORBA.OBJ_ADAPTER; |
import org.omg.CORBA.OBJ_ADAPTER; |
57 |
import org.omg.CORBA.ORB; |
import org.omg.CORBA.ORB; |
58 |
import org.omg.CORBA.SystemException; |
import org.omg.CORBA.SystemException; |
59 |
|
import org.omg.CORBA.TCKind; |
60 |
import org.omg.CORBA.TRANSIENT; |
import org.omg.CORBA.TRANSIENT; |
61 |
|
import org.omg.CORBA.UserException; |
62 |
import org.omg.CORBA.portable.InputStream; |
import org.omg.CORBA.portable.InputStream; |
63 |
import org.omg.CORBA.portable.InvokeHandler; |
import org.omg.CORBA.portable.InvokeHandler; |
64 |
import org.omg.CORBA.portable.ObjectImpl; |
import org.omg.CORBA.portable.ObjectImpl; |
65 |
import org.omg.CORBA.portable.OutputStream; |
import org.omg.CORBA.portable.OutputStream; |
66 |
import org.omg.CORBA.portable.ResponseHandler; |
import org.omg.CORBA.portable.ResponseHandler; |
67 |
|
import org.omg.PortableInterceptor.ForwardRequest; |
68 |
|
import org.omg.PortableInterceptor.ServerRequestInterceptorOperations; |
69 |
import org.omg.PortableServer.CurrentOperations; |
import org.omg.PortableServer.CurrentOperations; |
70 |
import org.omg.PortableServer.DynamicImplementation; |
import org.omg.PortableServer.DynamicImplementation; |
|
import org.omg.PortableServer.ForwardRequest; |
|
71 |
import org.omg.PortableServer.ImplicitActivationPolicyValue; |
import org.omg.PortableServer.ImplicitActivationPolicyValue; |
72 |
import org.omg.PortableServer.POA; |
import org.omg.PortableServer.POA; |
73 |
import org.omg.PortableServer.POAManager; |
import org.omg.PortableServer.POAManager; |
77 |
import org.omg.PortableServer.ServantRetentionPolicyValue; |
import org.omg.PortableServer.ServantRetentionPolicyValue; |
78 |
import org.omg.PortableServer.portable.Delegate; |
import org.omg.PortableServer.portable.Delegate; |
79 |
|
|
80 |
|
import java.io.IOException; |
81 |
|
|
82 |
import java.util.Arrays; |
import java.util.Arrays; |
83 |
|
|
84 |
/** |
/** |
85 |
* Represents a CORBA object, being locally served by the associated |
* Represents a CORBA object, being locally served by the associated servant. |
86 |
* servant. The calls to the object are forwarded to the calls to the |
* The calls to the object are forwarded to the calls to the servant. |
|
* servant. |
|
87 |
* |
* |
88 |
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) |
* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) |
89 |
*/ |
*/ |
90 |
public class gnuServantObject |
public class gnuServantObject extends ObjectImpl |
91 |
extends ObjectImpl |
implements org.omg.CORBA.Object, |
92 |
implements org.omg.CORBA.Object, InvokeHandler, CurrentOperations |
InvokeHandler, |
93 |
|
CurrentOperations |
94 |
{ |
{ |
95 |
/** |
/** |
96 |
* The associated servant that must also implement the |
* The associated servant that must also implement the {@link InvokeHandler} |
97 |
* {@link InvokeHandler} interface. This value can be temporary |
* interface. This value can be temporary null if the object was created using |
|
* null if the object was created using |
|
98 |
* POA.create_reference or POA.create_reference_with_id, private to force |
* POA.create_reference or POA.create_reference_with_id, private to force |
99 |
* always to use {@link setServant}. |
* always to use {@link setServant}. |
100 |
*/ |
*/ |
121 |
public final ORB_1_4 orb; |
public final ORB_1_4 orb; |
122 |
|
|
123 |
/** |
/** |
124 |
* The object repository ids, if they were specified separately. |
* The object repository ids, if they were specified separately. Normally, the |
125 |
* Normally, the ids are requested from the servant. |
* ids are requested from the servant. |
126 |
*/ |
*/ |
127 |
public final String[] repository_ids; |
public final String[] repository_ids; |
128 |
|
|
129 |
/** |
/** |
130 |
* Create an object with no connected servant. The servant must be |
* Create an object with no connected servant. The servant must be set later. |
|
* set later. |
|
131 |
* |
* |
132 |
* @param a_repository_ids an array of repository ids, can be null |
* @param a_repository_ids an array of repository ids, can be null (then ids |
133 |
* (then ids will be requested from the servant). |
* will be requested from the servant). |
134 |
* @param an_id the object id. |
* @param an_id the object id. |
135 |
* @param a_poa the POA. |
* @param a_poa the POA. |
136 |
*/ |
*/ |
137 |
public gnuServantObject(String[] a_repository_ids, byte[] an_id, |
public gnuServantObject(String[] a_repository_ids, byte[] an_id, |
138 |
gnuPOA a_poa, ORB_1_4 an_orb |
gnuPOA a_poa, ORB_1_4 an_orb |
139 |
) |
) |
140 |
{ |
{ |
141 |
repository_ids = a_repository_ids; |
repository_ids = a_repository_ids; |
142 |
Id = an_id; |
Id = an_id; |
151 |
* @param a_servant a servant, serving this object. |
* @param a_servant a servant, serving this object. |
152 |
* @param an_id an Object Id for this object. |
* @param an_id an Object Id for this object. |
153 |
* |
* |
154 |
* @throws BAD_PARAM if the passed servant is not an |
* @throws BAD_PARAM if the passed servant is not an {@link InvokeHandler}. |
|
* {@link InvokeHandler}. |
|
155 |
*/ |
*/ |
156 |
public gnuServantObject(Servant a_servant, byte[] an_id, ORB_1_4 an_orb, |
public gnuServantObject(Servant a_servant, byte[] an_id, ORB_1_4 an_orb, |
157 |
gnuPOA a_poa |
gnuPOA a_poa |
158 |
) |
) |
159 |
{ |
{ |
160 |
Id = an_id; |
Id = an_id; |
161 |
setServant(a_servant); |
setServant(a_servant); |
162 |
poa = a_poa; |
poa = a_poa; |
163 |
if (poa != null) |
if (poa != null) |
164 |
manager = poa.the_POAManager(); |
{ |
165 |
|
manager = poa.the_POAManager(); |
166 |
|
} |
167 |
else |
else |
168 |
manager = null; |
{ |
169 |
|
manager = null; |
170 |
|
} |
171 |
repository_ids = null; |
repository_ids = null; |
172 |
orb = an_orb; |
orb = an_orb; |
173 |
} |
} |
175 |
/** |
/** |
176 |
* Set a servant, if it has not been previously set. |
* Set a servant, if it has not been previously set. |
177 |
* |
* |
178 |
* @param a_servant a servant to set, can be null to indicate |
* @param a_servant a servant to set, can be null to indicate the necessity |
179 |
* the necessity for the subsequent activation. |
* for the subsequent activation. |
180 |
* |
* |
181 |
* @throws BAD_PARAM if the passed servant is not an |
* @throws BAD_PARAM if the passed servant is not an {@link InvokeHandler} or |
182 |
* {@link InvokeHandler} or {@link DynamicImplementation} and also |
* {@link DynamicImplementation} and also not null. |
|
* not null. |
|
183 |
*/ |
*/ |
184 |
public void setServant(Servant a_servant) |
public void setServant(Servant a_servant) |
185 |
{ |
{ |
186 |
if (a_servant != null && !(a_servant instanceof InvokeHandler) && |
if (a_servant != null && |
187 |
!(a_servant instanceof DynamicImplementation) |
!(a_servant instanceof InvokeHandler) && |
188 |
) |
!(a_servant instanceof DynamicImplementation) |
189 |
|
) |
190 |
throw new BAD_PARAM("Must be either InvokeHandler or " + |
{ |
191 |
"DynamicImplementation, but is " + a_servant |
throw new BAD_PARAM("Must be either InvokeHandler or " + |
192 |
); |
"DynamicImplementation, but is " + a_servant |
193 |
|
); |
194 |
|
} |
195 |
servant = a_servant; |
servant = a_servant; |
196 |
} |
} |
197 |
|
|
207 |
* Return the associated invocation handler. |
* Return the associated invocation handler. |
208 |
*/ |
*/ |
209 |
public InvokeHandler getHandler(String operation, CookieHolder cookie, |
public InvokeHandler getHandler(String operation, CookieHolder cookie, |
210 |
boolean forwarding_allowed |
boolean forwarding_allowed |
211 |
) |
) throws gnuForwardRequest |
|
throws gnuForwardRequest |
|
212 |
{ |
{ |
213 |
if (servant != null) |
if (servant != null) |
214 |
return servantToHandler(servant); |
{ |
215 |
|
return servantToHandler(servant); |
216 |
|
} |
217 |
else |
else |
218 |
{ |
{ |
219 |
// Use servant locator to locate the servant. |
// Use servant locator to locate the servant. |
225 |
poa.servant_locator.preinvoke(Id, poa, operation, cookie); |
poa.servant_locator.preinvoke(Id, poa, operation, cookie); |
226 |
return servantToHandler(servant); |
return servantToHandler(servant); |
227 |
} |
} |
228 |
catch (ForwardRequest forw_ex) |
catch (org.omg.PortableServer.ForwardRequest forw_ex) |
229 |
{ |
{ |
230 |
if (forwarding_allowed) |
if (forwarding_allowed) |
231 |
throw new gnuForwardRequest(forw_ex.forward_reference); |
{ |
232 |
|
throw new gnuForwardRequest(forw_ex.forward_reference); |
233 |
|
} |
234 |
else |
else |
235 |
{ |
{ |
236 |
servant = |
servant = |
242 |
else |
else |
243 |
// Use servant activator to locate the servant. |
// Use servant activator to locate the servant. |
244 |
if (poa.applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) && |
if (poa.applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) && |
245 |
poa.applies(ServantRetentionPolicyValue.RETAIN) |
poa.applies(ServantRetentionPolicyValue.RETAIN) |
246 |
) |
) |
247 |
{ |
{ |
248 |
try |
try |
249 |
{ |
{ |
261 |
|
|
262 |
BAD_OPERATION bad = |
BAD_OPERATION bad = |
263 |
new BAD_OPERATION("Unable to activate", 0x5004, |
new BAD_OPERATION("Unable to activate", 0x5004, |
264 |
CompletionStatus.COMPLETED_NO |
CompletionStatus.COMPLETED_NO |
265 |
); |
); |
266 |
bad.initCause(ex); |
bad.initCause(ex); |
267 |
throw bad; |
throw bad; |
268 |
} |
} |
275 |
|
|
276 |
// No servant and no servant manager - throw exception. |
// No servant and no servant manager - throw exception. |
277 |
else |
else |
278 |
throw new BAD_OPERATION("Unable to activate", 0x5002, |
{ |
279 |
CompletionStatus.COMPLETED_NO |
throw new BAD_OPERATION("Unable to activate", 0x5002, |
280 |
); |
CompletionStatus.COMPLETED_NO |
281 |
|
); |
282 |
|
} |
283 |
} |
} |
284 |
} |
} |
285 |
|
|
286 |
/** |
/** |
287 |
* Convert the servant to invocation handler. |
* Convert the servant to invocation handler. |
288 |
*/ |
*/ |
289 |
public InvokeHandler servantToHandler(Servant servant) |
public InvokeHandler servantToHandler(Servant a_servant) |
290 |
{ |
{ |
291 |
if (servant instanceof InvokeHandler) |
if (a_servant instanceof InvokeHandler) |
292 |
return (InvokeHandler) servant; |
{ |
293 |
else if (servant instanceof DynamicImplementation) |
return (InvokeHandler) a_servant; |
294 |
return new dynImpHandler((DynamicImplementation) servant); |
} |
295 |
|
else if (a_servant instanceof DynamicImplementation) |
296 |
|
{ |
297 |
|
return new dynImpHandler((DynamicImplementation) a_servant); |
298 |
|
} |
299 |
else |
else |
300 |
throw new BAD_OPERATION(servant + " must be either InvokeHandler or " + |
{ |
301 |
"POA DynamicImplementation" |
throw new BAD_OPERATION(a_servant + |
302 |
); |
" must be either InvokeHandler or " + "POA DynamicImplementation" |
303 |
|
); |
304 |
|
} |
305 |
} |
} |
306 |
|
|
307 |
/** |
/** |
308 |
* Create a servant object, associated with the passed servant. |
* Create a servant object, associated with the passed servant. Requests the |
309 |
* Requests the object id from the servant. Depending on the |
* object id from the servant. Depending on the policies of the servants POA, |
310 |
* policies of the servants POA, the calls are eithe not |
* the calls are eithe not synchronized or synchronized on POA or ORB. |
|
* synchronized or synchronized on POA or ORB. |
|
311 |
* |
* |
312 |
* @param a_servant a servant, serving this object. |
* @param a_servant a servant, serving this object. |
313 |
* @param an_id an Object Id for this object. |
* @param an_id an Object Id for this object. |
314 |
*/ |
*/ |
315 |
public gnuServantObject(Servant a_servant, gnuPOA poa) |
public gnuServantObject(Servant a_servant, gnuPOA a_poa) |
316 |
{ |
{ |
317 |
this(a_servant, a_servant._object_id(), (ORB_1_4) a_servant._orb(), poa); |
this(a_servant, a_servant._object_id(), (ORB_1_4) a_servant._orb(), a_poa); |
318 |
} |
} |
319 |
|
|
320 |
/** |
/** |
323 |
public String[] _ids() |
public String[] _ids() |
324 |
{ |
{ |
325 |
if (repository_ids == null) |
if (repository_ids == null) |
326 |
return getServant()._all_interfaces(poa, Id); |
{ |
327 |
|
return getServant()._all_interfaces(poa, Id); |
328 |
|
} |
329 |
else |
else |
330 |
return repository_ids; |
{ |
331 |
|
return repository_ids; |
332 |
|
} |
333 |
} |
} |
334 |
|
|
335 |
/** |
/** |
357 |
|
|
358 |
/** |
/** |
359 |
* Check if this object could be named by the given repository id. |
* Check if this object could be named by the given repository id. |
360 |
|
* |
361 |
* @param idl_id the repository id to check. |
* @param idl_id the repository id to check. |
362 |
* |
* |
363 |
* @return true if it is one of the possible repository ids of this |
* @return true if it is one of the possible repository ids of this object. |
|
* object. |
|
364 |
*/ |
*/ |
365 |
public boolean _is_a(String idl_id) |
public boolean _is_a(String idl_id) |
366 |
{ |
{ |
368 |
for (int i = 0; i < maybe.length; i++) |
for (int i = 0; i < maybe.length; i++) |
369 |
{ |
{ |
370 |
if (maybe [ i ].equals(idl_id)) |
if (maybe [ i ].equals(idl_id)) |
371 |
return true; |
{ |
372 |
|
return true; |
373 |
|
} |
374 |
} |
} |
375 |
return false; |
return false; |
376 |
} |
} |
377 |
|
|
378 |
/** |
/** |
379 |
* Get an ORB, associated with the servant of this object. |
* Get an ORB, associated with the servant of this object. |
380 |
|
* |
381 |
* @return |
* @return |
382 |
*/ |
*/ |
383 |
public ORB _orb() |
public ORB _orb() |
390 |
* |
* |
391 |
* @throws TRANSIENT minor 0x535503e9 if the POA is in discarding mode. |
* @throws TRANSIENT minor 0x535503e9 if the POA is in discarding mode. |
392 |
* @throws OBJ_ADAPTER minor 0x535503ea if the POA is inactivated. |
* @throws OBJ_ADAPTER minor 0x535503ea if the POA is inactivated. |
393 |
* @throws OBJECT_NOT_EXISTS minor 0x535503ec if this object is |
* @throws OBJECT_NOT_EXISTS minor 0x535503ec if this object is inactivated. |
|
* inactivated. |
|
394 |
* |
* |
395 |
* @specnote see {@link POAManagerOperations} for specnotes about |
* @specnote see {@link POAManagerOperations} for specnotes about the minor |
396 |
* the minor codes. |
* codes. |
397 |
*/ |
*/ |
398 |
public OutputStream _invoke(String method, InputStream input, |
public OutputStream _invoke(String method, InputStream input, |
399 |
ResponseHandler r_handler |
ResponseHandler r_handler |
400 |
) |
) throws SystemException |
|
throws SystemException |
|
401 |
{ |
{ |
402 |
|
boolean intercept = false; |
403 |
|
ServerRequestInterceptorOperations interceptor = null; |
404 |
|
gnuServerRequestInfo info = null; |
405 |
|
bufferedResponseHandler i_handler = null; |
406 |
|
|
407 |
try |
try |
408 |
{ |
{ |
409 |
CookieHolder cookie = null; |
if (orb.iServer != null && |
410 |
activeObjectMap.Obj self = poa.aom.get(Id); |
r_handler instanceof bufferedResponseHandler |
411 |
|
) |
|
if (poa.servant_locator != null) |
|
412 |
{ |
{ |
413 |
// If the servant locator is in use, it is always responsible |
interceptor = orb.iServer; |
|
// for providing the servant. |
|
|
self.servant = servant = null; |
|
|
cookie = new CookieHolder(); |
|
|
} |
|
|
else if (self != null && self.isDeactiveted()) |
|
|
{ |
|
|
if (poa.applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) && |
|
|
poa.servant_activator != null |
|
|
) |
|
|
{ |
|
|
// Reset the servant, forcing the subsequent activation. |
|
|
servant = null; |
|
|
} |
|
|
else |
|
|
throw new OBJECT_NOT_EXIST("Object deactivated", 0x535503ec, |
|
|
CompletionStatus.COMPLETED_NO |
|
|
); |
|
|
} |
|
414 |
|
|
415 |
InvokeHandler handler = getHandler(method, cookie, true); |
i_handler = (bufferedResponseHandler) r_handler; |
416 |
|
|
417 |
Delegate d = null; |
info = |
418 |
|
new gnuServerRequestInfo(this, i_handler.request_header, |
419 |
|
i_handler.reply_header |
420 |
|
); |
421 |
|
intercept = true; |
422 |
|
|
423 |
try |
interceptor.receive_request_service_contexts(info); |
|
{ |
|
|
d = servant._get_delegate(); |
|
|
orb.currents.put(Thread.currentThread(), this); |
|
|
} |
|
|
catch (Exception ex) |
|
|
{ |
|
|
// In some cases exception is thrown if the delegate is not set. |
|
|
} |
|
|
if (d instanceof servantDelegate) |
|
|
{ |
|
|
// If the delegate is already set, check maybe we can |
|
|
// reuse the existing instance. |
|
|
if (((servantDelegate) d).object != this) |
|
|
servant._set_delegate(new servantDelegate(servant, poa, Id)); |
|
|
} |
|
|
else |
|
|
{ |
|
|
servant._set_delegate(new servantDelegate(servant, poa, Id)); |
|
424 |
} |
} |
425 |
|
|
426 |
try |
try |
427 |
{ |
{ |
428 |
switch (manager.get_state().value()) |
CookieHolder cookie = null; |
429 |
|
activeObjectMap.Obj self = poa.aom.get(Id); |
430 |
|
|
431 |
|
if (poa.servant_locator != null) |
432 |
|
{ |
433 |
|
// If the servant locator is in use, it is always responsible |
434 |
|
// for providing the servant. |
435 |
|
self.servant = servant = null; |
436 |
|
cookie = new CookieHolder(); |
437 |
|
} |
438 |
|
else if (self != null && self.isDeactiveted()) |
439 |
|
{ |
440 |
|
if (poa.applies( |
441 |
|
ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION |
442 |
|
) && |
443 |
|
poa.servant_activator != null |
444 |
|
) |
445 |
|
{ |
446 |
|
// Reset the servant, forcing the subsequent activation. |
447 |
|
servant = null; |
448 |
|
} |
449 |
|
else |
450 |
|
{ |
451 |
|
throw new OBJECT_NOT_EXIST("Object deactivated", |
452 |
|
0x535503ec, CompletionStatus.COMPLETED_NO |
453 |
|
); |
454 |
|
} |
455 |
|
} |
456 |
|
|
457 |
|
InvokeHandler handler = getHandler(method, cookie, true); |
458 |
|
|
459 |
|
Delegate d = null; |
460 |
|
|
461 |
|
try |
462 |
|
{ |
463 |
|
d = servant._get_delegate(); |
464 |
|
orb.currents.put(Thread.currentThread(), this); |
465 |
|
} |
466 |
|
catch (Exception ex) |
467 |
|
{ |
468 |
|
// In some cases exception is thrown if the delegate is not set. |
469 |
|
} |
470 |
|
if (d instanceof servantDelegate) |
471 |
|
{ |
472 |
|
// If the delegate is already set, check maybe we can |
473 |
|
// reuse the existing instance. |
474 |
|
if (((servantDelegate) d).object != this) |
475 |
|
{ |
476 |
|
servant._set_delegate(new servantDelegate(servant, poa, Id)); |
477 |
|
} |
478 |
|
} |
479 |
|
else |
480 |
{ |
{ |
481 |
case State._ACTIVE : |
servant._set_delegate(new servantDelegate(servant, poa, Id)); |
482 |
return handler._invoke(method, input, r_handler); |
} |
483 |
|
|
484 |
case State._HOLDING : |
try |
485 |
|
{ |
486 |
|
switch (manager.get_state().value()) |
487 |
|
{ |
488 |
|
case State._ACTIVE : |
489 |
|
|
490 |
// The holding mode is implemented |
OutputStream rt; |
|
// relying on the holding capabilites of the network |
|
|
// support (if any). |
|
|
// TODO FIXME in more recent CORBA applications, the client |
|
|
// ORB can free the connection and wait for a server side |
|
|
// notification about the completed request. Implement this. |
|
|
int sleep = 5; |
|
|
int max = 500; |
|
|
|
|
|
// Wait till the state will be switched into some other |
|
|
// mode. |
|
|
while (manager.get_state().value() == State._HOLDING) |
|
|
{ |
|
491 |
try |
try |
492 |
{ |
{ |
493 |
Thread.sleep(sleep); |
if (intercept) |
494 |
if (sleep < max) |
{ |
495 |
sleep = max; |
interceptor.receive_request(info); |
496 |
|
} |
497 |
|
|
498 |
|
rt = handler._invoke(method, input, r_handler); |
499 |
|
|
500 |
|
if (intercept) |
501 |
|
{ |
502 |
|
// Handler is casted into i_handler. |
503 |
|
if (i_handler.isExceptionReply()) |
504 |
|
{ |
505 |
|
info.m_reply_header.reply_status = |
506 |
|
ReplyHeader.USER_EXCEPTION; |
507 |
|
|
508 |
|
// Make Any, holding the user exception. |
509 |
|
Any a = orb.create_any(); |
510 |
|
OutputStream buf = i_handler.getBuffer(); |
511 |
|
InputStream in = buf.create_input_stream(); |
512 |
|
String uex_idl = "unknown"; |
513 |
|
try |
514 |
|
{ |
515 |
|
in.mark(Integer.MAX_VALUE); |
516 |
|
uex_idl = in.read_string(); |
517 |
|
in.reset(); |
518 |
|
} |
519 |
|
catch (IOException e) |
520 |
|
{ |
521 |
|
throw new Unexpected(e); |
522 |
|
} |
523 |
|
|
524 |
|
try |
525 |
|
{ |
526 |
|
UserException exception = |
527 |
|
ObjectCreator.readUserException(uex_idl, |
528 |
|
in |
529 |
|
); |
530 |
|
|
531 |
|
ObjectCreator.insertWithHelper(a, |
532 |
|
exception |
533 |
|
); |
534 |
|
} |
535 |
|
catch (Exception e) |
536 |
|
{ |
537 |
|
// Failed due any reason, insert without |
538 |
|
// helper. |
539 |
|
a.insert_Streamable(new streamReadyHolder( |
540 |
|
buf.create_input_stream() |
541 |
|
) |
542 |
|
); |
543 |
|
|
544 |
|
recordTypeCode r = |
545 |
|
new recordTypeCode(TCKind.tk_except); |
546 |
|
r.setId(uex_idl); |
547 |
|
r.setName(ObjectCreator.getDefaultName( |
548 |
|
uex_idl |
549 |
|
) |
550 |
|
); |
551 |
|
} |
552 |
|
|
553 |
|
info.m_usr_exception = a; |
554 |
|
interceptor.send_exception(info); |
555 |
|
} |
556 |
|
else |
557 |
|
{ |
558 |
|
info.m_reply_header.reply_status = |
559 |
|
ReplyHeader.NO_EXCEPTION; |
560 |
|
interceptor.send_reply(info); |
561 |
|
} |
562 |
|
} |
563 |
|
} |
564 |
|
catch (SystemException sys_ex) |
565 |
|
{ |
566 |
|
if (intercept) |
567 |
|
{ |
568 |
|
info.m_reply_header.reply_status = |
569 |
|
ReplyHeader.SYSTEM_EXCEPTION; |
570 |
|
info.m_sys_exception = sys_ex; |
571 |
|
interceptor.send_exception(info); |
572 |
|
} |
573 |
|
throw sys_ex; |
574 |
} |
} |
575 |
catch (InterruptedException ex) |
|
576 |
|
return rt; |
577 |
|
|
578 |
|
case State._HOLDING : |
579 |
|
|
580 |
|
// The holding mode is implemented |
581 |
|
// relying on the holding capabilites of the network |
582 |
|
// support (if any). |
583 |
|
// TODO FIXME in more recent CORBA applications, the |
584 |
|
// client |
585 |
|
// ORB can free the connection and wait for a server side |
586 |
|
// notification about the completed request. Implement |
587 |
|
// this |
588 |
|
// as soon as JDK specification would allow bidirectional |
589 |
|
// policy. |
590 |
|
int sleep = 5; |
591 |
|
int max = 500; |
592 |
|
|
593 |
|
// Wait till the state will be switched into some other |
594 |
|
// mode. |
595 |
|
while (manager.get_state().value() == State._HOLDING) |
596 |
{ |
{ |
597 |
|
try |
598 |
|
{ |
599 |
|
Thread.sleep(sleep); |
600 |
|
if (sleep < max) |
601 |
|
{ |
602 |
|
sleep = max; |
603 |
|
} |
604 |
|
} |
605 |
|
catch (InterruptedException ex) |
606 |
|
{ |
607 |
|
} |
608 |
} |
} |
|
} |
|
609 |
|
|
610 |
// Handle another mode. |
// Handle another mode. |
611 |
return _invoke(method, input, r_handler); |
return _invoke(method, input, r_handler); |
612 |
|
|
613 |
case State._DISCARDING : |
case State._DISCARDING : |
614 |
throw new TRANSIENT("Discarding mode", 0x535503e9, |
throw new TRANSIENT("Discarding mode", 0x535503e9, |
615 |
CompletionStatus.COMPLETED_NO |
CompletionStatus.COMPLETED_NO |
616 |
); |
); |
617 |
|
|
618 |
case State._INACTIVE : |
case State._INACTIVE : |
619 |
throw new OBJ_ADAPTER("POA deactivated", 0x535503ea, |
throw new OBJ_ADAPTER("POA deactivated", 0x535503ea, |
620 |
CompletionStatus.COMPLETED_NO |
CompletionStatus.COMPLETED_NO |
621 |
); |
); |
622 |
|
|
623 |
default : |
default : |
624 |
throw new InternalError(); // No more states. |
throw new InternalError(); // No more states. |
625 |
|
} |
626 |
|
} |
627 |
|
finally |
628 |
|
{ |
629 |
|
if (poa.servant_locator != null) |
630 |
|
{ |
631 |
|
poa.servant_locator.postinvoke(Id, poa, method, |
632 |
|
cookie.value, servant |
633 |
|
); |
634 |
|
servant = null; |
635 |
|
} |
636 |
} |
} |
637 |
} |
} |
638 |
finally |
finally |
639 |
{ |
{ |
640 |
if (poa.servant_locator != null) |
orb.currents.remove(Thread.currentThread()); |
641 |
|
} |
642 |
|
} |
643 |
|
catch (ForwardRequest fex) |
644 |
|
{ |
645 |
|
// May be thrown by interceptor. |
646 |
|
if (intercept) |
647 |
|
{ |
648 |
|
Forwarding: |
649 |
|
while (true) |
650 |
{ |
{ |
651 |
poa.servant_locator.postinvoke(Id, poa, method, cookie.value, |
info.m_reply_header.reply_status = |
652 |
servant |
ReplyHeader.LOCATION_FORWARD; |
653 |
); |
info.m_forward_reference = fex.forward; |
654 |
servant = null; |
try |
655 |
|
{ |
656 |
|
interceptor.send_other(info); |
657 |
|
break Forwarding; |
658 |
|
} |
659 |
|
catch (ForwardRequest fex2) |
660 |
|
{ |
661 |
|
info.m_forward_reference = fex2.forward; |
662 |
|
fex.forward = info.m_forward_reference; |
663 |
|
} |
664 |
} |
} |
665 |
} |
} |
666 |
|
throw new gnuForwardRequest(fex.forward); |
667 |
} |
} |
668 |
finally |
catch (gnuForwardRequest fex) |
669 |
{ |
{ |
670 |
orb.currents.remove(Thread.currentThread()); |
// May be thrown during activation. |
671 |
|
if (intercept) |
672 |
|
{ |
673 |
|
Forwarding: |
674 |
|
while (true) |
675 |
|
{ |
676 |
|
info.m_reply_header.reply_status = |
677 |
|
ReplyHeader.LOCATION_FORWARD; |
678 |
|
info.m_forward_reference = fex.forward_reference; |
679 |
|
try |
680 |
|
{ |
681 |
|
interceptor.send_other(info); |
682 |
|
break Forwarding; |
683 |
|
} |
684 |
|
catch (ForwardRequest fex2) |
685 |
|
{ |
686 |
|
info.m_forward_reference = fex2.forward; |
687 |
|
fex.forward_reference = (ObjectImpl) fex2.forward; |
688 |
|
} |
689 |
|
} |
690 |
|
} |
691 |
|
throw fex; |
692 |
} |
} |
693 |
} |
} |
694 |
|
|
695 |
/** |
/** |
696 |
* Compare with another object for equality, comparing the |
* Compare with another object for equality, comparing the object keys. |
|
* object keys. |
|
697 |
*/ |
*/ |
698 |
public boolean equals(java.lang.Object other) |
public boolean equals(java.lang.Object other) |
699 |
{ |
{ |
704 |
return Arrays.equals(o.Id, Id); |
return Arrays.equals(o.Id, Id); |
705 |
} |
} |
706 |
else |
else |
707 |
return false; |
{ |
708 |
|
return false; |
709 |
|
} |
710 |
} |
} |
711 |
|
|
712 |
/** |
/** |
760 |
} |
} |
761 |
|
|
762 |
/** |
/** |
763 |
* Checks if this object is equivalent to another instance. |
* Checks if this object is equivalent to another instance. These objects are |
764 |
* These objects are assumed equal if they are connected to the |
* assumed equal if they are connected to the same orb and poa under the same |
765 |
* same orb and poa under the same Id, regardless of they |
* Id, regardless of they delegates. |
|
* delegates. |
|
766 |
* |
* |
767 |
* @param another instance to check. |
* @param another instance to check. |
768 |
* @return |
* @return |
782 |
IOR_Delegate ird = (IOR_Delegate) ir._get_delegate(); |
IOR_Delegate ird = (IOR_Delegate) ir._get_delegate(); |
783 |
byte[] ior_id = poa.idFormIor(ird.getIor().key); |
byte[] ior_id = poa.idFormIor(ird.getIor().key); |
784 |
if (ior_id != null && Arrays.equals(ior_id, Id)) |
if (ior_id != null && Arrays.equals(ior_id, Id)) |
785 |
return true; |
{ |
786 |
|
return true; |
787 |
|
} |
788 |
else |
else |
789 |
return false; |
{ |
790 |
|
return false; |
791 |
|
} |
792 |
} |
} |
793 |
catch (Exception ex) |
catch (Exception ex) |
794 |
{ |
{ |