Go to the documentation of this file.00001
00002
00003 #include "tao/Messaging/Asynch_Reply_Dispatcher.h"
00004
00005 #include "tao/Pluggable_Messaging_Utils.h"
00006 #include "tao/ORB_Core.h"
00007 #include "tao/debug.h"
00008 #include "tao/ORB_Core.h"
00009 #include "tao/Transport.h"
00010
00011 ACE_RCSID(Messaging, Asynch_Reply_Dispatcher, "$Id: Asynch_Reply_Dispatcher.cpp 85001 2009-03-31 10:06:45Z msmit $")
00012
00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00014
00015
00016 TAO_Asynch_Reply_Dispatcher::TAO_Asynch_Reply_Dispatcher (
00017 const TAO_Reply_Handler_Stub &reply_handler_stub,
00018 Messaging::ReplyHandler_ptr reply_handler,
00019 TAO_ORB_Core *orb_core,
00020 ACE_Allocator *allocator
00021 )
00022 :TAO_Asynch_Reply_Dispatcher_Base (orb_core, allocator)
00023 , reply_handler_stub_ (reply_handler_stub)
00024 , reply_handler_ (Messaging::ReplyHandler::_duplicate (reply_handler))
00025 , timeout_handler_ (0)
00026 {
00027 }
00028
00029
00030 TAO_Asynch_Reply_Dispatcher::~TAO_Asynch_Reply_Dispatcher (void)
00031 {
00032 }
00033
00034
00035 int
00036 TAO_Asynch_Reply_Dispatcher::dispatch_reply (TAO_Pluggable_Reply_Params ¶ms)
00037 {
00038 if (this->timeout_handler_)
00039 {
00040
00041
00042 this->timeout_handler_->cancel ();
00043 this->timeout_handler_->remove_reference ();
00044 this->timeout_handler_ = 0;
00045
00046 }
00047
00048 if (!params.input_cdr_)
00049 return -1;
00050
00051 if (!this->try_dispatch_reply ())
00052 return 0;
00053
00054 this->reply_status_ = params.reply_status ();
00055 this->locate_reply_status_ = params.locate_reply_status ();
00056
00057
00058 ACE_Data_Block *db = this->reply_cdr_.clone_from (*params.input_cdr_);
00059
00060 if (db == 0)
00061 {
00062 if (TAO_debug_level > 2)
00063 {
00064 ACE_ERROR ((
00065 LM_ERROR,
00066 ACE_TEXT ("TAO_Messaging (%P|%t) - Asynch_Reply_Dispatcher::dispatch_reply ")
00067 ACE_TEXT ("clone_from failed\n")));
00068 }
00069 return -1;
00070 }
00071
00072
00073
00074
00075
00076
00077 if (ACE_BIT_DISABLED (db->flags (), ACE_Message_Block::DONT_DELETE))
00078 {
00079 db->release ();
00080 }
00081
00082 if (!CORBA::is_nil (this->reply_handler_.in ()))
00083 {
00084
00085
00086 CORBA::ULong const max = params.svc_ctx_.maximum ();
00087 CORBA::ULong const len = params.svc_ctx_.length ();
00088 IOP::ServiceContext *context_list = params.svc_ctx_.get_buffer (1);
00089 this->reply_service_info_.replace (max, len, context_list, 1);
00090
00091 if (TAO_debug_level >= 4)
00092 {
00093 ACE_DEBUG ((LM_DEBUG,
00094 ACE_TEXT ("TAO_Messaging (%P|%t) - Asynch_Reply_Dispatcher")
00095 ACE_TEXT ("::dispatch_reply status = %d\n"),
00096 this->reply_status_));
00097 }
00098
00099 CORBA::ULong reply_error = TAO_AMI_REPLY_NOT_OK;
00100 switch (this->reply_status_)
00101 {
00102 case GIOP::NO_EXCEPTION:
00103 reply_error = TAO_AMI_REPLY_OK;
00104 break;
00105 case GIOP::USER_EXCEPTION:
00106 reply_error = TAO_AMI_REPLY_USER_EXCEPTION;
00107 break;
00108 case GIOP::SYSTEM_EXCEPTION:
00109 reply_error = TAO_AMI_REPLY_SYSTEM_EXCEPTION;
00110 break;
00111 case GIOP::LOCATION_FORWARD:
00112 reply_error = TAO_AMI_REPLY_LOCATION_FORWARD;
00113 break;
00114 case GIOP::LOCATION_FORWARD_PERM:
00115 reply_error = TAO_AMI_REPLY_LOCATION_FORWARD_PERM;
00116 break;
00117
00118 default:
00119
00120
00121
00122
00123 reply_error = TAO_AMI_REPLY_NOT_OK;
00124 break;
00125 }
00126
00127 try
00128 {
00129
00130 this->reply_handler_stub_ (this->reply_cdr_,
00131 this->reply_handler_.in (),
00132 reply_error);
00133 }
00134 catch (const ::CORBA::Exception& ex)
00135 {
00136 if (TAO_debug_level >= 4)
00137 ex._tao_print_exception ("Exception during reply handler");
00138 }
00139 }
00140
00141 this->intrusive_remove_ref (this);
00142
00143 return 1;
00144 }
00145
00146 void
00147 TAO_Asynch_Reply_Dispatcher::connection_closed (void)
00148 {
00149 try
00150 {
00151 if (this->timeout_handler_)
00152 {
00153
00154
00155 this->timeout_handler_->cancel ();
00156 this->timeout_handler_->remove_reference ();
00157 this->timeout_handler_ = 0;
00158 }
00159
00160 if (!this->try_dispatch_reply ())
00161 return;
00162
00163 if (!CORBA::is_nil (this->reply_handler_.in ()))
00164 {
00165
00166 CORBA::COMM_FAILURE comm_failure (0, CORBA::COMPLETED_MAYBE);
00167
00168 TAO_OutputCDR out_cdr;
00169
00170 comm_failure._tao_encode (out_cdr);
00171
00172
00173 TAO_InputCDR cdr (out_cdr);
00174
00175 this->reply_handler_stub_ (cdr,
00176 this->reply_handler_.in (),
00177 TAO_AMI_REPLY_SYSTEM_EXCEPTION);
00178 }
00179 }
00180 catch (const ::CORBA::Exception& ex)
00181 {
00182 if (TAO_debug_level >= 4)
00183 {
00184 ex._tao_print_exception (
00185 "Asynch_Reply_Dispatcher::connection_closed");
00186 }
00187
00188 }
00189
00190 this->intrusive_remove_ref (this);
00191 }
00192
00193
00194
00195 void
00196 TAO_Asynch_Reply_Dispatcher::reply_timed_out (void)
00197 {
00198 try
00199 {
00200
00201 if (this->timeout_handler_)
00202 {
00203
00204
00205 this->timeout_handler_->remove_reference ();
00206 this->timeout_handler_ = 0;
00207 }
00208
00209
00210
00211
00212 if (!this->try_dispatch_reply ())
00213 return;
00214
00215 if (!CORBA::is_nil (this->reply_handler_.in ()))
00216 {
00217
00218 CORBA::TIMEOUT timeout_failure (
00219 CORBA::SystemException::_tao_minor_code (
00220 TAO_TIMEOUT_RECV_MINOR_CODE,
00221 errno),
00222 CORBA::COMPLETED_MAYBE);
00223
00224 TAO_OutputCDR out_cdr;
00225
00226 timeout_failure._tao_encode (out_cdr);
00227
00228
00229 TAO_InputCDR cdr (out_cdr);
00230
00231 this->reply_handler_stub_ (cdr,
00232 this->reply_handler_.in (),
00233 TAO_AMI_REPLY_SYSTEM_EXCEPTION);
00234 }
00235 }
00236 catch (const ::CORBA::Exception& ex)
00237 {
00238 if (TAO_debug_level >= 4)
00239 {
00240 ex._tao_print_exception ("Asynch_Reply_Dispatcher::reply_timed_out");
00241 }
00242 }
00243
00244 this->intrusive_remove_ref (this);
00245 }
00246
00247 long
00248 TAO_Asynch_Reply_Dispatcher::schedule_timer (CORBA::ULong request_id,
00249 const ACE_Time_Value &max_wait_time)
00250 {
00251 if (this->timeout_handler_ == 0)
00252 {
00253
00254 ACE_NEW_THROW_EX (this->timeout_handler_,
00255 TAO_Asynch_Timeout_Handler (
00256 this->transport_->orb_core ()->reactor ()),
00257 CORBA::NO_MEMORY ());
00258 }
00259
00260 return this->timeout_handler_->schedule_timer (
00261 this->transport_->tms (),
00262 request_id,
00263 max_wait_time);
00264 }
00265
00266 TAO_END_VERSIONED_NAMESPACE_DECL