55 |
import org.omg.CORBA.portable.InputStream; |
import org.omg.CORBA.portable.InputStream; |
56 |
import org.omg.CORBA.portable.OutputStream; |
import org.omg.CORBA.portable.OutputStream; |
57 |
import org.omg.CORBA.portable.RemarshalException; |
import org.omg.CORBA.portable.RemarshalException; |
58 |
|
import org.omg.PortableInterceptor.ForwardRequest; |
59 |
|
|
60 |
import java.io.IOException; |
import java.io.IOException; |
61 |
|
|
70 |
* |
* |
71 |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
72 |
*/ |
*/ |
73 |
public class IOR_Delegate |
public class IOR_Delegate extends Simple_delegate |
|
extends Simple_delegate |
|
74 |
{ |
{ |
75 |
/** |
/** |
76 |
* True if the current IOR does not map into the local servant. |
* True if the current IOR does not map into the local servant. If false, the |
77 |
* If false, the IOR is either local or should be checked. |
* IOR is either local or should be checked. |
78 |
*/ |
*/ |
79 |
boolean remote_ior; |
boolean remote_ior; |
80 |
|
|
105 |
* @return the created request. |
* @return the created request. |
106 |
*/ |
*/ |
107 |
public Request create_request(org.omg.CORBA.Object target, Context context, |
public Request create_request(org.omg.CORBA.Object target, Context context, |
108 |
String operation, NVList parameters, |
String operation, NVList parameters, NamedValue returns |
109 |
NamedValue returns |
) |
|
) |
|
110 |
{ |
{ |
111 |
gnuRequest request = getRequestInstance(target); |
gnuRequest request = getRequestInstance(target); |
112 |
|
|
134 |
* @return the created request. |
* @return the created request. |
135 |
*/ |
*/ |
136 |
public Request create_request(org.omg.CORBA.Object target, Context context, |
public Request create_request(org.omg.CORBA.Object target, Context context, |
137 |
String operation, NVList parameters, |
String operation, NVList parameters, NamedValue returns, |
138 |
NamedValue returns, ExceptionList exceptions, |
ExceptionList exceptions, ContextList ctx_list |
139 |
ContextList ctx_list |
) |
|
) |
|
140 |
{ |
{ |
141 |
gnuRequest request = getRequestInstance(target); |
gnuRequest request = getRequestInstance(target); |
142 |
|
|
164 |
|
|
165 |
/** |
/** |
166 |
* Invoke operation on the given object, als handling temproray and permanent |
* Invoke operation on the given object, als handling temproray and permanent |
167 |
* redirections. The ReplyHeader.LOCATION_FORWARD will cause to resend |
* redirections. The ReplyHeader.LOCATION_FORWARD will cause to resend the |
168 |
* the request to the new direction. The ReplyHeader.LOCATION_FORWARD_PERM |
* request to the new direction. The ReplyHeader.LOCATION_FORWARD_PERM will |
169 |
* will cause additionally to remember the new location by this delegate, |
* cause additionally to remember the new location by this delegate, so |
170 |
* so subsequent calls will be immediately delivered to the new target. |
* subsequent calls will be immediately delivered to the new target. |
171 |
* |
* |
172 |
* @param target the target object. |
* @param target the target object. |
173 |
* @param output the output stream, previously returned by |
* @param output the output stream, previously returned by |
174 |
* {@link #request(org.omg.CORBA.Object, String, boolean)}. |
* {@link #request(org.omg.CORBA.Object, String, boolean)}. |
175 |
* |
* |
176 |
* @return the input stream, to read the response from or null for a |
* @return the input stream, to read the response from or null for a one-way |
177 |
* one-way request. |
* request. |
178 |
* |
* |
179 |
* @throws SystemException if the SystemException has been thrown on the |
* @throws SystemException if the SystemException has been thrown on the |
180 |
* remote side (the exact type and the minor code matches the data of |
* remote side (the exact type and the minor code matches the data of the |
181 |
* the remote exception that has been thrown). |
* remote exception that has been thrown). |
182 |
* |
* |
183 |
* @throws org.omg.CORBA.portable.ApplicationException as specified. |
* @throws org.omg.CORBA.portable.ApplicationException as specified. |
184 |
* @throws org.omg.CORBA.portable.RemarshalException as specified. |
* @throws org.omg.CORBA.portable.RemarshalException as specified. |
185 |
*/ |
*/ |
186 |
public InputStream invoke(org.omg.CORBA.Object target, OutputStream output) |
public InputStream invoke(org.omg.CORBA.Object target, OutputStream output) |
187 |
throws ApplicationException, RemarshalException |
throws ApplicationException, RemarshalException |
188 |
{ |
{ |
189 |
streamRequest request = (streamRequest) output; |
streamRequest request = (streamRequest) output; |
190 |
if (request.response_expected) |
Forwardings: |
191 |
|
while (true) |
192 |
{ |
{ |
193 |
binaryReply response = request.request.submit(); |
try |
|
|
|
|
// Read reply header. |
|
|
ReplyHeader rh = response.header.create_reply_header(); |
|
|
cdrBufInput input = response.getStream(); |
|
|
input.setOrb(orb); |
|
|
rh.read(input); |
|
|
|
|
|
boolean moved_permanently = false; |
|
|
|
|
|
switch (rh.reply_status) |
|
194 |
{ |
{ |
195 |
case ReplyHeader.NO_EXCEPTION : |
if (request.response_expected) |
196 |
if (response.header.version.since_inclusive(1, 2)) |
{ |
197 |
input.align(8); |
binaryReply response = request.request.submit(); |
198 |
return input; |
|
199 |
|
// Read reply header. |
200 |
case ReplyHeader.SYSTEM_EXCEPTION : |
ReplyHeader rh = response.header.create_reply_header(); |
201 |
if (response.header.version.since_inclusive(1, 2)) |
cdrBufInput input = response.getStream(); |
202 |
input.align(8); |
input.setOrb(orb); |
203 |
throw ObjectCreator.readSystemException(input); |
rh.read(input); |
204 |
|
request.request.m_rph = rh; |
205 |
case ReplyHeader.USER_EXCEPTION : |
|
206 |
if (response.header.version.since_inclusive(1, 2)) |
boolean moved_permanently = false; |
207 |
input.align(8); |
|
208 |
input.mark(2000); |
switch (rh.reply_status) |
209 |
|
{ |
210 |
String uxId = input.read_string(); |
case ReplyHeader.NO_EXCEPTION : |
211 |
input.reset(); |
if (request.request.m_interceptor != null) |
212 |
|
request.request.m_interceptor. |
213 |
throw new ApplicationException(uxId, input); |
receive_reply(request.request.m_info); |
214 |
|
if (response.header.version.since_inclusive(1, 2)) |
215 |
case ReplyHeader.LOCATION_FORWARD_PERM : |
input.align(8); |
216 |
moved_permanently = true; |
return input; |
217 |
|
|
218 |
case ReplyHeader.LOCATION_FORWARD : |
case ReplyHeader.SYSTEM_EXCEPTION : |
219 |
if (response.header.version.since_inclusive(1, 2)) |
if (response.header.version.since_inclusive(1, 2)) |
220 |
input.align(8); |
input.align(8); |
221 |
|
showException(request, input); |
222 |
IOR forwarded = new IOR(); |
|
223 |
try |
throw ObjectCreator.readSystemException(input); |
224 |
{ |
|
225 |
forwarded._read_no_endian(input); |
case ReplyHeader.USER_EXCEPTION : |
226 |
} |
if (response.header.version.since_inclusive(1, 2)) |
227 |
catch (IOException ex) |
input.align(8); |
228 |
{ |
showException(request, input); |
229 |
MARSHAL t = |
|
230 |
new MARSHAL("Cant read forwarding info", 5102, |
throw new ApplicationException(request. |
231 |
CompletionStatus.COMPLETED_NO |
request.m_exception_id, input |
232 |
); |
); |
233 |
t.initCause(ex); |
|
234 |
throw t; |
case ReplyHeader.LOCATION_FORWARD_PERM : |
235 |
} |
moved_permanently = true; |
236 |
|
|
237 |
gnuRequest prev = request.request; |
case ReplyHeader.LOCATION_FORWARD : |
238 |
gnuRequest r = getRequestInstance(target); |
if (response.header.version.since_inclusive(1, 2)) |
239 |
|
input.align(8); |
240 |
r.m_args = prev.m_args; |
|
241 |
r.m_context = prev.m_context; |
IOR forwarded = new IOR(); |
242 |
r.m_context_list = prev.m_context_list; |
try |
243 |
r.m_environment = prev.m_environment; |
{ |
244 |
r.m_exceptions = prev.m_exceptions; |
forwarded._read_no_endian(input); |
245 |
r.m_operation = prev.m_operation; |
} |
246 |
r.m_parameter_buffer = prev.m_parameter_buffer; |
catch (IOException ex) |
247 |
r.m_parameter_buffer.request = r; |
{ |
248 |
r.m_result = prev.m_result; |
MARSHAL t = |
249 |
r.m_target = prev.m_target; |
new MARSHAL("Cant read forwarding info", 5102, |
250 |
r.oneWay = prev.oneWay; |
CompletionStatus.COMPLETED_NO |
251 |
r.setIor(forwarded); |
); |
252 |
|
t.initCause(ex); |
253 |
IOR_contructed_object it = |
throw t; |
254 |
new IOR_contructed_object(orb, forwarded); |
} |
255 |
|
|
256 |
r.m_target = it; |
gnuRequest prev = request.request; |
257 |
|
gnuRequest r = getRequestInstance(target); |
258 |
request.request = r; |
|
259 |
|
r.m_interceptor = prev.m_interceptor; |
260 |
IOR prev_ior = getIor(); |
r.m_slots = prev.m_slots; |
261 |
|
|
262 |
setIor(forwarded); |
r.m_args = prev.m_args; |
263 |
|
r.m_context = prev.m_context; |
264 |
try |
r.m_context_list = prev.m_context_list; |
265 |
{ |
r.m_environment = prev.m_environment; |
266 |
return invoke(it, request); |
r.m_exceptions = prev.m_exceptions; |
267 |
} |
r.m_operation = prev.m_operation; |
268 |
finally |
r.m_parameter_buffer = prev.m_parameter_buffer; |
269 |
{ |
r.m_parameter_buffer.request = r; |
270 |
if (!moved_permanently) |
r.m_result = prev.m_result; |
271 |
setIor(prev_ior); |
r.m_target = prev.m_target; |
272 |
} |
r.oneWay = prev.oneWay; |
273 |
|
r.m_forward_ior = forwarded; |
274 |
default : |
|
275 |
throw new MARSHAL("Unknow reply status: " + rh.reply_status, |
if (r.m_interceptor != null) |
276 |
8000 + rh.reply_status, |
r.m_interceptor.receive_other(r.m_info); |
277 |
CompletionStatus.COMPLETED_NO |
|
278 |
); |
r.setIor(forwarded); |
279 |
|
|
280 |
|
IOR_contructed_object it = |
281 |
|
new IOR_contructed_object(orb, forwarded); |
282 |
|
|
283 |
|
r.m_target = it; |
284 |
|
|
285 |
|
request.request = r; |
286 |
|
|
287 |
|
IOR prev_ior = getIor(); |
288 |
|
|
289 |
|
setIor(forwarded); |
290 |
|
|
291 |
|
try |
292 |
|
{ |
293 |
|
return invoke(it, request); |
294 |
|
} |
295 |
|
finally |
296 |
|
{ |
297 |
|
if (!moved_permanently) |
298 |
|
setIor(prev_ior); |
299 |
|
} |
300 |
|
|
301 |
|
default : |
302 |
|
throw new MARSHAL("Unknow reply status: " + |
303 |
|
rh.reply_status, 8000 + rh.reply_status, |
304 |
|
CompletionStatus.COMPLETED_NO |
305 |
|
); |
306 |
|
} |
307 |
|
} |
308 |
|
else |
309 |
|
{ |
310 |
|
request.request.send_oneway(); |
311 |
|
return null; |
312 |
|
} |
313 |
|
} |
314 |
|
catch (ForwardRequest forwarded) |
315 |
|
{ |
316 |
|
ForwardRequest fw = forwarded; |
317 |
|
Forwarding2: |
318 |
|
while (true) |
319 |
|
{ |
320 |
|
try |
321 |
|
{ |
322 |
|
gnuRequest prev = request.request; |
323 |
|
gnuRequest r = getRequestInstance(target); |
324 |
|
|
325 |
|
r.m_interceptor = prev.m_interceptor; |
326 |
|
r.m_args = prev.m_args; |
327 |
|
r.m_context = prev.m_context; |
328 |
|
r.m_context_list = prev.m_context_list; |
329 |
|
r.m_environment = prev.m_environment; |
330 |
|
r.m_exceptions = prev.m_exceptions; |
331 |
|
r.m_operation = prev.m_operation; |
332 |
|
r.m_parameter_buffer = prev.m_parameter_buffer; |
333 |
|
r.m_parameter_buffer.request = r; |
334 |
|
r.m_result = prev.m_result; |
335 |
|
r.m_target = prev.m_target; |
336 |
|
r.oneWay = prev.oneWay; |
337 |
|
|
338 |
|
r.m_forwarding_target = fw.forward; |
339 |
|
|
340 |
|
if (r.m_interceptor != null) |
341 |
|
r.m_interceptor.receive_other(r.m_info); |
342 |
|
|
343 |
|
r.m_target = fw.forward; |
344 |
|
request.request = r; |
345 |
|
break Forwarding2; |
346 |
|
} |
347 |
|
catch (ForwardRequest e) |
348 |
|
{ |
349 |
|
forwarded = e; |
350 |
|
} |
351 |
|
} |
352 |
} |
} |
353 |
} |
} |
354 |
else |
} |
355 |
{ |
|
356 |
request.request.send_oneway(); |
/** |
357 |
return null; |
* Show exception to interceptor. |
358 |
} |
*/ |
359 |
|
void showException(streamRequest request, cdrBufInput input) |
360 |
|
throws ForwardRequest |
361 |
|
{ |
362 |
|
input.mark(2048); |
363 |
|
request.request.m_exception_id = input.read_string(); |
364 |
|
input.reset(); |
365 |
|
|
366 |
|
if (request.request.m_interceptor != null) |
367 |
|
request.request.m_interceptor.receive_exception(request.request.m_info); |
368 |
} |
} |
369 |
|
|
370 |
/** |
/** |
399 |
* @return the stream where the method arguments should be written. |
* @return the stream where the method arguments should be written. |
400 |
*/ |
*/ |
401 |
public OutputStream request(org.omg.CORBA.Object target, String operation, |
public OutputStream request(org.omg.CORBA.Object target, String operation, |
402 |
boolean response_expected |
boolean response_expected |
403 |
) |
) |
404 |
{ |
{ |
405 |
gnuRequest request = getRequestInstance(target); |
gnuRequest request = getRequestInstance(target); |
406 |
|
|
408 |
request.set_target(target); |
request.set_target(target); |
409 |
request.setOperation(operation); |
request.setOperation(operation); |
410 |
|
|
411 |
request.getParameterStream().response_expected = response_expected; |
streamRequest out = request.getParameterStream(); |
412 |
|
out.response_expected = response_expected; |
413 |
request.setORB(orb); |
request.setORB(orb); |
414 |
|
|
415 |
return request.getParameterStream(); |
return out; |
416 |
} |
} |
417 |
|
|
418 |
/** |
/** |
419 |
* If there is an opened cache socket to access this object, close |
* If there is an opened cache socket to access this object, close that |
420 |
* that socket. |
* socket. |
421 |
* |
* |
422 |
* @param target The target is not used, this delegate requires a |
* @param target The target is not used, this delegate requires a single |
423 |
* single instance per object. |
* instance per object. |
424 |
*/ |
*/ |
425 |
public void release(org.omg.CORBA.Object target) |
public void release(org.omg.CORBA.Object target) |
426 |
{ |
{ |
441 |
} |
} |
442 |
|
|
443 |
/** |
/** |
444 |
* Reset the remote_ior flag, forcing to check if the object is local |
* Reset the remote_ior flag, forcing to check if the object is local on the |
445 |
* on the next getRequestInstance call. |
* next getRequestInstance call. |
446 |
*/ |
*/ |
447 |
public void setIor(IOR an_ior) |
public void setIor(IOR an_ior) |
448 |
{ |
{ |