Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "tao/IORTable/Table_Adapter.h"
00011 #include "tao/IORTable/IOR_Table_Impl.h"
00012 #include "tao/ORB_Core.h"
00013 #include "tao/Server_Strategy_Factory.h"
00014 #include "tao/Object.h"
00015 #include "tao/Stub.h"
00016 #include "tao/ORB.h"
00017 #include "tao/Profile.h"
00018 #include "tao/TAO_Server_Request.h"
00019
00020 ACE_RCSID (IORTable,
00021 Table_Adapter,
00022 "$Id: Table_Adapter.cpp 84215 2009-01-22 18:31:17Z johnnyw $")
00023
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025
00026 TAO_Table_Adapter::TAO_Table_Adapter (TAO_ORB_Core &orb_core)
00027 : orb_core_ (orb_core),
00028 root_ (),
00029 closed_ (true),
00030 enable_locking_ (orb_core_.server_factory ()->enable_poa_locking ()),
00031 thread_lock_ (),
00032 lock_ (TAO_Table_Adapter::create_lock (enable_locking_,
00033 thread_lock_))
00034 {
00035 }
00036
00037 TAO_Table_Adapter::~TAO_Table_Adapter (void)
00038 {
00039 delete this->lock_;
00040 }
00041
00042
00043 ACE_Lock *
00044 TAO_Table_Adapter::create_lock (bool enable_locking,
00045 TAO_SYNCH_MUTEX &thread_lock)
00046 {
00047 #if defined (ACE_HAS_THREADS)
00048 if (enable_locking)
00049 {
00050 ACE_Lock *the_lock = 0;
00051 ACE_NEW_RETURN (the_lock,
00052 ACE_Lock_Adapter<TAO_SYNCH_MUTEX> (thread_lock),
00053 0);
00054 return the_lock;
00055 }
00056 #else
00057 ACE_UNUSED_ARG (enable_locking);
00058 ACE_UNUSED_ARG (thread_lock);
00059 #endif
00060
00061 ACE_Lock *the_lock = 0;
00062 ACE_NEW_RETURN (the_lock,
00063 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
00064 0);
00065 return the_lock;
00066 }
00067
00068 void
00069 TAO_Table_Adapter::open (void)
00070 {
00071 ACE_GUARD (ACE_Lock, ace_mon, *this->lock_);
00072 TAO_IOR_Table_Impl *impl = 0;
00073 ACE_NEW_THROW_EX (impl,
00074 TAO_IOR_Table_Impl (),
00075 CORBA::NO_MEMORY ());
00076
00077 this->root_ = impl;
00078 this->closed_ = false;
00079 }
00080
00081 void
00082 TAO_Table_Adapter::close (int)
00083 {
00084 ACE_GUARD (ACE_Lock, ace_mon, *this->lock_);
00085 this->closed_ = true;
00086
00087
00088 }
00089
00090 void
00091 TAO_Table_Adapter::check_close (int)
00092 {
00093 }
00094
00095 int
00096 TAO_Table_Adapter::priority (void) const
00097 {
00098 return static_cast<int> (TAO_DEFAULT_ADAPTER_REGISTRY_SIZE);
00099 }
00100
00101 int
00102 TAO_Table_Adapter::dispatch (TAO::ObjectKey &key,
00103 TAO_ServerRequest &request,
00104 CORBA::Object_out forward_to)
00105 {
00106 TAO_IOR_Table_Impl_var rootref;
00107 {
00108 ACE_GUARD_RETURN (ACE_Lock,
00109 ace_mon,
00110 *this->lock_,
00111 TAO_Adapter::DS_MISMATCHED_KEY);
00112 if (this->closed_)
00113 return TAO_Adapter::DS_MISMATCHED_KEY;
00114 rootref = this->root_;
00115 }
00116
00117 if (this->find_object (key, forward_to))
00118 {
00119 request.forward_location (forward_to);
00120 return TAO_Adapter::DS_FORWARD;
00121 }
00122 else
00123 return TAO_Adapter::DS_MISMATCHED_KEY;
00124 }
00125
00126 const char *
00127 TAO_Table_Adapter::name (void) const
00128 {
00129 return "IORTable";
00130 }
00131
00132 CORBA::Object_ptr
00133 TAO_Table_Adapter::root (void)
00134 {
00135 return CORBA::Object::_duplicate (this->root_.in());
00136 }
00137
00138 CORBA::Object_ptr
00139 TAO_Table_Adapter::create_collocated_object (TAO_Stub *stub,
00140 const TAO_MProfile &)
00141 {
00142 CORBA::Object_ptr result = CORBA::Object::_nil ();
00143
00144 if (! this->initialize_collocated_object (stub))
00145 {
00146
00147
00148
00149
00150 ACE_NEW_RETURN (result,
00151 CORBA::Object (stub,
00152 stub->is_collocated (),
00153 stub->collocated_servant ()),
00154 CORBA::Object::_nil ());
00155
00156 }
00157
00158 return result;
00159 }
00160
00161 CORBA::Long
00162 TAO_Table_Adapter::initialize_collocated_object (TAO_Stub *stub)
00163 {
00164
00165 const TAO_MProfile &mp = stub->forward_profiles () ? *(stub->forward_profiles ())
00166 : stub->base_profiles ();
00167 TAO_PHandle j = 0;
00168
00169
00170 TAO::ObjectKey_var key = mp.get_profile (j)->_key ();
00171
00172 CORBA::Object_var forward_to = CORBA::Object::_nil ();
00173 CORBA::Boolean found = false;
00174
00175 try
00176 {
00177 found = this->find_object (key, forward_to.out ());
00178 }
00179 catch (const ::CORBA::Exception&)
00180 {
00181 }
00182
00183 if (found)
00184 {
00185
00186
00187 stub->add_forward_profiles (forward_to->_stubobj ()->base_profiles ());
00188 stub->next_profile ();
00189 }
00190
00191
00192 return ! found;
00193 }
00194
00195 bool
00196 TAO_Table_Adapter::find_object (TAO::ObjectKey &key,
00197 CORBA::Object_out forward_to)
00198 {
00199 CORBA::String_var object_key;
00200 TAO::ObjectKey::encode_sequence_to_string (object_key.out (), key);
00201 try
00202 {
00203 CORBA::String_var ior = root_->find (object_key.in ());
00204 forward_to = this->orb_core_.orb ()->string_to_object (ior.in ());
00205 }
00206 catch (const ::IORTable::NotFound&)
00207 {
00208 return false;
00209 }
00210 return true;
00211 }
00212
00213
00214
00215 TAO_Table_Adapter_Factory::TAO_Table_Adapter_Factory (void)
00216 {
00217 }
00218
00219 TAO_Adapter*
00220 TAO_Table_Adapter_Factory::create (TAO_ORB_Core *oc)
00221 {
00222 TAO_Adapter* ptr = 0;
00223 ACE_NEW_RETURN (ptr,
00224 TAO_Table_Adapter (*oc),
00225 0);
00226 return ptr;
00227 }
00228
00229 TAO_END_VERSIONED_NAMESPACE_DECL
00230
00231 ACE_FACTORY_DEFINE (TAO_IORTable, TAO_Table_Adapter_Factory)
00232 ACE_STATIC_SVC_DEFINE (TAO_Table_Adapter_Factory,
00233 ACE_TEXT ("TAO_IORTable"),
00234 ACE_SVC_OBJ_T,
00235 &ACE_SVC_NAME (TAO_Table_Adapter_Factory),
00236 ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00237 0)