Updated logging to include the class/method so that it is more obvious where these...
[ACE_TAO.git] / TAO / tao / PortableServer / RequestProcessingStrategyDefaultServant.cpp
blobcd58b8697d95f218cb49e0d95c2a5e5e715025a9
1 // -*- C++ -*-
2 #include "tao/orbconf.h"
4 #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) && !defined (CORBA_E_MICRO)
6 #include "tao/ORB_Constants.h"
7 #include "tao/TSS_Resources.h"
8 #include "tao/PortableServer/RequestProcessingStrategyDefaultServant.h"
9 #include "tao/PortableServer/Non_Servant_Upcall.h"
10 #include "tao/PortableServer/Root_POA.h"
11 #include "tao/PortableServer/ServantManagerC.h"
12 #include "tao/PortableServer/Servant_Base.h"
13 #include "tao/PortableServer/POA_Current_Impl.h"
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 namespace TAO
19 namespace Portable_Server
21 RequestProcessingStrategyDefaultServant::RequestProcessingStrategyDefaultServant ()
22 : default_servant_ (0)
26 void
27 RequestProcessingStrategyDefaultServant::strategy_cleanup()
29 this->default_servant_ = 0;
32 PortableServer::ServantManager_ptr
33 RequestProcessingStrategyDefaultServant::get_servant_manager ()
35 throw PortableServer::POA::WrongPolicy ();
38 void
39 RequestProcessingStrategyDefaultServant::set_servant_manager (
40 PortableServer::ServantManager_ptr /*imgr*/)
42 throw PortableServer::POA::WrongPolicy ();
45 PortableServer::Servant
46 RequestProcessingStrategyDefaultServant::get_servant ()
48 // This operation returns the default servant associated with the
49 // POA.
50 return this->default_servant_.in ();
53 void
54 RequestProcessingStrategyDefaultServant::set_servant (
55 PortableServer::Servant servant)
57 // This operation registers the specified servant with the POA as
58 // the default servant. This servant will be used for all requests
59 // for which no servant is found in the Active Object Map.
60 this->default_servant_ = servant;
62 // The implementation of set_servant will invoke _add_ref at least
63 // once on the Servant argument before returning. When the POA no
64 // longer needs the Servant, it will invoke _remove_ref on it the
65 // same number of times.
66 if (servant != 0)
68 // A recursive thread lock without using a recursive thread
69 // lock. Non_Servant_Upcall has a magic constructor and
70 // destructor. We unlock the Object_Adapter lock for the
71 // duration of the servant activator upcalls; reacquiring once
72 // the upcalls complete. Even though we are releasing the lock,
73 // other threads will not be able to make progress since
74 // <Object_Adapter::non_servant_upcall_in_progress_> has been
75 // set.
76 Non_Servant_Upcall non_servant_upcall (*this->poa_);
77 ACE_UNUSED_ARG (non_servant_upcall);
79 servant->_add_ref ();
83 TAO_SERVANT_LOCATION
84 RequestProcessingStrategyDefaultServant::locate_servant (
85 const PortableServer::ObjectId & system_id,
86 PortableServer::Servant & servant)
88 TAO_SERVANT_LOCATION location = TAO_SERVANT_NOT_FOUND;
90 location = this->poa_->servant_present (system_id, servant);
92 if (location == TAO_SERVANT_NOT_FOUND)
94 if (this->default_servant_.in () != 0)
96 location = TAO_DEFAULT_SERVANT;
100 return location;
103 PortableServer::Servant
104 RequestProcessingStrategyDefaultServant::locate_servant (
105 const char * /*operation*/,
106 const PortableServer::ObjectId & system_id,
107 TAO::Portable_Server::Servant_Upcall &servant_upcall,
108 TAO::Portable_Server::POA_Current_Impl &poa_current_impl,
109 bool & /*wait_occurred_restart_call*/)
111 PortableServer::Servant servant = 0;
113 servant = this->poa_->find_servant (system_id,
114 servant_upcall,
115 poa_current_impl);
117 if (servant == 0)
119 // If the POA has the USE_DEFAULT_SERVANT policy, a default servant
120 // has been associated with the POA so the POA will invoke the
121 // appropriate method on that servant. If no servant has been
122 // associated with the POA, the POA raises the OBJ_ADAPTER system
123 // exception.
124 PortableServer::Servant default_servant = this->default_servant_.in ();
125 if (default_servant == 0)
127 throw ::CORBA::OBJ_ADAPTER (
128 CORBA::OMGVMCID | 3,
129 CORBA::COMPLETED_NO);
131 else
133 // Success
134 servant = default_servant;
138 return servant;
141 PortableServer::Servant
142 RequestProcessingStrategyDefaultServant::system_id_to_servant (
143 const PortableServer::ObjectId &system_id)
145 PortableServer::Servant servant = this->default_servant_.in ();
147 if (servant == 0)
149 servant = this->poa_->find_servant (system_id);
152 return servant;
155 PortableServer::Servant
156 RequestProcessingStrategyDefaultServant::id_to_servant (
157 const PortableServer::ObjectId & /*id*/)
159 PortableServer::Servant servant = this->default_servant_.in ();
161 if (servant == 0)
164 * If using default servant request processing strategy but
165 * no default servant is available, we will raise the
166 * ObjectNotActive system exception.
168 throw PortableServer::POA::ObjectNotActive ();
171 return servant;
174 void
175 RequestProcessingStrategyDefaultServant::cleanup_servant (
176 PortableServer::Servant servant,
177 const PortableServer::ObjectId &user_id)
179 if (servant)
181 // ATTENTION: Trick locking here, see class header for details
182 Non_Servant_Upcall non_servant_upcall (*this->poa_);
183 ACE_UNUSED_ARG (non_servant_upcall);
187 servant->_remove_ref ();
189 catch (...)
191 // Ignore exceptions from servant cleanup.
195 // This operation causes the association of the Object Id specified
196 // by the oid parameter and its servant to be removed from the
197 // Active Object Map.
198 if (this->poa_->unbind_using_user_id (user_id) != 0)
200 throw ::CORBA::OBJ_ADAPTER ();
204 void
205 RequestProcessingStrategyDefaultServant::etherealize_objects (
206 CORBA::Boolean /*etherealize_objects*/)
210 PortableServer::ObjectId *
211 RequestProcessingStrategyDefaultServant::servant_to_id (
212 PortableServer::Servant servant)
214 PortableServer::Servant default_servant = this->default_servant_.in ();
216 if (default_servant != 0 &&
217 default_servant == servant)
219 // If they are the same servant, then check if we are in an
220 // upcall.
221 TAO::Portable_Server::POA_Current_Impl *poa_current_impl =
222 static_cast <TAO::Portable_Server::POA_Current_Impl *>
223 (TAO_TSS_Resources::instance ()->poa_current_impl_);
224 // If we are in an upcall on the default servant, return the
225 // ObjectId associated with the current invocation.
226 if (poa_current_impl != 0 &&
227 servant == poa_current_impl->servant ())
229 return poa_current_impl->get_object_id ();
233 return this->poa_->servant_to_user_id (servant);
236 void
237 RequestProcessingStrategyDefaultServant::post_invoke_servant_cleanup(
238 const PortableServer::ObjectId &/*system_id*/,
239 const TAO::Portable_Server::Servant_Upcall &/*servant_upcall*/)
243 ::PortableServer::RequestProcessingPolicyValue
244 RequestProcessingStrategyDefaultServant::type() const
246 return ::PortableServer::USE_DEFAULT_SERVANT;
251 TAO_END_VERSIONED_NAMESPACE_DECL
253 #endif /* TAO_HAS_MINIMUM_POA == 0 */