40 |
|
|
41 |
import gnu.CORBA.CDR.cdrBufInput; |
import gnu.CORBA.CDR.cdrBufInput; |
42 |
import gnu.CORBA.GIOP.ReplyHeader; |
import gnu.CORBA.GIOP.ReplyHeader; |
43 |
|
import gnu.CORBA.Poa.activeObjectMap; |
44 |
|
|
45 |
|
import org.omg.CORBA.CompletionStatus; |
46 |
import org.omg.CORBA.Context; |
import org.omg.CORBA.Context; |
47 |
import org.omg.CORBA.ContextList; |
import org.omg.CORBA.ContextList; |
48 |
import org.omg.CORBA.ExceptionList; |
import org.omg.CORBA.ExceptionList; |
73 |
extends Simple_delegate |
extends Simple_delegate |
74 |
{ |
{ |
75 |
/** |
/** |
76 |
|
* True if the current IOR does not map into the local servant. |
77 |
|
* If false, the IOR is either local or should be checked. |
78 |
|
*/ |
79 |
|
boolean remote_ior; |
80 |
|
|
81 |
|
/** |
82 |
|
* If not null, this field contains data about the local servant. |
83 |
|
*/ |
84 |
|
activeObjectMap.Obj local_ior; |
85 |
|
|
86 |
|
/** |
87 |
* Contructs an instance of object using the given IOR. |
* Contructs an instance of object using the given IOR. |
88 |
*/ |
*/ |
89 |
public IOR_Delegate(ORB an_orb, IOR an_ior) |
public IOR_Delegate(ORB an_orb, IOR an_ior) |
109 |
NamedValue returns |
NamedValue returns |
110 |
) |
) |
111 |
{ |
{ |
112 |
gnuRequest request = new gnuRequest(); |
gnuRequest request = getRequestInstance(target); |
113 |
|
|
114 |
request.setIor(getIor()); |
request.setIor(getIor()); |
115 |
request.set_target(target); |
request.set_target(target); |
140 |
ContextList ctx_list |
ContextList ctx_list |
141 |
) |
) |
142 |
{ |
{ |
143 |
gnuRequest request = new gnuRequest(); |
gnuRequest request = getRequestInstance(target); |
144 |
|
|
145 |
request.setIor(ior); |
request.setIor(ior); |
146 |
request.set_target(target); |
request.set_target(target); |
157 |
} |
} |
158 |
|
|
159 |
/** |
/** |
160 |
* Invoke operation on the given object, writing parameters to the given |
* Get the instance of request. |
161 |
* output stream. |
*/ |
162 |
|
protected gnuRequest getRequestInstance(org.omg.CORBA.Object target) |
163 |
|
{ |
164 |
|
return new gnuRequest(); |
165 |
|
} |
166 |
|
|
167 |
|
/** |
168 |
|
* Invoke operation on the given object, als handling temproray and permanent |
169 |
|
* redirections. The ReplyHeader.LOCATION_FORWARD will cause to resend |
170 |
|
* the request to the new direction. The ReplyHeader.LOCATION_FORWARD_PERM |
171 |
|
* will cause additionally to remember the new location by this delegate, |
172 |
|
* so subsequent calls will be immediately delivered to the new target. |
173 |
* |
* |
174 |
* @param target the target object. |
* @param target the target object. |
175 |
* @param output the output stream, previously returned by |
* @param output the output stream, previously returned by |
237 |
} |
} |
238 |
catch (IOException ex) |
catch (IOException ex) |
239 |
{ |
{ |
240 |
MARSHAL t = new MARSHAL("Cant read forwarding info"); |
MARSHAL t = |
241 |
|
new MARSHAL("Cant read forwarding info", 5102, |
242 |
|
CompletionStatus.COMPLETED_NO |
243 |
|
); |
244 |
t.initCause(ex); |
t.initCause(ex); |
245 |
throw t; |
throw t; |
246 |
} |
} |
247 |
|
|
248 |
request.request.setIor(forwarded); |
gnuRequest prev = request.request; |
249 |
|
gnuRequest r = getRequestInstance(target); |
250 |
|
|
251 |
|
r.m_args = prev.m_args; |
252 |
|
r.m_context = prev.m_context; |
253 |
|
r.m_context_list = prev.m_context_list; |
254 |
|
r.m_environment = prev.m_environment; |
255 |
|
r.m_exceptions = prev.m_exceptions; |
256 |
|
r.m_operation = prev.m_operation; |
257 |
|
r.m_parameter_buffer = prev.m_parameter_buffer; |
258 |
|
r.m_parameter_buffer.request = r; |
259 |
|
r.m_result = prev.m_result; |
260 |
|
r.m_target = prev.m_target; |
261 |
|
r.oneWay = prev.oneWay; |
262 |
|
r.setIor(forwarded); |
263 |
|
|
264 |
|
IOR_contructed_object it = |
265 |
|
new IOR_contructed_object(orb, forwarded); |
266 |
|
|
267 |
// If the object has moved permanently, its IOR is replaced. |
r.m_target = it; |
|
if (moved_permanently) |
|
|
setIor(forwarded); |
|
268 |
|
|
269 |
return invoke(target, request); |
request.request = r; |
270 |
|
|
271 |
|
IOR prev_ior = getIor(); |
272 |
|
|
273 |
|
setIor(forwarded); |
274 |
|
|
275 |
|
try |
276 |
|
{ |
277 |
|
return invoke(it, request); |
278 |
|
} |
279 |
|
finally |
280 |
|
{ |
281 |
|
if (!moved_permanently) |
282 |
|
setIor(prev_ior); |
283 |
|
} |
284 |
|
|
285 |
default : |
default : |
286 |
throw new MARSHAL("Unknow reply status: " + rh.reply_status); |
throw new MARSHAL("Unknow reply status: " + rh.reply_status, |
287 |
|
8000 + rh.reply_status, |
288 |
|
CompletionStatus.COMPLETED_NO |
289 |
|
); |
290 |
} |
} |
291 |
} |
} |
292 |
else |
else |
306 |
*/ |
*/ |
307 |
public Request request(org.omg.CORBA.Object target, String operation) |
public Request request(org.omg.CORBA.Object target, String operation) |
308 |
{ |
{ |
309 |
gnuRequest request = new gnuRequest(); |
gnuRequest request = getRequestInstance(target); |
310 |
|
|
311 |
request.setIor(ior); |
request.setIor(ior); |
312 |
request.set_target(target); |
request.set_target(target); |
331 |
boolean response_expected |
boolean response_expected |
332 |
) |
) |
333 |
{ |
{ |
334 |
gnuRequest request = new gnuRequest(); |
gnuRequest request = getRequestInstance(target); |
335 |
|
|
336 |
request.setIor(ior); |
request.setIor(ior); |
337 |
request.set_target(target); |
request.set_target(target); |
367 |
// do nothing, then. |
// do nothing, then. |
368 |
} |
} |
369 |
} |
} |
370 |
|
|
371 |
|
/** |
372 |
|
* Reset the remote_ior flag, forcing to check if the object is local |
373 |
|
* on the next getRequestInstance call. |
374 |
|
*/ |
375 |
|
public void setIor(IOR an_ior) |
376 |
|
{ |
377 |
|
super.setIor(an_ior); |
378 |
|
remote_ior = false; |
379 |
|
local_ior = null; |
380 |
|
} |
381 |
|
|
382 |
|
/** |
383 |
|
* Checks if the ior is local so far it is easy. |
384 |
|
*/ |
385 |
|
public boolean is_local(org.omg.CORBA.Object self) |
386 |
|
{ |
387 |
|
if (remote_ior) |
388 |
|
return false; |
389 |
|
else if (local_ior != null) |
390 |
|
return true; |
391 |
|
else |
392 |
|
return super.is_local(self); |
393 |
|
} |
394 |
} |
} |