00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "Forwarder.h"
00015 #include "ImR_Locator_i.h"
00016
00017 #include "tao/ORB.h"
00018 #include "tao/Object_KeyC.h"
00019 #include "tao/ORB_Constants.h"
00020
00021 #include "tao/PortableServer/PortableServer.h"
00022 #include "tao/PortableServer/POA_Current_Impl.h"
00023 #include "tao/PortableServer/POA_Current.h"
00024
00025
00026
00027
00028
00029
00030 ImR_Forwarder::ImR_Forwarder (ImR_Locator_i& imr_impl)
00031 : locator_ (imr_impl)
00032 {
00033 }
00034
00035 void
00036 ImR_Forwarder::init (CORBA::ORB_ptr orb)
00037 {
00038 ACE_ASSERT (! CORBA::is_nil(orb));
00039 this->orb_ = orb;
00040 try
00041 {
00042 CORBA::Object_var tmp =
00043 orb->resolve_initial_references ("POACurrent");
00044
00045 this->poa_current_var_ =
00046 PortableServer::Current::_narrow (tmp.in ());
00047 }
00048 catch (const CORBA::Exception&)
00049 {
00050 ACE_DEBUG ((LM_DEBUG, "ImR_Forwarder::init() Exception ignored.\n"));
00051 }
00052 ACE_ASSERT (!CORBA::is_nil (this->poa_current_var_.in ()));
00053 }
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 PortableServer::Servant
00064 ImR_Forwarder::preinvoke (const PortableServer::ObjectId &,
00065 PortableServer::POA_ptr poa,
00066 const char *,
00067 PortableServer::ServantLocator::Cookie &)
00068 {
00069 ACE_ASSERT (! CORBA::is_nil(poa));
00070 CORBA::Object_var forward_obj;
00071
00072 try
00073 {
00074 CORBA::String_var server_name = poa->the_name();
00075
00076 if (locator_.debug() > 1)
00077 ACE_DEBUG ((LM_DEBUG, "ImR: Activating server <%s>.\n", server_name.in()));
00078
00079
00080
00081
00082 CORBA::String_var pior = locator_.activate_server_by_name (server_name.in (), false);
00083
00084 ACE_CString ior = pior.in ();
00085
00086
00087
00088 if (ior.find ("corbaloc:") != 0 || ior[ior.length () - 1] != '/')
00089 {
00090 ACE_ERROR ((LM_ERROR, "ImR_Forwarder::preinvoke () Invalid corbaloc ior.\n\t<%s>\n", ior.c_str()));
00091 throw CORBA::OBJECT_NOT_EXIST (
00092 CORBA::SystemException::_tao_minor_code (
00093 TAO_IMPLREPO_MINOR_CODE,
00094 0),
00095 CORBA::COMPLETED_NO);
00096 }
00097
00098 CORBA::String_var key_str;
00099
00100 TAO::Portable_Server::POA_Current* tao_current =
00101 dynamic_cast <TAO::Portable_Server::POA_Current*> (this->poa_current_var_.in ());
00102
00103 ACE_ASSERT(tao_current != 0);
00104 TAO::Portable_Server::POA_Current_Impl* impl = tao_current->implementation ();
00105 TAO::ObjectKey::encode_sequence_to_string (key_str.out (), impl->object_key ());
00106
00107 ior += key_str.in();
00108
00109 if (locator_.debug() > 0)
00110 ACE_DEBUG ((LM_DEBUG, "ImR: Forwarding invocation on <%s> to <%s>\n", server_name.in(), ior.c_str()));
00111
00112 forward_obj =
00113 this->orb_->string_to_object (ior.c_str ());
00114 }
00115 catch (const ImplementationRepository::CannotActivate&)
00116 {
00117 throw CORBA::TRANSIENT (
00118 CORBA::SystemException::_tao_minor_code (
00119 TAO_IMPLREPO_MINOR_CODE,
00120 0),
00121 CORBA::COMPLETED_NO);
00122 }
00123 catch (const ImplementationRepository::NotFound&)
00124 {
00125 throw CORBA::TRANSIENT (
00126 CORBA::SystemException::_tao_minor_code (
00127 TAO_IMPLREPO_MINOR_CODE,
00128 0),
00129 CORBA::COMPLETED_NO);
00130 }
00131 catch (const CORBA::Exception& ex)
00132 {
00133 ex._tao_print_exception ("Forwarder");
00134 throw CORBA::TRANSIENT (
00135 CORBA::SystemException::_tao_minor_code (
00136 TAO_IMPLREPO_MINOR_CODE,
00137 0),
00138 CORBA::COMPLETED_NO);
00139 }
00140
00141 if (!CORBA::is_nil (forward_obj.in ()))
00142 throw PortableServer::ForwardRequest (forward_obj.in ());
00143
00144 ACE_ERROR ((LM_ERROR, "Error: Forward_to reference is nil.\n"));
00145 throw CORBA::OBJECT_NOT_EXIST (
00146 CORBA::SystemException::_tao_minor_code (
00147 TAO_IMPLREPO_MINOR_CODE,
00148 0),
00149 CORBA::COMPLETED_NO);
00150 }
00151
00152 void
00153 ImR_Forwarder::postinvoke (const PortableServer::ObjectId &,
00154 PortableServer::POA_ptr,
00155 const char *,
00156 PortableServer::ServantLocator::Cookie,
00157 PortableServer::Servant)
00158 {
00159 }
00160