1 //=============================================================================
3 * @file Identity_Client.cpp
5 * @author Marina Spivak <marina@cs.wustl.edu>
7 //=============================================================================
10 #include "Identity_Client.h"
11 #include "IdentityC.h"
12 #include "Load_BalancerC.h"
13 #include "tao/debug.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/High_Res_Timer.h"
16 #include "ace/Stats.h"
18 Identity_Client::Identity_Client ()
19 : group_factory_ior_ (0),
20 number_of_invocations_ (5),
27 Identity_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
29 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("di:n:k:r"));
32 while ((c
= get_opts ()) != -1)
35 case 'd': // debug flag.
38 case 'i': // ior of the <Object_Group_Factory> object.
39 this->group_factory_ior_
= get_opts
.opt_arg ();
41 case 'n': // number of times to make invocation on an <Identity> object.
42 this->number_of_invocations_
= ACE_OS::atoi (get_opts
.opt_arg ());
45 this->iterations_
= ACE_OS::atoi (get_opts
.opt_arg ());
47 case 'r': // flag signifying to obtain references to <Identity>
48 // objects from the random <Object_Group> rather than
49 // from the round robin one.
50 this->use_random_
= 1;
54 ACE_ERROR_RETURN ((LM_ERROR
,
57 " [-i] <Object_Group_Factory_ior>"
58 " [-n] <number_of_invocations>"
65 // Indicates successful parsing of command line.
70 Identity_Client::init (int argc
, ACE_TCHAR
* argv
[])
76 result
= this->orb_manager_
.init (argc
, argv
);
80 // Check the non-ORB arguments.
81 result
= this->parse_args (argc
, argv
);
85 catch (const CORBA::Exception
& ex
)
87 ex
._tao_print_exception ("Identity_Client::init");
95 Identity_Client::run ()
97 // Contact the <Object_Group_Factory> to obtain an <Object_Group>.
98 CORBA::ORB_var orb
= orb_manager_
.orb ();
99 CORBA::Object_var obj
=
100 orb
->string_to_object (this->group_factory_ior_
);
103 ACE_ERROR_RETURN ((LM_ERROR
,
104 ACE_TEXT ("(%N|%l) <ERROR> [Identity_Client::run]\n")
105 ACE_TEXT ("factory_resolve\n")),
108 Load_Balancer::Object_Group_Factory_var factory
=
109 Load_Balancer::Object_Group_Factory::_narrow (obj
.in ());
111 if (CORBA::is_nil (factory
.in ()))
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 "Identity_Client: problems using the factory ior\n"),
116 const char *group_name
;
117 if (this->use_random_
)
118 group_name
= "Random group";
120 group_name
= "Round Robin group";
122 Load_Balancer::Object_Group_var object_group
;
124 // We have this for the measurement that was done.
125 #if defined (DOORS_MEASURE_STATS)
127 // Performance measurements start here
128 ACE_High_Res_Timer::calibrate ();
130 ACE_hrtime_t throughput_base
= ACE_OS::gethrtime ();
132 ACE_Throughput_Stats throughput
;
133 ACE_High_Res_Timer::global_scale_factor_type gsf
=
134 ACE_High_Res_Timer::global_scale_factor ();
136 for (int i
= 0; i
< this->iterations_
; i
++)
138 // Record current time.
139 ACE_hrtime_t latency_base
= ACE_OS::gethrtime ();
141 #endif /*TAO_MEASURE_STATS*/
144 factory
->resolve (group_name
);
146 CORBA::String_var iorstring
=
147 orb
->object_to_string (object_group
.in ());
149 ACE_DEBUG ((LM_DEBUG
,
150 "The ior string is %s\n", iorstring
.in ()));
151 #if defined (DOORS_MEASURE_STATS)
152 // Grab timestamp again.
153 ACE_hrtime_t now
= ACE_OS::gethrtime ();
155 // Record statistics.
156 throughput
.sample (now
- throughput_base
,
160 ACE_OS::printf ("*=*=*=*=Aggregated result *=*=*=*=*=\n");
161 throughput
.dump_results (ACE_TEXT("Aggregated"), gsf
);
162 #endif /*TAO_MEASURE_STATS */
164 if (CORBA::is_nil (object_group
.in ()))
166 ACE_ERROR_RETURN ((LM_ERROR
,
167 "(%l|%d)The narrowed object is NUL:"),
171 // List <Object_Group>'s id.
172 CORBA::String_var id
= object_group
->id ();
173 ACE_DEBUG ((LM_DEBUG
, "Object Group's id is: %s\n\n", id
.in ()));
175 // List all <Object_Group>s members.
176 Load_Balancer::Member_ID_List_var id_list
=
177 object_group
->members ();
178 ACE_DEBUG ((LM_DEBUG
,
179 "The group contains %d members:\n",
180 id_list
->length ()));
181 for (CORBA::ULong i
= 0; i
< id_list
->length (); ++i
)
182 ACE_DEBUG ((LM_DEBUG
, "%s\n", static_cast<char const*>(id_list
[i
])));
184 // Perform <number_of_invocations_> method calls on <Identity>
185 // objects, which are members of the <Object_Group>. Before each
186 // invocations, we get an <Identity> reference to use for that
187 // invocation from our <Object_Group>.
188 Identity_var identity_object
;
189 CORBA::String_var identity
;
190 CORBA::String_var objref
;
192 for (size_t ind
= 0; ind
< this->number_of_invocations_
; ++ind
)
194 objref
= object_group
->resolve ();
196 obj
= orb
->string_to_object (objref
.in ());
198 identity_object
= Identity::_narrow (obj
.in ());
200 if (CORBA::is_nil (identity_object
.in ()))
201 ACE_ERROR_RETURN ((LM_ERROR
,
202 "Identity_Client: cannot narrow an object received from"
203 "<Object_Group::resolve> to <Identity>\n"),
205 identity_object
->get_name (identity
.out ());
207 ACE_DEBUG ((LM_DEBUG
,
215 Identity_Client::~Identity_Client ()
220 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
223 Identity_Client client
;
225 if (client
.init (argc
, argv
) == -1)
230 result
= client
.run ();
232 catch (const CORBA::Exception
& ex
)
234 ex
._tao_print_exception ("Identity_Client");