Table_Adapter.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Table_Adapter.cpp
00003  *
00004  * $Id: Table_Adapter.cpp 77409 2007-02-26 23:48:49Z ossama $
00005  *
00006  * @author Carlos O'Ryan <coryan@uci.edu>
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 
00019 ACE_RCSID (IORTable,
00020            Table_Adapter,
00021            "$Id: Table_Adapter.cpp 77409 2007-02-26 23:48:49Z ossama $")
00022 
00023 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 TAO_Table_Adapter::TAO_Table_Adapter (TAO_ORB_Core &orb_core)
00026   :  orb_core_ (orb_core),
00027      root_ (),
00028      closed_ (true),
00029      enable_locking_ (orb_core_.server_factory ()->enable_poa_locking ()),
00030      thread_lock_ (),
00031      lock_ (TAO_Table_Adapter::create_lock (enable_locking_,
00032                                             thread_lock_))
00033 {
00034 }
00035 
00036 TAO_Table_Adapter::~TAO_Table_Adapter (void)
00037 {
00038   delete this->lock_;
00039 }
00040 
00041 /* static */
00042 ACE_Lock *
00043 TAO_Table_Adapter::create_lock (bool enable_locking,
00044                                 TAO_SYNCH_MUTEX &thread_lock)
00045 {
00046 #if defined (ACE_HAS_THREADS)
00047   if (enable_locking)
00048     {
00049       ACE_Lock *the_lock = 0;
00050       ACE_NEW_RETURN (the_lock,
00051                       ACE_Lock_Adapter<TAO_SYNCH_MUTEX> (thread_lock),
00052                       0);
00053       return the_lock;
00054     }
00055 #else
00056   ACE_UNUSED_ARG (enable_locking);
00057   ACE_UNUSED_ARG (thread_lock);
00058 #endif /* ACE_HAS_THREADS */
00059 
00060   ACE_Lock *the_lock = 0;
00061   ACE_NEW_RETURN (the_lock,
00062                   ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX> (),
00063                   0);
00064   return the_lock;
00065 }
00066 
00067 void
00068 TAO_Table_Adapter::open (void)
00069 {
00070   ACE_GUARD (ACE_Lock, ace_mon, *this->lock_);
00071   TAO_IOR_Table_Impl *impl = 0;
00072   ACE_NEW_THROW_EX (impl,
00073                     TAO_IOR_Table_Impl (),
00074                     CORBA::NO_MEMORY ());
00075 
00076   this->root_ = impl;
00077   this->closed_ = false;
00078 }
00079 
00080 void
00081 TAO_Table_Adapter::close (int)
00082 {
00083   ACE_GUARD (ACE_Lock, ace_mon, *this->lock_);
00084   this->closed_ = true;
00085   // no need to release the impl now, that will happen in the
00086   // destructor.
00087 }
00088 
00089 void
00090 TAO_Table_Adapter::check_close (int)
00091 {
00092 }
00093 
00094 int
00095 TAO_Table_Adapter::priority (void) const
00096 {
00097   return static_cast<int> (TAO_DEFAULT_ADAPTER_REGISTRY_SIZE);
00098 }
00099 
00100 int
00101 TAO_Table_Adapter::dispatch (TAO::ObjectKey &key,
00102                              TAO_ServerRequest &,
00103                              CORBA::Object_out forward_to)
00104 {
00105   TAO_IOR_Table_Impl_var rootref;
00106   {
00107     ACE_GUARD_RETURN (ACE_Lock,
00108                       ace_mon,
00109                       *this->lock_,
00110                       TAO_Adapter::DS_MISMATCHED_KEY);
00111     if (this->closed_)
00112       return TAO_Adapter::DS_MISMATCHED_KEY;
00113     rootref = this->root_;
00114   }
00115 
00116   return this->find_object (key, forward_to) ? TAO_Adapter::DS_FORWARD
00117                                              : TAO_Adapter::DS_MISMATCHED_KEY;
00118 }
00119 
00120 const char *
00121 TAO_Table_Adapter::name (void) const
00122 {
00123   return "IORTable";
00124 }
00125 
00126 CORBA::Object_ptr
00127 TAO_Table_Adapter::root (void)
00128 {
00129   return CORBA::Object::_duplicate (this->root_.in());
00130 }
00131 
00132 CORBA::Object_ptr
00133 TAO_Table_Adapter::create_collocated_object (TAO_Stub *stub,
00134                                              const TAO_MProfile &)
00135 {
00136   CORBA::Object_ptr result = CORBA::Object::_nil ();
00137 
00138   if (! this->initialize_collocated_object (stub)) // 0 == success
00139     {
00140       // A reference was found in the table. The stub has been forwarded
00141       // to this. The collocation indicators are now correct on the stub
00142       // (although they may well now indicate that the stub is not in fact
00143       // collocated at all).
00144       ACE_NEW_RETURN (result,
00145                       CORBA::Object (stub,
00146                                      stub->is_collocated (),
00147                                      stub->collocated_servant ()),
00148                       CORBA::Object::_nil ());
00149 
00150     }
00151 
00152   return result;
00153 }
00154 
00155 CORBA::Long
00156 TAO_Table_Adapter::initialize_collocated_object (TAO_Stub *stub)
00157 {
00158   // Get the effective profile set.
00159   const TAO_MProfile &mp = stub->forward_profiles () ? *(stub->forward_profiles ())
00160                                                      : stub->base_profiles ();
00161   TAO_PHandle j = 0;
00162   // We only look at the key from the 0th profile but we only really care about
00163   // corbaloc's here where all profiles share a single object key
00164   TAO::ObjectKey_var key = mp.get_profile (j)->_key ();
00165 
00166   CORBA::Object_var forward_to = CORBA::Object::_nil ();
00167   CORBA::Boolean found = false;
00168 
00169   try
00170     {
00171       found = this->find_object (key, forward_to.out ());
00172     }
00173   catch (const ::CORBA::Exception&)
00174     {
00175     }
00176 
00177   if (found)
00178     {
00179       // This call will set the appropriate collocation values
00180       // to correspond to the reference we found in the table.
00181       stub->add_forward_profiles (forward_to->_stubobj ()->base_profiles ());
00182       stub->next_profile ();
00183     }
00184 
00185   // 0 for success
00186   return ! found;
00187 }
00188 
00189 CORBA::Long
00190 TAO_Table_Adapter::find_object (TAO::ObjectKey &key,
00191                                 CORBA::Object_out forward_to)
00192 {
00193   CORBA::String_var object_key;
00194   TAO::ObjectKey::encode_sequence_to_string (object_key.out (), key);
00195   try
00196     {
00197       CORBA::String_var ior = root_->find (object_key.in ());
00198       forward_to = this->orb_core_.orb ()->string_to_object (ior.in ());
00199     }
00200   catch (const ::IORTable::NotFound&)
00201     {
00202       return 0;
00203     }
00204   return 1;
00205 }
00206 
00207 // ****************************************************************
00208 
00209 TAO_Table_Adapter_Factory::TAO_Table_Adapter_Factory (void)
00210 {
00211 }
00212 
00213 TAO_Adapter*
00214 TAO_Table_Adapter_Factory::create (TAO_ORB_Core *oc)
00215 {
00216   TAO_Adapter* ptr = 0;
00217   ACE_NEW_RETURN (ptr,
00218                  TAO_Table_Adapter (*oc),
00219                  0);
00220   return ptr;
00221 }
00222 
00223 TAO_END_VERSIONED_NAMESPACE_DECL
00224 
00225 ACE_FACTORY_DEFINE (TAO_IORTable, TAO_Table_Adapter_Factory)
00226 ACE_STATIC_SVC_DEFINE (TAO_Table_Adapter_Factory,
00227                        ACE_TEXT ("TAO_IORTable"),
00228                        ACE_SVC_OBJ_T,
00229                        &ACE_SVC_NAME (TAO_Table_Adapter_Factory),
00230                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00231                        0)

Generated on Sun Jan 27 13:38:22 2008 for TAO_IORTable by doxygen 1.3.6