1 //=============================================================================
5 * @brief Definition of ImR_DSI_Forwarder
7 * @author Phil Mesnier <mesnier_p@ociweb.com>
9 //=============================================================================
11 #include "orbsvcs/Log_Macros.h"
12 #include "Forwarder.h"
13 #include "ImR_Locator_i.h"
16 #include "tao/Object_KeyC.h"
17 #include "tao/ORB_Constants.h"
19 #include "tao/PortableServer/PortableServer.h"
20 #include "tao/PortableServer/POA_Current_Impl.h"
21 #include "tao/PortableServer/POA_Current.h"
23 #include "tao/TAO_Server_Request.h"
24 #include "tao/DynamicInterface/Request.h"
25 #include "tao/DynamicInterface/Server_Request.h"
26 #include "tao/DynamicInterface/AMH_DSI_Response_Handler.h"
27 #include "tao/Messaging/AMH_Response_Handler.h"
29 ImR_DSI_Forwarder::ImR_DSI_Forwarder (ImR_Locator_i
& imr_impl
)
35 ImR_DSI_Forwarder::~ImR_DSI_Forwarder ()
40 ImR_DSI_Forwarder::init (CORBA::ORB_ptr orb
)
42 ACE_ASSERT (! CORBA::is_nil(orb
));
46 CORBA::Object_var tmp
=
47 orb
->resolve_initial_references ("POACurrent");
49 this->poa_current_var_
=
50 PortableServer::Current::_narrow (tmp
.in ());
52 catch (const CORBA::Exception
&)
55 ACE_ASSERT (!CORBA::is_nil (this->poa_current_var_
.in ()));
59 ImR_DSI_Forwarder::_dispatch (TAO_ServerRequest
&request
,
60 TAO::Portable_Server::Servant_Upcall
* /*context */ )
62 // No need to do any of this if the client isn't waiting.
63 if (request
.response_expected ())
65 if (!CORBA::is_nil (request
.forward_location ()))
67 request
.init_reply ();
68 request
.tao_send_reply ();
70 // No need to invoke in this case.
75 // Create DSI request object.
76 CORBA::ServerRequest
*dsi_request
= 0;
78 CORBA::ServerRequest (request
));
81 TAO_AMH_DSI_Response_Handler_ptr rhp
;
82 ACE_NEW (rhp
, TAO_AMH_DSI_Response_Handler(request
));
83 TAO_AMH_DSI_Response_Handler_var
rh(rhp
);
85 rh
->init (request
, 0);
87 this->invoke (dsi_request
, rh
.in());
89 catch (const CORBA::Exception
& ex
)
91 // Only if the client is waiting.
92 if (request
.response_expected () && !request
.sync_with_server ())
94 request
.tao_send_reply_exception (ex
);
97 CORBA::release (dsi_request
);
101 ImR_DSI_Forwarder::invoke (CORBA::ServerRequest_ptr
)
103 // unused method, only asynch invocations are used
107 ImR_DSI_Forwarder::_primary_interface (const PortableServer::ObjectId
&,
108 PortableServer::POA_ptr
)
110 return CORBA::string_dup ("IDL:Object:1.0");
114 ImR_DSI_Forwarder::invoke (CORBA::ServerRequest_ptr request
,
115 TAO_AMH_DSI_Response_Handler_ptr resp
)
117 bool is_oneway
= !(request
->_tao_server_request().response_expected()
118 || request
->_tao_server_request().sync_with_server());
122 return; // nothing else to do, the client isn't waiting so no forwarding
126 PortableServer::POA_var poa
= this->poa_current_var_
->get_POA();
127 PortableServer::ObjectId_var oid
= this->poa_current_var_
->get_object_id ();
129 CORBA::String_var server_name
= poa
->the_name();
131 CORBA::String_var key_str
;
132 // Unlike POA Current, this implementation cannot be cached.
133 TAO::Portable_Server::POA_Current
* tao_current
=
134 dynamic_cast <TAO::Portable_Server::POA_Current
*> (this->poa_current_var_
.in ());
136 ACE_ASSERT(tao_current
!= 0);
137 TAO::Portable_Server::POA_Current_Impl
* impl
= tao_current
->implementation ();
138 TAO::ObjectKey::encode_sequence_to_string (key_str
.out (), impl
->object_key ());
140 ImR_DSI_ResponseHandler
* rh
= 0;
141 ACE_NEW (rh
, ImR_DSI_ResponseHandler(key_str
.in(),
142 this->locator_
.debug() > 0 ?
143 server_name
.in() : "",
145 this->locator_
.activate_server_by_name (server_name
.in(), false, rh
);
149 ImR_DSI_Forwarder::invoke_get_interface(CORBA::ServerRequest_ptr
)
155 ImR_DSI_Forwarder::invoke_primary_interface(CORBA::ServerRequest_ptr
)
161 //--------------------------------------------------------------------
163 ImR_DSI_ResponseHandler::ImR_DSI_ResponseHandler (const char *key
,
164 const char *server_name
,
166 TAO_AMH_DSI_Response_Handler_ptr resp
)
168 server_name_ (server_name
),
169 orb_(CORBA::ORB::_duplicate (orb
)),
170 resp_ (TAO_AMH_DSI_Response_Handler::_duplicate (resp
))
174 ImR_DSI_ResponseHandler::~ImR_DSI_ResponseHandler ()
179 ImR_DSI_ResponseHandler::send_ior (const char *pior
)
181 ACE_CString ior
= pior
;
183 // Check that the returned ior is the expected partial ior with
184 // missing ObjectKey.
185 if (ior
.find ("corbaloc:") == 0 && ior
[ior
.length () -1] == '/')
187 ior
+= this->key_str_
.in();
189 CORBA::Object_var forward_obj
= this->orb_
->string_to_object (ior
.c_str ());
191 if (!CORBA::is_nil (forward_obj
.in ()))
193 this->resp_
->invoke_location_forward(forward_obj
.in(), false);
199 if (ImR_Locator_i::debug () > 1)
201 ORBSVCS_ERROR ((LM_ERROR
,
202 ACE_TEXT ("(%P|%t) ImR_DSI_ResponseHandler::send_ior (): Forward_to ")
203 ACE_TEXT ("reference is nil for key <%C> server_name <%C>\n"),
204 key_str_
.in (), server_name_
.in ()));
210 if (ImR_Locator_i::debug () > 1)
212 ORBSVCS_ERROR ((LM_ERROR
,
213 ACE_TEXT ("(%P|%t) ImR_DSI_ResponseHandler::send_ior (): Invalid corbaloc ior for key <%C> server_name <%C> IOR <%C>\n"),
214 key_str_
.in (), server_name_
.in (), pior
));
218 this->invoke_excep_i (new CORBA::OBJECT_NOT_EXIST
219 (CORBA::SystemException::_tao_minor_code
220 ( TAO_IMPLREPO_MINOR_CODE
, 0),
221 CORBA::COMPLETED_NO
));
225 ImR_DSI_ResponseHandler::invoke_excep_i (CORBA::Exception
*ex
)
227 TAO_AMH_DSI_Exception_Holder
h(ex
);
228 this->resp_
->invoke_excep(&h
);
233 ImR_DSI_ResponseHandler::send_exception (CORBA::Exception
*ex
)
235 // Discard the exception, always throw a transient:
238 this->invoke_excep_i (new CORBA::TRANSIENT
239 (CORBA::SystemException::_tao_minor_code
240 (TAO_IMPLREPO_MINOR_CODE
, 0),
241 CORBA::COMPLETED_NO
));