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
);
99 catch (const CORBA::Exception
&ex
)
102 ACE_ERROR ((LM_ERROR
,
103 "(%t) Exception caught: %s after %d invocations\n",
109 ACE_DEBUG ((LM_DEBUG
, "(%t) Did all iterations\n"));
112 ACE_GUARD_RETURN (ACE_Mutex
, ace_mon
, this->lock_
, 0);
113 --this->busy_threads_
;
114 if (this->busy_threads_
)
120 this->orb_
->shutdown();
122 catch (const CORBA::Exception
&)
130 init_callback (Worker
&w
)
132 CORBA::Object_var obj
=
133 w
.orb_
->resolve_initial_references ("RootPOA");
135 if (CORBA::is_nil (obj
.in ()))
136 ACE_ERROR_RETURN ((LM_ERROR
,
137 " (%P|%t) Unable to initialize the POA.\n"),
140 PortableServer::POA_var root_poa
=
141 PortableServer::POA::_narrow (obj
.in ());
143 PortableServer::POAManager_var poa_manager
=
144 root_poa
->the_POAManager ();
146 // Policies for the childPOA to be created.
147 CORBA::PolicyList
policies (1);
151 pol
<<= BiDirPolicy::BOTH
;
153 w
.orb_
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
156 // Create POA as child of RootPOA with the above policies. This POA
157 // will receive request in the same connection in which it sent
159 PortableServer::POA_var child_poa
=
160 root_poa
->create_POA ("childPOA",
165 Callback_i
*servant
= new Callback_i
;
166 PortableServer::ServantBase_var owner
= servant
;
168 PortableServer::ObjectId_var id
= child_poa
->activate_object (servant
);
169 obj
= child_poa
->id_to_reference (id
.in());
170 w
.callback_
= Test::CallBack::_narrow(obj
.in());
172 // Creation of childPOA is over. Destroy the Policy objects.
173 for (CORBA::ULong i
= 0;
174 i
< policies
.length ();
177 policies
[i
]->destroy ();
180 poa_manager
->activate ();
187 parse_args (int argc
, ACE_TCHAR
*argv
[])
189 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
192 while ((c
= get_opts ()) != -1)
196 ior
= get_opts
.opt_arg ();
201 ACE_ERROR_RETURN ((LM_ERROR
,
208 // Indicates successful parsing of the command line
213 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
215 static const int orb_threads
= 5;
216 static const int total_threads
= 15;
218 // It must be ensured that there are more total threads that there are
219 // that are dedicated to running the ORB.
220 ACE_ASSERT (total_threads
> orb_threads
);
222 Worker
worker (orb_threads
);
226 CORBA::ORB_init (argc
, argv
, "test");
228 if (parse_args (argc
, argv
) != 0)
231 ACE_DEBUG ((LM_DEBUG
,"using ior = %s\n",ior
));
233 CORBA::Object_var tmp
= worker
.orb_
->string_to_object(ior
);
235 if (CORBA::is_nil (tmp
.in ()))
237 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid IOR.\n")
240 worker
.hello_
= Test::Hello::_narrow(tmp
.in ());
242 if (CORBA::is_nil (worker
.hello_
.in ()))
244 ACE_ERROR_RETURN ((LM_ERROR
,
245 "Nil Test::Hello reference <%s>\n",
250 // bool x = worker.hello_->_non_existent();
251 // ACE_DEBUG ((LM_DEBUG, "_non_existent returned %d\n",x));
254 // Set the Synch Scopes
256 CORBA::Any scope_as_any
;
258 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) - Applying SYNC_NONE.\n"));
259 scope_as_any
<<= Messaging::SYNC_NONE
;
260 CORBA::PolicyList
policies (1);
263 worker
.orb_
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
266 ACE_DEBUG ((LM_DEBUG
,
267 "(%P|%t) - Applying Synch Scope at Object level.\n"));
268 tmp
= tmp
->_set_policy_overrides (policies
, CORBA::SET_OVERRIDE
);
269 policies
[0]->destroy ();
272 worker
.asynch_hello_
= Test::Hello::_narrow(tmp
.in ());
274 if (CORBA::is_nil (worker
.asynch_hello_
.in ())) {
275 ACE_ERROR_RETURN ((LM_ERROR
,
276 "Nil Test::Hello reference <%s>\n",
281 init_callback(worker
);
283 catch (const CORBA::Exception
&ex
)
285 ACE_ERROR ((LM_ERROR
, "Exception caught: %s\"%s\"\n"
286 , ex
._name(), ex
._rep_id ()));
290 worker
.activate (THR_NEW_LWP
| THR_JOINABLE
, total_threads
);