00001
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
00013 ACE_RCSID (tao,
00014 Adapter_Registry,
00015 "Adapter_Registry.cpp,v 1.8 2006/04/19 08:24:24 jwillemsen Exp")
00016
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018
00019 TAO_Adapter_Registry::TAO_Adapter_Registry (TAO_ORB_Core *oc)
00020 : orb_core_ (oc),
00021 adapters_capacity_ (16),
00022 adapters_count_ (0),
00023 adapters_ (0)
00024 {
00025 ACE_NEW (this->adapters_,
00026 TAO_Adapter*[this->adapters_capacity_]);
00027 }
00028
00029 TAO_Adapter_Registry::~TAO_Adapter_Registry (void)
00030 {
00031 for (size_t i = 0; i != this->adapters_count_; ++i)
00032 delete this->adapters_[i];
00033
00034 delete[] this->adapters_;
00035 }
00036
00037 void
00038 TAO_Adapter_Registry::close (int wait_for_completion
00039 ACE_ENV_ARG_DECL)
00040 {
00041 ACE_TRY
00042 {
00043 for (size_t i = 0; i != this->adapters_count_; ++i)
00044 {
00045 this->adapters_[i]->close (wait_for_completion
00046 ACE_ENV_ARG_PARAMETER);
00047 ACE_TRY_CHECK;
00048 }
00049 }
00050 ACE_CATCHANY
00051 {
00052 if (TAO_debug_level > 3)
00053 {
00054 ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
00055 "Exception in TAO_Adapter_Registry::close ()");
00056 }
00057 return;
00058 }
00059 ACE_ENDTRY;
00060
00061 return;
00062 }
00063
00064 void
00065 TAO_Adapter_Registry::check_close (int wait_for_completion
00066 ACE_ENV_ARG_DECL)
00067 {
00068 for (size_t i = 0; i != this->adapters_count_; ++i)
00069 {
00070 this->adapters_[i]->check_close (wait_for_completion
00071 ACE_ENV_ARG_PARAMETER);
00072 ACE_TRY_CHECK;
00073 }
00074 }
00075
00076 void
00077 TAO_Adapter_Registry::insert (TAO_Adapter *adapter
00078 ACE_ENV_ARG_DECL)
00079 {
00080 if (this->adapters_capacity_ == this->adapters_count_)
00081 {
00082 this->adapters_capacity_ *= 2;
00083 TAO_Adapter **tmp = 0;
00084 ACE_NEW_THROW_EX (tmp,
00085 TAO_Adapter*[this->adapters_capacity_],
00086 CORBA::NO_MEMORY ());
00087 ACE_CHECK;
00088
00089 for (size_t i = 0; i != this->adapters_count_; ++i)
00090 tmp[i] = this->adapters_[i];
00091 delete[] this->adapters_;
00092 this->adapters_ = tmp;
00093 }
00094
00095 int const priority = adapter->priority ();
00096 for (size_t i = 0; i != this->adapters_count_; ++i)
00097 {
00098 if (this->adapters_[i]->priority () >= priority)
00099 {
00100 for (size_t j = this->adapters_count_ + 1;
00101 j > i;
00102 --j)
00103 {
00104 this->adapters_[j] = this->adapters_[j - 1];
00105 }
00106 this->adapters_[i] = adapter;
00107 ++this->adapters_count_;
00108 return;
00109 }
00110 }
00111 this->adapters_[this->adapters_count_++] = adapter;
00112 }
00113
00114 void
00115 TAO_Adapter_Registry::dispatch (TAO::ObjectKey &key,
00116 TAO_ServerRequest &request,
00117 CORBA::Object_out forward_to
00118 ACE_ENV_ARG_DECL)
00119 {
00120 for (size_t i = 0; i != this->adapters_count_; ++i)
00121 {
00122 int const r = this->adapters_[i]->dispatch (key,
00123 request,
00124 forward_to
00125 ACE_ENV_ARG_PARAMETER);
00126 ACE_CHECK;
00127
00128 if (r != TAO_Adapter::DS_MISMATCHED_KEY)
00129 {
00130 return;
00131 }
00132 }
00133
00134 if (CORBA::is_nil (forward_to))
00135 {
00136 ACE_THROW (CORBA::OBJECT_NOT_EXIST ());
00137 }
00138 }
00139
00140 CORBA::Object_ptr
00141 TAO_Adapter_Registry::create_collocated_object (TAO_Stub *stub,
00142 const TAO_MProfile &mprofile)
00143 {
00144 for (size_t i = 0; i != this->adapters_count_; ++i)
00145 {
00146 CORBA::Object_ptr x =
00147 this->adapters_[i]->create_collocated_object (stub,
00148 mprofile);
00149 if (x != 0)
00150 {
00151 if (!stub->collocated_servant ())
00152 {
00153
00154
00155
00156 for (CORBA::Long go_on = 1; go_on && i != this->adapters_count_; ++i)
00157 {
00158
00159
00160 go_on = this->adapters_[i]->initialize_collocated_object (stub);
00161 }
00162 }
00163 return x;
00164 }
00165 }
00166 return 0;
00167 }
00168
00169 CORBA::Long
00170 TAO_Adapter_Registry::initialize_collocated_object (TAO_Stub *stub)
00171 {
00172 for (size_t i = 0; i != this->adapters_count_; ++i)
00173 {
00174 int const retval =
00175 this->adapters_[i]->initialize_collocated_object (stub);
00176 if (retval == 0)
00177 {
00178
00179
00180 return retval;
00181 }
00182 }
00183 return 0;
00184 }
00185
00186 TAO_Adapter *
00187 TAO_Adapter_Registry::find_adapter (const char *name) const
00188 {
00189 for (TAO_Adapter **i = this->adapters_;
00190 i != this->adapters_ + this->adapters_count_;
00191 ++i)
00192 if (ACE_OS::strcmp ((*i)->name (), name) == 0)
00193 return *i;
00194
00195 return 0;
00196
00197 }
00198
00199 TAO_END_VERSIONED_NAMESPACE_DECL