1 #include "Client_Task.h"
2 #include "Server_Task.h"
3 #include "ace/Get_Opt.h"
4 #include "tao/Messaging/Messaging.h"
5 #include "tao/Transport_Cache_Manager.h"
6 #include "tao/Transport.h"
7 #include "tao/ORB_Core.h"
8 #include "tao/Thread_Lane_Resources.h"
9 #include "tao/PortableServer/PortableServer.h"
10 #include "tao/AnyTypeCode/Any.h"
12 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
13 int number_of_oneways
= 10;
14 int number_of_client_tasks
= 2;
17 parse_args (int argc
, ACE_TCHAR
*argv
[])
19 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:n:c:"));
22 while ((c
= get_opts ()) != -1)
26 ior
= get_opts
.opt_arg ();
29 number_of_oneways
= ACE_OS::atoi (get_opts
.opt_arg ());
32 number_of_client_tasks
= ACE_OS::atoi (get_opts
.opt_arg ());
36 ACE_ERROR_RETURN ((LM_ERROR
,
39 "-n <number of oneways>"
40 "-c <number of client tasks>"
45 // Indicates successful parsing of the command line
50 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
55 CORBA::ORB_init (argc
, argv
);
57 CORBA::Object_var poa_object
=
58 orb
->resolve_initial_references("RootPOA");
60 if (CORBA::is_nil (poa_object
.in ()))
61 ACE_ERROR_RETURN ((LM_ERROR
,
62 " (%P|%t) Unable to initialize the POA.\n"),
65 PortableServer::POA_var root_poa
=
66 PortableServer::POA::_narrow (poa_object
.in ());
68 PortableServer::POAManager_var poa_manager
=
69 root_poa
->the_POAManager ();
71 CORBA::Object_var object
=
72 orb
->resolve_initial_references ("PolicyCurrent");
74 CORBA::PolicyCurrent_var policy_current
=
75 CORBA::PolicyCurrent::_narrow (object
.in ());
77 if (CORBA::is_nil (policy_current
.in ()))
79 ACE_ERROR ((LM_ERROR
, "ERROR: Nil policy current\n"));
82 CORBA::Any scope_as_any
;
83 scope_as_any
<<= Messaging::SYNC_NONE
;
85 CORBA::PolicyList
policies (1); policies
.length (1);
87 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
89 policy_current
->set_policy_overrides (policies
, CORBA::ADD_OVERRIDE
);
91 policies
[0]->destroy ();
93 if (parse_args (argc
, argv
) != 0)
96 // Get the sender reference..
97 CORBA::Object_var tmp
=
98 orb
->string_to_object(ior
);
100 Test::Sender_var sender
=
101 Test::Sender::_narrow(tmp
.in ());
103 if (CORBA::is_nil (sender
.in ()))
105 ACE_ERROR_RETURN ((LM_DEBUG
,
106 "Nil coordinator reference <%s>\n",
111 Client_Task
client_task (orb
.in(),
113 ACE_Thread_Manager::instance (),
116 Server_Task
server_task (orb
.in (),
117 ACE_Thread_Manager::instance ());
119 // Before creating threads we will let the sender know that we
120 // will have two threads that would make invocations..
121 // this is the first oneway we do, so after this we would have a queue
122 // on one of the transports
123 sender
->active_objects ((CORBA::Short
) number_of_client_tasks
);
125 TAO::Transport_Cache_Manager
& manager
= orb
->orb_core()->lane_resources ().transport_cache ();
127 TAO::Transport_Cache_Manager::HASH_MAP
& cachemap
= manager
.map();
128 TAO::Transport_Cache_Manager::HASH_MAP_ITER end_iter
= cachemap
.end ();
130 bool tranportwithqueue
= false;
131 for (TAO::Transport_Cache_Manager::HASH_MAP_ITER iter
= cachemap
.begin ();
135 TAO_Transport
* transport
= (*iter
).int_id_
.transport ();
136 if (transport
->queue_is_empty() == 0 && transport
->is_connected() == false)
138 tranportwithqueue
= true;
143 if (!tranportwithqueue
)
145 ACE_ERROR ((LM_ERROR
, "(%P|%t) Error: expect a not connected transport with a queue\n"));
149 ACE_DEBUG((LM_DEBUG
, "(%P|%t) Found not connected transport with a queue\n"));
152 if (server_task
.activate (THR_NEW_LWP
| THR_JOINABLE
, 2,1) == -1)
154 ACE_ERROR ((LM_ERROR
, "Error activating server task\n"));
157 if (client_task
.activate (THR_NEW_LWP
| THR_JOINABLE
, number_of_client_tasks
, 1) == -1)
159 ACE_ERROR ((LM_ERROR
, "Error activating client task\n"));
162 ACE_Thread_Manager::instance ()->wait ();
164 ACE_DEBUG ((LM_DEBUG
,
165 "Event Loop finished\n"));
169 if (tranportwithqueue
== false)
174 catch (const CORBA::Exception
& ex
)
176 ex
._tao_print_exception ("Exception caught:");