Go to the documentation of this file.00001 #include "tao/LocateRequest_Invocation.h"
00002 #include "tao/Profile_Transport_Resolver.h"
00003 #include "tao/operation_details.h"
00004 #include "tao/Stub.h"
00005 #include "tao/Bind_Dispatcher_Guard.h"
00006 #include "tao/Transport.h"
00007 #include "tao/Synch_Reply_Dispatcher.h"
00008 #include "tao/GIOP_Utils.h"
00009 #include "tao/Profile.h"
00010 #include "tao/ORB_Constants.h"
00011 #include "tao/SystemException.h"
00012 #include "ace/Intrusive_Auto_Ptr.h"
00013
00014 #include "ace/Countdown_Time.h"
00015
00016 ACE_RCSID (tao,
00017 LocateRequest_Invocation,
00018 "$Id: LocateRequest_Invocation.cpp 85364 2009-05-18 08:13:02Z vzykov $")
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 namespace TAO
00023 {
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class First_Request_Guard
00036 {
00037 public:
00038 First_Request_Guard (TAO_Transport &transport);
00039
00040 ~First_Request_Guard (void);
00041
00042 private:
00043
00044 TAO_Transport &transport_;
00045
00046
00047 bool is_first_;
00048 };
00049
00050 First_Request_Guard::First_Request_Guard (TAO_Transport &transport)
00051 : transport_ (transport)
00052 {
00053 this->is_first_ = this->transport_.first_request ();
00054 }
00055
00056 First_Request_Guard::~First_Request_Guard (void)
00057 {
00058 this->transport_.first_request_sent (this->is_first_);
00059 }
00060
00061 LocateRequest_Invocation::LocateRequest_Invocation (
00062 CORBA::Object_ptr otarget,
00063 Profile_Transport_Resolver &resolver,
00064 TAO_Operation_Details &detail
00065 )
00066 : Synch_Twoway_Invocation (otarget,
00067 resolver,
00068 detail)
00069 {
00070 }
00071
00072 Invocation_Status
00073 LocateRequest_Invocation::invoke (ACE_Time_Value *max_wait_time)
00074 {
00075 ACE_Countdown_Time countdown (max_wait_time);
00076
00077 TAO_Synch_Reply_Dispatcher *rd_p = 0;
00078 ACE_NEW_NORETURN (rd_p, TAO_Synch_Reply_Dispatcher (this->resolver_.stub ()->orb_core (),
00079 this->details_.reply_service_info ()));
00080 if (!rd_p)
00081 {
00082 throw ::CORBA::NO_MEMORY ();
00083 }
00084
00085 ACE_Intrusive_Auto_Ptr<TAO_Synch_Reply_Dispatcher> rd(rd_p, false);
00086
00087
00088
00089 TAO_Bind_Dispatcher_Guard dispatch_guard (this->details_.request_id (),
00090 rd.get (),
00091 this->resolver_.transport ()->tms ());
00092
00093 if (dispatch_guard.status () != 0)
00094 {
00095
00096
00097 this->resolver_.transport ()->close_connection ();
00098
00099 throw ::CORBA::INTERNAL (TAO::VMCID, CORBA::COMPLETED_NO);
00100 }
00101
00102 TAO_Transport *transport = this->resolver_.transport ();
00103
00104 Invocation_Status s = TAO_INVOKE_FAILURE;
00105 {
00106 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon,
00107 transport->output_cdr_lock (), TAO_INVOKE_FAILURE);
00108 TAO_OutputCDR &cdr = transport->out_stream ();
00109
00110
00111 First_Request_Guard fr_quard (*transport);
00112
00113 TAO_Target_Specification tspec;
00114 this->init_target_spec (tspec, cdr);
00115
00116 if (transport->generate_locate_request (tspec, this->details_, cdr) == -1)
00117 return TAO_INVOKE_FAILURE;
00118
00119 countdown.update ();
00120
00121 s = this->send_message (cdr, TAO_TWOWAY_REQUEST, max_wait_time);
00122 }
00123
00124 if (s != TAO_INVOKE_SUCCESS)
00125 return s;
00126
00127 countdown.update ();
00128
00129
00130
00131
00132 if (this->resolver_.transport ()->idle_after_send ())
00133 this->resolver_.transport_released ();
00134
00135 s = this->wait_for_reply (max_wait_time, *rd.get (), dispatch_guard);
00136
00137 s = this->check_reply (*rd.get ());
00138
00139
00140
00141
00142 if (this->resolver_.transport ()->idle_after_reply ())
00143 this->resolver_.transport_released ();
00144
00145 return s;
00146 }
00147
00148 Invocation_Status
00149 LocateRequest_Invocation::check_reply (TAO_Synch_Reply_Dispatcher &rd)
00150 {
00151 TAO_InputCDR &cdr = rd.reply_cdr ();
00152
00153
00154 this->resolver_.transport ()->assign_translators (&cdr, 0);
00155
00156 switch (rd.locate_reply_status ())
00157 {
00158 case GIOP::OBJECT_HERE:
00159 break;
00160 case GIOP::UNKNOWN_OBJECT:
00161 throw ::CORBA::OBJECT_NOT_EXIST (TAO::VMCID, CORBA::COMPLETED_YES);
00162 case GIOP::OBJECT_FORWARD:
00163 case GIOP::OBJECT_FORWARD_PERM:
00164 return this->location_forward (cdr);
00165 case GIOP::LOC_SYSTEM_EXCEPTION:
00166 {
00167
00168 CORBA::String_var buf;
00169
00170 if ((cdr >> buf.inout ()) == 0)
00171 {
00172
00173
00174 throw ::CORBA::MARSHAL (TAO::VMCID, CORBA::COMPLETED_MAYBE);
00175 }
00176
00177
00178
00179 throw ::CORBA::UNKNOWN (TAO::VMCID, CORBA::COMPLETED_YES);
00180 }
00181 case GIOP::LOC_NEEDS_ADDRESSING_MODE:
00182 {
00183
00184
00185
00186 CORBA::Short addr_mode = 0;
00187
00188 if (cdr.read_short (addr_mode) == 0)
00189 {
00190
00191
00192 throw ::CORBA::MARSHAL (TAO::VMCID, CORBA::COMPLETED_MAYBE);
00193 }
00194
00195
00196
00197 this->resolver_.profile ()->addressing_mode (addr_mode);
00198
00199
00200 return TAO_INVOKE_RESTART;
00201 }
00202 }
00203
00204 return TAO_INVOKE_SUCCESS;
00205 }
00206 }
00207
00208 TAO_END_VERSIONED_NAMESPACE_DECL