Adapter_Registry.cpp

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

Generated on Tue Feb 2 17:37:51 2010 for TAO by  doxygen 1.4.7