3 #include "ace/OS_NS_time.h"
5 #include "tao/Messaging/Messaging.h"
7 #include "tao/Transport_Cache_Manager.h"
8 #include "tao/ORB_Core.h"
9 #include "tao/Thread_Lane_Resources.h"
10 #include "tao/Base_Transport_Property.h"
12 #include "tao/Profile.h"
13 #include "tao/Transport.h"
14 #include "tao/BiDir_GIOP/BiDirGIOP.h"
17 #include "ace/Synch.h"
19 #include "ace/Get_Opt.h"
21 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
23 class Callback_i
: public POA_Test::CallBack
28 ACE_DEBUG ((LM_DEBUG
,"(%t) Callback_i::method2 called\n"));
32 class Worker
: public ACE_Task_Base
36 Test::Hello_var hello_
;
37 Test::Hello_var asynch_hello_
;
38 Test::CallBack_var callback_
;
44 CORBA::Short message_counter_
;
54 Worker::Worker(int ot
)
63 this->orb_
->destroy();
70 ACE_GUARD_RETURN (ACE_Mutex
, ace_mon
, this->lock_
, 0);
71 if (this->orb_threads_
> 0)
74 hello_
->set_callback(this->callback_
.in());
80 ++this->busy_threads_
;
83 ACE_DEBUG ((LM_DEBUG
, "(%t) starting loop\n"));
84 for (int i
= 0; i
< 40; i
++)
90 ACE_GUARD_RETURN (ACE_Mutex
, ace_mon
, this->lock_
, 0);
91 n
= ++this->message_counter_
;
93 this->asynch_hello_
->method (n
);
95 ACE_Time_Value
udelay(0,400);
96 struct timespec ts
= udelay
;
97 ACE_OS::nanosleep (&ts
);
100 catch (const CORBA::Exception
&ex
)
103 ACE_ERROR ((LM_ERROR
,
104 "(%t) Exception caught: %s after %d invocations\n",
110 ACE_DEBUG ((LM_DEBUG
, "(%t) Did all iterations\n"));
113 ACE_GUARD_RETURN (ACE_Mutex
, ace_mon
, this->lock_
, 0);
114 --this->busy_threads_
;
115 if (this->busy_threads_
)
121 this->orb_
->shutdown();
123 catch (const CORBA::Exception
&)
131 init_callback (Worker
&w
)
133 CORBA::Object_var obj
=
134 w
.orb_
->resolve_initial_references ("RootPOA");
136 if (CORBA::is_nil (obj
.in ()))
137 ACE_ERROR_RETURN ((LM_ERROR
,
138 " (%P|%t) Unable to initialize the POA.\n"),
141 PortableServer::POA_var root_poa
=
142 PortableServer::POA::_narrow (obj
.in ());
144 PortableServer::POAManager_var poa_manager
=
145 root_poa
->the_POAManager ();
147 // Policies for the childPOA to be created.
148 CORBA::PolicyList
policies (1);
152 pol
<<= BiDirPolicy::BOTH
;
154 w
.orb_
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
157 // Create POA as child of RootPOA with the above policies. This POA
158 // will receive request in the same connection in which it sent
160 PortableServer::POA_var child_poa
=
161 root_poa
->create_POA ("childPOA",
166 Callback_i
*servant
= new Callback_i
;
167 PortableServer::ServantBase_var owner
= servant
;
169 PortableServer::ObjectId_var id
= child_poa
->activate_object (servant
);
170 obj
= child_poa
->id_to_reference (id
.in());
171 w
.callback_
= Test::CallBack::_narrow(obj
.in());
173 // Creation of childPOA is over. Destroy the Policy objects.
174 for (CORBA::ULong i
= 0;
175 i
< policies
.length ();
178 policies
[i
]->destroy ();
181 poa_manager
->activate ();
188 parse_args (int argc
, ACE_TCHAR
*argv
[])
190 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
193 while ((c
= get_opts ()) != -1)
197 ior
= get_opts
.opt_arg ();
202 ACE_ERROR_RETURN ((LM_ERROR
,
209 // Indicates successful parsing of the command line
214 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
216 static const int orb_threads
= 5;
217 static const int total_threads
= 15;
219 // It must be ensured that there are more total threads that there are
220 // that are dedicated to running the ORB.
221 ACE_ASSERT (total_threads
> orb_threads
);
223 Worker
worker (orb_threads
);
227 CORBA::ORB_init (argc
, argv
, "test");
229 if (parse_args (argc
, argv
) != 0)
232 ACE_DEBUG ((LM_DEBUG
,"using ior = %s\n",ior
));
234 CORBA::Object_var tmp
= worker
.orb_
->string_to_object(ior
);
236 if (CORBA::is_nil (tmp
.in ()))
238 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid IOR.\n")
241 worker
.hello_
= Test::Hello::_narrow(tmp
.in ());
243 if (CORBA::is_nil (worker
.hello_
.in ()))
245 ACE_ERROR_RETURN ((LM_ERROR
,
246 "Nil Test::Hello reference <%s>\n",
251 // bool x = worker.hello_->_non_existent();
252 // ACE_DEBUG ((LM_DEBUG, "_non_existent returned %d\n",x));
255 // Set the Synch Scopes
257 CORBA::Any scope_as_any
;
259 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Applying SYNC_NONE.\n"));
260 scope_as_any
<<= Messaging::SYNC_NONE
;
261 CORBA::PolicyList
policies (1);
264 worker
.orb_
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
267 ACE_DEBUG ((LM_DEBUG
,
268 "(%P|%t) - Applying Synch Scope at Object level.\n"));
269 tmp
= tmp
->_set_policy_overrides (policies
, CORBA::SET_OVERRIDE
);
270 policies
[0]->destroy ();
273 worker
.asynch_hello_
= Test::Hello::_narrow(tmp
.in ());
275 if (CORBA::is_nil (worker
.asynch_hello_
.in ())) {
276 ACE_ERROR_RETURN ((LM_ERROR
,
277 "Nil Test::Hello reference <%s>\n",
282 init_callback(worker
);
285 catch (const CORBA::Exception
&ex
)
287 ACE_ERROR ((LM_ERROR
, "Exception caught: %s\"%s\"\n"
288 , ex
._name(), ex
._rep_id ()));
292 worker
.activate (THR_NEW_LWP
| THR_JOINABLE
, total_threads
);