2 //=============================================================================
6 * This program tests that multiple calls to the Servant Locator
7 * can take place simultaneously.
9 * @author Irfan Pyarali
11 //=============================================================================
15 #include "tao/PortableServer/ServantLocatorC.h"
22 public virtual POA_test
25 test_i (PortableServer::POA_ptr poa
);
33 PortableServer::POA_var poa_
;
36 test_i::test_i (PortableServer::POA_ptr poa
)
37 : poa_ (PortableServer::POA::_duplicate (poa
))
44 ACE_DEBUG ((LM_DEBUG
, "executing normal\n"));
48 test_i::exceptional ()
50 ACE_DEBUG ((LM_DEBUG
, "executing exceptional\n"));
54 test_i::notexisting ()
56 ACE_DEBUG ((LM_DEBUG
, "executing notexisting\n"));
59 class Servant_Locator
:
60 public PortableServer::ServantLocator
63 Servant_Locator (PortableServer::POA_ptr poa
);
65 ::PortableServer::Servant
preinvoke (const PortableServer::ObjectId
&,
66 PortableServer::POA_ptr
,
68 PortableServer::ServantLocator::Cookie
&);
70 void postinvoke (const PortableServer::ObjectId
&,
71 PortableServer::POA_ptr
,
73 PortableServer::ServantLocator::Cookie
,
74 PortableServer::Servant
);
79 Servant_Locator::Servant_Locator (PortableServer::POA_ptr poa
)
84 ::PortableServer::Servant
85 Servant_Locator::preinvoke (const PortableServer::ObjectId
&oid
,
86 PortableServer::POA_ptr
,
88 PortableServer::ServantLocator::Cookie
&)
90 CORBA::String_var name
=
91 PortableServer::ObjectId_to_string (oid
);
94 "Servant_Locator::preinvoke for %C.%C ",
97 if (ACE_OS::strcmp (op
, "normal") == 0)
99 ACE_DEBUG ((LM_DEBUG
, "returning servant\n"));
100 return &this->servant_
;
102 else if (ACE_OS::strcmp (op
, "exceptional") == 0)
104 ACE_DEBUG ((LM_DEBUG
, "throwing exception\n"));
105 throw CORBA::INTERNAL();
109 ACE_DEBUG ((LM_DEBUG
, "returning NULL\n"));
115 Servant_Locator::postinvoke (const PortableServer::ObjectId
&oid
,
116 PortableServer::POA_ptr
,
118 PortableServer::ServantLocator::Cookie
,
119 PortableServer::Servant
)
122 CORBA::String_var name
=
123 PortableServer::ObjectId_to_string (oid
);
131 ACE_DEBUG ((LM_DEBUG
,
132 "Servant_Locator::postinvoke for %C.%C\n",
137 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
142 CORBA::ORB_init (argc
, argv
);
144 CORBA::Object_var obj
=
145 orb
->resolve_initial_references ("RootPOA");
147 PortableServer::POA_var root_poa
=
148 PortableServer::POA::_narrow (obj
.in ());
150 PortableServer::POAManager_var poa_manager
=
151 root_poa
->the_POAManager ();
153 poa_manager
->activate ();
155 CORBA::PolicyList policies
;
156 CORBA::ULong current_length
= 0;
158 policies
.length (current_length
+ 1);
159 policies
[current_length
++] =
160 root_poa
->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER
);
162 policies
.length (current_length
+ 1);
163 policies
[current_length
++] =
164 root_poa
->create_servant_retention_policy (PortableServer::NON_RETAIN
);
166 policies
.length (current_length
+ 1);
167 policies
[current_length
++] =
168 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
170 PortableServer::POA_var child_poa
=
171 root_poa
->create_POA ("child",
175 Servant_Locator
servant_locator (child_poa
.in ());
176 child_poa
->set_servant_manager (&servant_locator
);
178 PortableServer::ObjectId_var objectID
=
179 PortableServer::string_to_ObjectId ("object");
181 CORBA::Object_var objectREF
=
182 child_poa
->create_reference_with_id (objectID
.in (),
185 test_var testObject
=
186 test::_narrow (objectREF
.in ());
188 testObject
->normal();
193 testObject
->exceptional();
195 catch (const CORBA::Exception
&)
197 ACE_DEBUG ((LM_DEBUG
, "exceptional() yielded exception\n"));
200 if (!caught
) ++errorCount
;
205 testObject
->notexisting();
207 catch (const CORBA::Exception
&)
209 ACE_DEBUG ((LM_DEBUG
, "notexisting() yielded exception\n"));
212 if (!caught
) ++errorCount
;
216 catch (const CORBA::Exception
& ex
)
218 ex
._tao_print_exception ("Exception caught");
224 ACE_DEBUG ((LM_DEBUG
,"test successful\n"));
228 ACE_DEBUG ((LM_DEBUG
,"unsuccessfull: %d errors\n", errorCount
));