2 #include "tao/Messaging/Asynch_Invocation_Adapter.h"
3 #include "tao/Messaging/Asynch_Reply_Dispatcher.h"
4 #include "tao/Messaging/Asynch_Invocation.h"
5 #include "tao/Messaging/AMI_Arguments_Converter_Impl.h"
7 #include "tao/Profile_Transport_Resolver.h"
8 #include "tao/operation_details.h"
10 #include "tao/Transport.h"
11 #include "tao/Muxed_TMS.h"
12 #include "tao/ORB_Constants.h"
13 #include "tao/debug.h"
14 #include "tao/ORB_Core.h"
15 #include "tao/Thread_Lane_Resources.h"
16 #include "tao/GIOP_Utils.h"
18 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
22 Asynch_Invocation_Adapter::Asynch_Invocation_Adapter (
23 CORBA::Object
*target
,
26 const char *operation
,
28 int collocation_opportunity
,
31 : Invocation_Adapter (target
,
36 collocation_opportunity
,
37 TAO_TWOWAY_INVOCATION
,
45 Asynch_Invocation_Adapter::invoke (
46 Messaging::ReplyHandler_ptr reply_handler_ptr
,
47 const TAO_Reply_Handler_Stub
&reply_handler_stub
)
52 if (TAO_debug_level
>= 4)
54 TAOLIB_DEBUG ((LM_DEBUG
,
55 "TAO_Messaging (%P|%t) - Asynch_Invocation_Adapter::"
59 // If the reply handler is nil, we do not create a reply dispatcher.
60 // The ORB will drop replies to which it cannot associate a reply
62 if (!CORBA::is_nil (reply_handler_ptr
))
64 // New reply dispatcher on the heap or allocator, because
65 // we will go out of scope and hand over the reply dispatcher
67 TAO_Asynch_Reply_Dispatcher
*rd
= 0;
69 // Get the allocator we could use.
70 ACE_Allocator
* ami_allocator
=
71 stub
->orb_core ()->lane_resources().ami_response_handler_allocator();
73 // If we have an allocator, use it, else use the heap.
78 static_cast<TAO_Asynch_Reply_Dispatcher
*> (
79 ami_allocator
->malloc (sizeof (TAO_Asynch_Reply_Dispatcher
))),
80 TAO_Asynch_Reply_Dispatcher (reply_handler_stub
,
88 TAO_Asynch_Reply_Dispatcher (reply_handler_stub
,
96 throw ::CORBA::NO_MEMORY ();
99 this->safe_rd_
.reset (rd
);
102 Invocation_Adapter::invoke (0, 0);
106 Asynch_Invocation_Adapter::invoke (
107 const TAO::Exception_Data
*ex
,
108 unsigned long ex_count
)
110 Invocation_Adapter::invoke (ex
, ex_count
);
114 Asynch_Invocation_Adapter::invoke_collocated_i (
116 TAO_Operation_Details
&details
,
117 CORBA::Object_var
&effective_target
,
118 Collocation_Strategy strat
)
120 if (stub
->orb_core ()->orb_params ()->ami_collication ())
122 // When doing a collocation asynch invocation we shouldn't use the
123 // stub args but use the skel args
124 details
.use_stub_args (false);
126 TAO_AMI_Arguments_Converter_Impl
* ami_arguments_converter
127 = ACE_Dynamic_Service
<TAO_AMI_Arguments_Converter_Impl
>::instance (
128 "AMI_Arguments_Converter");
129 details
.cac (ami_arguments_converter
);
131 // Release the owner ship of the reply dispatcher
132 details
.reply_dispatcher (this->safe_rd_
.release ());
134 return Invocation_Adapter::invoke_collocated_i (stub
,
141 ACE_Time_Value
*max_wait_time
= 0;
142 return Invocation_Adapter::invoke_remote_i (stub
,
150 Asynch_Invocation_Adapter::invoke_twoway (
151 TAO_Operation_Details
&op
,
152 CORBA::Object_var
&effective_target
,
153 Profile_Transport_Resolver
&r
,
154 ACE_Time_Value
*&max_wait_time
,
155 Invocation_Retry_State
*retry_state
)
157 ACE_UNUSED_ARG (retry_state
);
159 // Simple sanity check
160 if (this->mode_
!= TAO_ASYNCHRONOUS_CALLBACK_INVOCATION
161 || this->type_
!= TAO_TWOWAY_INVOCATION
)
163 throw ::CORBA::INTERNAL (
164 CORBA::SystemException::_tao_minor_code (
167 CORBA::COMPLETED_NO
);
170 if (this->safe_rd_
.get () && r
.transport ())
172 this->safe_rd_
->transport (r
.transport ());
173 // AMI Timeout Handling Begin
176 if (this->get_timeout (r
.stub (), tmp
))
178 this->safe_rd_
->schedule_timer (op
.request_id (), *max_wait_time
);
182 // Loose ownership of the reply dispatcher
183 TAO::Asynch_Remote_Invocation
asynch (
184 effective_target
.in (),
187 this->safe_rd_
.release ());
189 // forward requested byte order
190 asynch
._tao_byte_order (this->_tao_byte_order ());
192 Invocation_Status
const s
= asynch
.remote_invocation (max_wait_time
);
194 if (s
== TAO_INVOKE_RESTART
&&
195 (asynch
.reply_status () == GIOP::LOCATION_FORWARD
||
196 asynch
.reply_status () == GIOP::LOCATION_FORWARD_PERM
))
198 CORBA::Boolean
const permanent_forward
=
199 (asynch
.reply_status () == GIOP::LOCATION_FORWARD_PERM
);
201 effective_target
= asynch
.steal_forwarded_reference ();
203 this->object_forwarded (effective_target
, r
.stub (), permanent_forward
);
209 } // End namespace TAO
211 TAO_END_VERSIONED_NAMESPACE_DECL