Adapter_Registry.cpp

Go to the documentation of this file.
00001 // $Id: Adapter_Registry.cpp 77636 2007-03-09 12:56:14Z johnnyw $
00002 
00003 #include "tao/Object.h"
00004 #include "tao/Stub.h"
00005 #include "tao/Adapter_Registry.h"
00006 #include "tao/Adapter.h"
00007 #include "tao/SystemException.h"
00008 #include "tao/debug.h"
00009 
00010 #include "ace/Log_Msg.h"
00011 #include "ace/OS_NS_string.h"
00012 #include "ace/CORBA_macros.h"
00013 
00014 ACE_RCSID (tao,
00015            Adapter_Registry,
00016            "$Id: Adapter_Registry.cpp 77636 2007-03-09 12:56:14Z johnnyw $")
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 TAO_Adapter_Registry::TAO_Adapter_Registry (TAO_ORB_Core *oc)
00021   : orb_core_ (oc),
00022     adapters_capacity_ (16), // @@ Make it configurable
00023     adapters_count_ (0),
00024     adapters_ (0)
00025 {
00026   ACE_NEW (this->adapters_,
00027            TAO_Adapter*[this->adapters_capacity_]);
00028 }
00029 
00030 TAO_Adapter_Registry::~TAO_Adapter_Registry (void)
00031 {
00032   for (size_t i = 0; i != this->adapters_count_; ++i)
00033     delete this->adapters_[i];
00034 
00035   delete[] this->adapters_;
00036 }
00037 
00038 void
00039 TAO_Adapter_Registry::close (int wait_for_completion)
00040 {
00041   try
00042     {
00043       for (size_t i = 0; i != this->adapters_count_; ++i)
00044         {
00045           this->adapters_[i]->close (wait_for_completion);
00046         }
00047     }
00048   catch (const::CORBA::Exception &ex)
00049     {
00050       if (TAO_debug_level > 3)
00051         {
00052           ex._tao_print_exception (
00053             "Exception in TAO_Adapter_Registry::close ()");
00054         }
00055       return;
00056     }
00057 
00058   return;
00059 }
00060 
00061 void
00062 TAO_Adapter_Registry::check_close (int wait_for_completion)
00063 {
00064   for (size_t i = 0; i != this->adapters_count_; ++i)
00065     {
00066       this->adapters_[i]->check_close (wait_for_completion);
00067     }
00068 }
00069 
00070 void
00071 TAO_Adapter_Registry::insert (TAO_Adapter *adapter)
00072 {
00073   if (this->adapters_capacity_ == this->adapters_count_)
00074     {
00075       this->adapters_capacity_ *= 2;
00076       TAO_Adapter **tmp = 0;
00077       ACE_NEW_THROW_EX (tmp,
00078                         TAO_Adapter*[this->adapters_capacity_],
00079                         CORBA::NO_MEMORY ());
00080 
00081       for (size_t i = 0; i != this->adapters_count_; ++i)
00082         tmp[i] = this->adapters_[i];
00083       delete[] this->adapters_;
00084       this->adapters_ = tmp;
00085     }
00086 
00087   int const priority = adapter->priority ();
00088   for (size_t i = 0; i != this->adapters_count_; ++i)
00089     {
00090       if (this->adapters_[i]->priority () >= priority)
00091         {
00092           for (size_t j = this->adapters_count_ + 1;
00093                j > i;
00094                --j)
00095             {
00096               this->adapters_[j] = this->adapters_[j - 1];
00097             }
00098           this->adapters_[i] = adapter;
00099           ++this->adapters_count_;
00100           return;
00101         }
00102     }
00103   this->adapters_[this->adapters_count_++] = adapter;
00104 }
00105 
00106 void
00107 TAO_Adapter_Registry::dispatch (TAO::ObjectKey &key,
00108                                 TAO_ServerRequest &request,
00109                                 CORBA::Object_out forward_to)
00110 {
00111   for (size_t i = 0; i != this->adapters_count_; ++i)
00112     {
00113       int const r = this->adapters_[i]->dispatch (key, request, forward_to);
00114 
00115       if (r != TAO_Adapter::DS_MISMATCHED_KEY)
00116         {
00117           return;
00118         }
00119     }
00120 
00121   if (CORBA::is_nil (forward_to))
00122     {
00123       throw ::CORBA::OBJECT_NOT_EXIST ();
00124     }
00125 }
00126 
00127 CORBA::Object_ptr
00128 TAO_Adapter_Registry::create_collocated_object (TAO_Stub *stub,
00129                                                 const TAO_MProfile &mprofile)
00130 {
00131   for (size_t i = 0; i != this->adapters_count_; ++i)
00132     {
00133       CORBA::Object_ptr x =
00134         this->adapters_[i]->create_collocated_object (stub, mprofile);
00135       if (x != 0)
00136         {
00137           if (!stub->collocated_servant ())
00138             {
00139               // This adapter created an object but it was not able to locate
00140               // a servant so we need to give the rest of the adapters a chance to
00141               // initialise the stub and find a servant or forward us or whatever.
00142               for (CORBA::Long go_on = 1; go_on && i != this->adapters_count_;
00143                    ++i)
00144                 {
00145                   // initialize_collocated_object only returns 0 if it has completely
00146                   // initialised the object.
00147                   go_on = this->adapters_[i]->initialize_collocated_object (
00148                     stub);
00149                 }
00150             }
00151           return x;
00152         }
00153     }
00154   return 0;
00155 }
00156 
00157 CORBA::Long
00158 TAO_Adapter_Registry::initialize_collocated_object (TAO_Stub *stub)
00159 {
00160   for (size_t i = 0; i != this->adapters_count_; ++i)
00161     {
00162       int const retval =
00163         this->adapters_[i]->initialize_collocated_object (stub);
00164       if (retval == 0)
00165         {
00166           // initialize_collocated_object only returns 0 if it has completely
00167           // initialised the object. We can return early.
00168           return retval;
00169         }
00170     }
00171   return 0;
00172 }
00173 
00174 TAO_Adapter *
00175 TAO_Adapter_Registry::find_adapter (const char *name) const
00176 {
00177   for (TAO_Adapter **i = this->adapters_;
00178        i != this->adapters_ + this->adapters_count_;
00179        ++i)
00180     if (ACE_OS::strcmp ((*i)->name (), name) == 0)
00181       return *i;
00182 
00183   return 0;
00184 
00185 }
00186 
00187 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Sun Jan 27 13:07:31 2008 for TAO by doxygen 1.3.6