2 * @file Table_Adapter.cpp
4 * @author Carlos O'Ryan <coryan@uci.edu>
7 #include "tao/IORTable/Table_Adapter.h"
8 #include "tao/IORTable/IOR_Table_Impl.h"
10 #include "tao/ORB_Core.h"
11 #include "tao/Server_Strategy_Factory.h"
12 #include "tao/Object.h"
15 #include "tao/Profile.h"
16 #include "tao/TAO_Server_Request.h"
18 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
20 TAO_Table_Adapter::TAO_Table_Adapter (TAO_ORB_Core
&orb_core
)
21 : orb_core_ (orb_core
),
25 lock_ (TAO_Table_Adapter::create_lock (thread_lock_
))
29 TAO_Table_Adapter::~TAO_Table_Adapter ()
36 TAO_Table_Adapter::create_lock (TAO_SYNCH_MUTEX
&thread_lock
)
38 ACE_Lock
*the_lock
= 0;
39 ACE_NEW_RETURN (the_lock
,
40 ACE_Lock_Adapter
<TAO_SYNCH_MUTEX
> (thread_lock
),
46 TAO_Table_Adapter::open ()
48 ACE_GUARD (ACE_Lock
, ace_mon
, *this->lock_
);
49 TAO_IOR_Table_Impl
*impl
= 0;
50 ACE_NEW_THROW_EX (impl
,
51 TAO_IOR_Table_Impl (),
55 this->closed_
= false;
59 TAO_Table_Adapter::close (int)
61 ACE_GUARD (ACE_Lock
, ace_mon
, *this->lock_
);
67 TAO_Table_Adapter::check_close (int)
72 TAO_Table_Adapter::priority () const
74 return static_cast<int> (TAO_DEFAULT_ADAPTER_REGISTRY_SIZE
);
78 TAO_Table_Adapter::dispatch (TAO::ObjectKey
&key
,
79 TAO_ServerRequest
&request
,
80 CORBA::Object_out forward_to
)
82 if (this->find_object (key
, forward_to
))
84 request
.forward_location (forward_to
);
85 return TAO_Adapter::DS_FORWARD
;
88 return TAO_Adapter::DS_MISMATCHED_KEY
;
92 TAO_Table_Adapter::name () const
98 TAO_Table_Adapter::root ()
100 return CORBA::Object::_duplicate (this->root_
.in());
104 TAO_Table_Adapter::create_collocated_object (TAO_Stub
*stub
,
105 const TAO_MProfile
&)
107 CORBA::Object_ptr result
= CORBA::Object::_nil ();
109 if (! this->initialize_collocated_object (stub
)) // 0 == success
111 // A reference was found in the table. The stub has been forwarded
112 // to this. The collocation indicators are now correct on the stub
113 // (although they may well now indicate that the stub is not in fact
114 // collocated at all).
115 ACE_NEW_RETURN (result
,
117 stub
->is_collocated (),
118 stub
->collocated_servant ()),
119 CORBA::Object::_nil ());
126 TAO_Table_Adapter::initialize_collocated_object (TAO_Stub
*stub
)
128 // Get the effective profile set.
129 const TAO_MProfile
&mp
= stub
->forward_profiles () ? *(stub
->forward_profiles ())
130 : stub
->base_profiles ();
132 // We only look at the key from the 0th profile but we only really care about
133 // corbaloc's here where all profiles share a single object key
134 TAO::ObjectKey_var key
= mp
.get_profile (j
)->_key ();
136 CORBA::Object_var forward_to
= CORBA::Object::_nil ();
137 CORBA::Boolean found
= false;
141 found
= this->find_object (key
, forward_to
.out ());
143 catch (const ::CORBA::Exception
&)
149 // This call will set the appropriate collocation values
150 // to correspond to the reference we found in the table.
151 stub
->add_forward_profiles (forward_to
->_stubobj ()->base_profiles ());
152 stub
->next_profile ();
160 TAO_Table_Adapter::find_object (TAO::ObjectKey
&key
,
161 CORBA::Object_out forward_to
)
163 TAO_IOR_Table_Impl_var rootref
;
165 ACE_GUARD_RETURN (ACE_Lock
,
173 rootref
= this->root_
;
176 CORBA::String_var object_key
;
177 TAO::ObjectKey::encode_sequence_to_string (object_key
.out (), key
);
180 CORBA::String_var ior
= this->root_
->find (object_key
.in ());
181 forward_to
= this->orb_core_
.orb ()->string_to_object (ior
.in ());
183 catch (const ::IORTable::NotFound
&)
190 // ****************************************************************
192 TAO_Table_Adapter_Factory::TAO_Table_Adapter_Factory ()
197 TAO_Table_Adapter_Factory::create (TAO_ORB_Core
*oc
)
199 TAO_Adapter
* ptr
= 0;
201 TAO_Table_Adapter (*oc
),
206 TAO_END_VERSIONED_NAMESPACE_DECL
208 ACE_FACTORY_DEFINE (TAO_IORTable
, TAO_Table_Adapter_Factory
)
209 ACE_STATIC_SVC_DEFINE (TAO_Table_Adapter_Factory
,
210 ACE_TEXT ("TAO_IORTable"),
212 &ACE_SVC_NAME (TAO_Table_Adapter_Factory
),
213 ACE_Service_Type::DELETE_THIS
| ACE_Service_Type::DELETE_OBJ
,