00001
00002 #include "tao/orbconf.h"
00003
00004 ACE_RCSID (PortableServer,
00005 Request_Processing,
00006 "$Id: RequestProcessingStrategyServantActivator.cpp 76995 2007-02-11 12:51:42Z johnnyw $")
00007
00008 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
00009
00010 #include "tao/ORB_Constants.h"
00011 #include "tao/PortableServer/ServantActivatorC.h"
00012 #include "tao/PortableServer/RequestProcessingStrategyServantActivator.h"
00013 #include "tao/PortableServer/Servant_Base.h"
00014 #include "tao/PortableServer/Non_Servant_Upcall.h"
00015 #include "tao/PortableServer/Root_POA.h"
00016 #include "tao/PortableServer/POA_Current_Impl.h"
00017 #include "tao/PortableServer/Servant_Upcall.h"
00018
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020
00021 namespace TAO
00022 {
00023 namespace Portable_Server
00024 {
00025 RequestProcessingStrategyServantActivator::RequestProcessingStrategyServantActivator (void) :
00026 etherealize_objects_ (true)
00027 {
00028 }
00029
00030 void
00031 RequestProcessingStrategyServantActivator::strategy_cleanup (void)
00032 {
00033 {
00034 Non_Servant_Upcall non_servant_upcall (*this->poa_);
00035 ACE_UNUSED_ARG (non_servant_upcall);
00036
00037 this->servant_activator_ = PortableServer::ServantActivator::_nil ();
00038 }
00039
00040 RequestProcessingStrategy::strategy_cleanup ();
00041 }
00042
00043 PortableServer::ServantManager_ptr
00044 RequestProcessingStrategyServantActivator::get_servant_manager (void)
00045 {
00046 return PortableServer::ServantManager::_duplicate (this->servant_activator_.in ());
00047 }
00048
00049 void
00050 RequestProcessingStrategyServantActivator::set_servant_manager (
00051 PortableServer::ServantManager_ptr imgr)
00052 {
00053
00054
00055
00056
00057
00058 if (!CORBA::is_nil (this->servant_activator_.in ()))
00059 {
00060 throw ::CORBA::BAD_INV_ORDER (CORBA::OMGVMCID | 6, CORBA::COMPLETED_NO);
00061 }
00062
00063 this->servant_activator_ =
00064 PortableServer::ServantActivator::_narrow (imgr);
00065
00066 this->validate_servant_manager (this->servant_activator_.in ());
00067 }
00068
00069 TAO_SERVANT_LOCATION
00070 RequestProcessingStrategyServantActivator::locate_servant (
00071 const PortableServer::ObjectId &system_id,
00072 PortableServer::Servant &servant)
00073 {
00074 TAO_SERVANT_LOCATION location = TAO_SERVANT_NOT_FOUND;
00075
00076 location = this->poa_->servant_present (system_id, servant);
00077
00078 if (location == TAO_SERVANT_NOT_FOUND)
00079 {
00080 if (!CORBA::is_nil (this->servant_activator_.in ()))
00081 {
00082 location = TAO_SERVANT_MANAGER;
00083 }
00084 }
00085
00086 return location;
00087 }
00088
00089 PortableServer::Servant
00090 RequestProcessingStrategyServantActivator::locate_servant (
00091 const char * ,
00092 const PortableServer::ObjectId &system_id,
00093 TAO::Portable_Server::Servant_Upcall &servant_upcall,
00094 TAO::Portable_Server::POA_Current_Impl &poa_current_impl,
00095 bool &wait_occurred_restart_call
00096 )
00097 {
00098 PortableServer::Servant servant = 0;
00099
00100 servant = this->poa_->find_servant (system_id,
00101 servant_upcall,
00102 poa_current_impl);
00103
00104 if (servant != 0)
00105 {
00106 return servant;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 this->validate_servant_manager (this->servant_activator_.in ());
00129
00130 servant = this->incarnate_servant (poa_current_impl.object_id ());
00131
00132
00133
00134
00135
00136
00137
00138 bool may_activate =
00139 this->poa_->is_servant_activation_allowed (servant,
00140 wait_occurred_restart_call);
00141
00142 if (!may_activate)
00143 {
00144
00145
00146
00147 throw ::CORBA::OBJ_ADAPTER ();
00148 }
00149
00150
00151
00152
00153
00154
00155 if (!wait_occurred_restart_call)
00156 {
00157 int const result =
00158 this->poa_->
00159 rebind_using_user_id_and_system_id (servant,
00160 poa_current_impl.object_id (),
00161 system_id,
00162 servant_upcall);
00163 if (result != 0)
00164 {
00165
00166
00167 throw ::CORBA::OBJ_ADAPTER ();
00168 }
00169
00170
00171 servant_upcall.increment_servant_refcount ();
00172 }
00173 else
00174 {
00175 CORBA::Boolean cleanup_in_progress = 0;
00176 this->etherealize_servant (poa_current_impl.object_id (),
00177 servant,
00178 cleanup_in_progress);
00179
00180
00181
00182
00183 return 0;
00184 }
00185
00186
00187 return servant;
00188 }
00189
00190 void
00191 RequestProcessingStrategyServantActivator::etherealize_servant (
00192 const PortableServer::ObjectId& object_id,
00193 PortableServer::Servant servant,
00194 CORBA::Boolean cleanup_in_progress
00195 )
00196 {
00197 CORBA::Boolean remaining_activations =
00198 this->poa_->servant_has_remaining_activations (servant);
00199
00200
00201 Non_Servant_Upcall non_servant_upcall (*this->poa_);
00202 ACE_UNUSED_ARG (non_servant_upcall);
00203
00204
00205
00206
00207 this->servant_activator_->etherealize (object_id,
00208 this->poa_,
00209 servant,
00210 cleanup_in_progress,
00211 remaining_activations);
00212 }
00213
00214 PortableServer::Servant
00215 RequestProcessingStrategyServantActivator::incarnate_servant (
00216 const PortableServer::ObjectId& object_id)
00217 {
00218 PortableServer::Servant servant = 0;
00219
00220
00221 Non_Servant_Upcall non_servant_upcall (*this->poa_);
00222 ACE_UNUSED_ARG (non_servant_upcall);
00223
00224
00225
00226
00227
00228 servant = this->servant_activator_->incarnate (object_id, this->poa_);
00229
00230 if (servant == 0)
00231 {
00232 throw ::CORBA::OBJ_ADAPTER (CORBA::OMGVMCID | 7, CORBA::COMPLETED_NO);
00233 }
00234 else
00235 {
00236 return servant;
00237 }
00238 }
00239
00240 void
00241 RequestProcessingStrategyServantActivator::cleanup_servant (
00242 PortableServer::Servant servant,
00243 const PortableServer::ObjectId &user_id
00244 )
00245 {
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 if (servant)
00272 {
00273 if (this->etherealize_objects_ &&
00274 !CORBA::is_nil (this->servant_activator_.in ()))
00275 {
00276 this->etherealize_servant (user_id,
00277 servant,
00278 this->poa_->cleanup_in_progress ());
00279 }
00280 else
00281 {
00282
00283 Non_Servant_Upcall non_servant_upcall (*this->poa_);
00284 ACE_UNUSED_ARG (non_servant_upcall);
00285
00286 servant->_remove_ref ();
00287 }
00288 }
00289
00290
00291
00292
00293 if (this->poa_->unbind_using_user_id (user_id) != 0)
00294 throw ::CORBA::OBJ_ADAPTER ();
00295 }
00296
00297 void
00298 RequestProcessingStrategyServantActivator::etherealize_objects (
00299 CORBA::Boolean etherealize_objects)
00300 {
00301 this->etherealize_objects_ = etherealize_objects;
00302 }
00303
00304 void
00305 RequestProcessingStrategyServantActivator::post_invoke_servant_cleanup(
00306 const PortableServer::ObjectId &,
00307 const TAO::Portable_Server::Servant_Upcall &)
00308 {
00309 }
00310 }
00311 }
00312
00313 TAO_END_VERSIONED_NAMESPACE_DECL
00314
00315 #endif