Updated logging to include the class/method so that it is more obvious where these...
[ACE_TAO.git] / TAO / tao / PortableServer / ServantRetentionStrategyNonRetain.cpp
blobe4e39fbe4bd1f8e3f009e5bc68c2d209cd866eb0
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file ServantRetentionStrategyNonRetain.cpp
6 */
7 //=============================================================================
9 #include "tao/PortableServer/ServantRetentionStrategyNonRetain.h"
10 #include "tao/PortableServer/Non_Servant_Upcall.h"
11 #include "tao/PortableServer/Servant_Upcall.h"
12 #include "tao/PortableServer/POA_Current_Impl.h"
13 #include "tao/PortableServer/Root_POA.h"
14 #include "tao/PortableServer/Servant_Base.h"
15 #include "tao/debug.h"
17 #include "ace/OS_NS_sys_time.h"
18 #include "ace/Time_Value.h"
19 #include "ace/OS_NS_sys_time.h"
21 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
23 namespace TAO
25 namespace Portable_Server
27 ServantRetentionStrategyNonRetain::ServantRetentionStrategyNonRetain () :
28 poa_ (0),
29 sys_id_count_ (0)
33 void
34 ServantRetentionStrategyNonRetain::strategy_init (TAO_Root_POA *poa)
36 poa_ = poa;
39 void
40 ServantRetentionStrategyNonRetain::strategy_cleanup ()
42 poa_ = 0;
45 void
46 ServantRetentionStrategyNonRetain::deactivate_object (
47 const PortableServer::ObjectId &/*id*/)
49 // When using Non_Retain we don't have an active object map and we just
50 // can't deactivate any object
51 throw PortableServer::POA::WrongPolicy ();
54 PortableServer::Servant
55 ServantRetentionStrategyNonRetain::find_servant (
56 const PortableServer::ObjectId &/*system_id*/)
58 throw PortableServer::POA::WrongPolicy ();
61 PortableServer::ObjectId *
62 ServantRetentionStrategyNonRetain::system_id_to_object_id (
63 const PortableServer::ObjectId &system_id)
65 // The system id is the id (and no conversion/transformation is
66 // needed).
67 PortableServer::ObjectId *id = 0;
68 ACE_NEW_THROW_EX (id,
69 PortableServer::ObjectId (system_id),
70 CORBA::NO_MEMORY ());
72 return id;
75 PortableServer::Servant
76 ServantRetentionStrategyNonRetain::user_id_to_servant (
77 const PortableServer::ObjectId &/*id*/)
79 throw PortableServer::POA::WrongPolicy ();
82 CORBA::Object_ptr
83 ServantRetentionStrategyNonRetain::id_to_reference (
84 const PortableServer::ObjectId &/*id*/,
85 bool /*indirect*/)
87 throw PortableServer::POA::WrongPolicy ();
90 TAO_SERVANT_LOCATION
91 ServantRetentionStrategyNonRetain::servant_present (
92 const PortableServer::ObjectId &/*system_id*/,
93 PortableServer::Servant &/*servant*/)
95 return TAO_SERVANT_NOT_FOUND;
98 PortableServer::Servant
99 ServantRetentionStrategyNonRetain::find_servant (
100 const PortableServer::ObjectId &system_id,
101 TAO::Portable_Server::Servant_Upcall &servant_upcall,
102 TAO::Portable_Server::POA_Current_Impl &poa_current_impl)
104 // We have the NON_RETAIN policy, user id is the system id.
106 // Smartly copy all the data; <poa_current_impl.object_id_> does
107 // not own the data.
108 poa_current_impl.replace_object_id (system_id);
110 servant_upcall.user_id (&system_id);
112 return 0;
116 ServantRetentionStrategyNonRetain::find_servant_priority (
117 const PortableServer::ObjectId &/*system_id*/,
118 CORBA::Short &/*priority*/)
120 return -1;
124 ServantRetentionStrategyNonRetain::is_servant_in_map (
125 PortableServer::Servant /*servant*/,
126 bool &/*wait_occurred_restart_call*/)
128 return 0;
131 CORBA::ULong
132 ServantRetentionStrategyNonRetain::waiting_servant_deactivation () const
134 return 0;
137 void
138 ServantRetentionStrategyNonRetain::deactivate_all_objects ()
142 PortableServer::ObjectId *
143 ServantRetentionStrategyNonRetain::servant_to_user_id (
144 PortableServer::Servant /*servant*/)
146 throw PortableServer::POA::WrongPolicy ();
149 CORBA::Object_ptr
150 ServantRetentionStrategyNonRetain::servant_to_reference (
151 PortableServer::Servant /*servant*/)
153 throw PortableServer::POA::WrongPolicy ();
156 PortableServer::ObjectId *
157 ServantRetentionStrategyNonRetain::activate_object (
158 PortableServer::Servant /*servant*/,
159 CORBA::Short /*priority*/,
160 bool &/*wait_occurred_restart_call*/)
162 throw PortableServer::POA::WrongPolicy ();
165 void
166 ServantRetentionStrategyNonRetain::activate_object_with_id (
167 const PortableServer::ObjectId &/*id*/,
168 PortableServer::Servant /*servant*/,
169 CORBA::Short /*priority*/,
170 bool &/*wait_occurred_restart_call*/)
172 throw PortableServer::POA::WrongPolicy ();
175 CORBA::Object_ptr
176 ServantRetentionStrategyNonRetain::create_reference (
177 const char *intf,
178 CORBA::Short priority)
180 // This operation creates an object reference that encapsulates a
181 // POA-generated Object Id value and the specified interface
182 // repository id. This operation does not cause an activation to
183 // take place. The resulting reference may be passed to clients, so
184 // that subsequent requests on those references will cause the
185 // appropriate servant manager to be invoked, if one is
186 // available. The generated Object Id value may be obtained by
187 // invoking POA::reference_to_id with the created reference.
189 PortableServer::ObjectId_var system_id;
190 PortableServer::ObjectId user_id;
192 // Otherwise, it is the NON_RETAIN policy. Therefore, any ol'
193 // object id will do (even an empty one). However, to make an
194 // object id useful for discriminating objects in applications
195 // use a simple id of a counter and a time stamp. The use of a
196 // counter by itself is not sufficient for uniqueness over time
197 // and a timestamp isn't sufficient since multiple IDs may be
198 // requested within the same time unit.
200 PortableServer::ObjectId *sys_id = 0;
201 ACE_NEW_THROW_EX (sys_id,
202 PortableServer::ObjectId (8),
203 CORBA::NO_MEMORY ());
205 sys_id->length(8);
207 long count = this->sys_id_count_++;
208 ACE_Time_Value now = ACE_OS::gettimeofday();
210 ACE_UINT32 *id_ptr = reinterpret_cast<ACE_UINT32 *>(sys_id->get_buffer());
212 *(id_ptr++) = count;
213 *id_ptr = static_cast<ACE_UINT32>(now.sec());
215 system_id = sys_id;
217 // User id is the same as system id.
218 user_id = system_id.in ();
220 // Remember params for potentially invoking <key_to_object> later.
221 this->poa_->key_to_object_params_.set (system_id,
222 intf,
225 priority,
226 true);
228 return this->poa_->invoke_key_to_object_helper_i (intf, user_id);
231 #if !defined (CORBA_E_MICRO)
232 CORBA::Object_ptr
233 ServantRetentionStrategyNonRetain::create_reference_with_id (
234 const PortableServer::ObjectId &oid,
235 const char *intf,
236 CORBA::Short priority)
238 // This operation creates an object reference that encapsulates the
239 // specified Object Id and interface repository Id values. This
240 // operation does not cause an activation to take place. The
241 // resulting reference may be passed to clients, so that subsequent
242 // requests on those references will cause the object to be
243 // activated if necessary, or the default servant used, depending on
244 // the applicable policies.
246 PortableServer::Servant servant = 0;
247 PortableServer::ObjectId_var system_id;
249 // Otherwise, it is the NON_RETAIN policy. Therefore, user id
250 // is the same as system id.
251 PortableServer::ObjectId *sys_id = 0;
252 ACE_NEW_THROW_EX (sys_id,
253 PortableServer::ObjectId (oid),
254 CORBA::NO_MEMORY ());
256 system_id = sys_id;
258 // Remember params for potentially invoking <key_to_object> later.
259 this->poa_->key_to_object_params_.set (system_id,
260 intf,
261 servant,
263 priority,
264 true);
266 return this->poa_->invoke_key_to_object_helper_i (intf, oid);
268 #endif
271 ServantRetentionStrategyNonRetain::rebind_using_user_id_and_system_id (
272 PortableServer::Servant /*servant*/,
273 const PortableServer::ObjectId &/*user_id*/,
274 const PortableServer::ObjectId &/*system_id*/,
275 TAO::Portable_Server::Servant_Upcall &/*servant_upcall*/)
277 return -1;
280 CORBA::Boolean
281 ServantRetentionStrategyNonRetain::servant_has_remaining_activations (
282 PortableServer::Servant /*servant*/)
284 return false;
288 ServantRetentionStrategyNonRetain::unbind_using_user_id (
289 const PortableServer::ObjectId &/*user_id*/)
291 return 0;
294 ::PortableServer::ServantRetentionPolicyValue
295 ServantRetentionStrategyNonRetain::type() const
297 return ::PortableServer::NON_RETAIN;
300 TAO_Active_Object_Map *
301 ServantRetentionStrategyNonRetain::get_active_object_map() const
303 return 0;
308 TAO_END_VERSIONED_NAMESPACE_DECL