1 #include "tao/RTPortableServer/RT_Collocation_Resolver.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/ORB_Core.h"
6 #include "tao/ORB_Core_TSS_Resources.h"
7 #include "tao/Object.h"
9 #include "tao/PortableServer/Servant_Upcall.h"
10 #include "tao/PortableServer/Root_POA.h"
11 #include "tao/RTCORBA/Thread_Pool.h"
12 #include "tao/Profile.h"
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 TAO_RT_Collocation_Resolver::is_collocated (CORBA::Object_ptr object
) const
19 // Make sure that the servant is in the same ORB that created this
21 if (!object
->_is_collocated ())
25 TAO_ORB_Core
*orb_core
= object
->_stubobj ()->servant_orb_var ()->orb_core ();
27 // Lookup the target POA. Note that Object Adapter lock is held
28 // until <servant_upcall> dies.
29 TAO::Portable_Server::Servant_Upcall
servant_upcall (orb_core
);
31 servant_upcall
.lookup_POA (object
->_stubobj ()->object_key ());
33 // Get the thread pool associated with this POA.
34 TAO_Thread_Pool
*target_thread_pool
=
35 static_cast <TAO_Thread_Pool
*> (poa
->thread_pool ());
37 // If the target POA does not have a dedicated thread pool, then all
38 // calls to it are collocated.
39 if (target_thread_pool
== 0)
42 /// Get the ORB_Core's TSS resources.
43 TAO_ORB_Core_TSS_Resources
&tss
=
44 *orb_core
->get_tss_resources ();
46 // Get the lane for this thread.
47 TAO_Thread_Lane
*current_thread_lane
=
48 static_cast <TAO_Thread_Lane
*> (tss
.lane_
);
50 TAO_Thread_Pool
*current_thread_pool
= 0;
52 // If we don't have a lane, we don't have a pool.
53 if (current_thread_lane
)
55 ¤t_thread_lane
->pool ();
57 // If the pools don't match, then the current thread belongs to a
58 // different pool than POA. Therefore, this object is not
60 if (current_thread_pool
!= target_thread_pool
)
63 // If the current thread and the POA are in the default thread pool,
64 // then the object is collocated.
65 if (current_thread_pool
== 0)
68 // If the current thread and the POA are in a thread pool without
69 // lanes, then the object is collocated.
70 if (!current_thread_pool
->with_lanes ())
73 // Grab the priority model used by the POA. Note that this cannot
74 // be NOT_SPECIFIED because NOT_SPECIFIED is not allowed with thread
76 TAO::Portable_Server::Cached_Policies::PriorityModel priority_model
=
77 poa
->priority_model ();
79 // If the policy is CLIENT_PROPAGATED, then we are collocated
80 // because the current thread is of the correct priority :-) and
81 // we'll simple use the current thread to run the upcall.
82 if (priority_model
== TAO::Portable_Server::Cached_Policies::CLIENT_PROPAGATED
)
85 // Find the target servant priority. We are really not interested in the
86 // servant itself but in the priority that this servant will run at.
87 CORBA::Short target_priority
;
89 if (-1 == poa
->find_servant_priority (servant_upcall
.system_id_
,
95 // If it matches the current thread's priority, then we are
96 // collocated. Otherwise we are not.
97 if (target_priority
== current_thread_lane
->lane_priority ())
104 ACE_STATIC_SVC_DEFINE (TAO_RT_Collocation_Resolver
,
105 ACE_TEXT ("RT_Collocation_Resolver"),
107 &ACE_SVC_NAME (TAO_RT_Collocation_Resolver
),
108 ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ
,
110 ACE_FACTORY_DEFINE (TAO_RTPortableServer
, TAO_RT_Collocation_Resolver
)
112 TAO_END_VERSIONED_NAMESPACE_DECL
114 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */