Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / LoadBalancing / LoadMonitor / CPU / client.cpp
blobb8ed792c95759aa9b62a40791d8cbe172c910845
1 #include "orbsvcs/CosLoadBalancingC.h"
2 #include "orbsvcs/PortableGroup/PG_Operators.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_unistd.h"
6 const ACE_TCHAR *location = ACE_TEXT("MyLocation");
8 const int MAX_RETRIES = 10;
9 const CosLoadBalancing::LoadId LOAD_ID = CosLoadBalancing::LoadAverage;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("l:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'l':
22 location = get_opts.opt_arg ();
23 break;
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "Usage: %s -l <ior>\n",
28 argv[0]),
29 -1);
32 return 0;
35 void
36 check_loads (const CosLoadBalancing::LoadList & loads)
38 if (loads.length () != 1)
40 ACE_ERROR ((LM_ERROR,
41 "ERROR: Load list length is not equal to one.\n"));
43 throw CORBA::INTERNAL ();
46 if (loads[0].id != LOAD_ID
47 || loads[0].value < 0)
49 ACE_ERROR ((LM_ERROR,
50 "ERROR: Returned load is not a CPU load.\n"));
52 throw CORBA::INTERNAL ();
56 int
57 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
59 try
61 CORBA::ORB_var orb =
62 CORBA::ORB_init (argc, argv);
64 // Obtain a reference to the LoadManager.
65 CORBA::Object_var obj =
66 orb->resolve_initial_references ("LoadManager");
68 CosLoadBalancing::LoadManager_var lm =
69 CosLoadBalancing::LoadManager::_narrow (obj.in ());
71 CosLoadBalancing::Location the_location (1);
72 the_location.length (1);
74 the_location[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(location));
76 // Attempt to get loads from the LoadManager.
77 ACE_DEBUG ((LM_INFO,
78 "\n"
79 "Retrieving loads from LoadManager ..."));
81 CosLoadBalancing::LoadList_var loads;
83 CORBA::Boolean retrieved_load = false;
85 // Try a few times until a load is capable of being retrieved.
86 for (int i = 0; i < MAX_RETRIES && retrieved_load == 0; ++i)
88 try
90 loads = lm->get_loads (the_location);
92 retrieved_load = 1;
94 catch (const CORBA::Exception&)
96 ACE_DEBUG ((LM_DEBUG, ".")); // Show some progress.
98 // Give some time for loads to be reported to the
99 // LoadManager.
100 ACE_OS::sleep (2);
104 if (retrieved_load == 0)
105 ACE_ERROR_RETURN ((LM_ERROR,
106 "\nERROR: Unable to retrieve loads "
107 "from LoadManager.\n"),
109 else
110 ACE_DEBUG ((LM_INFO,
111 " DONE\n"));
113 ::check_loads (loads.in ());
115 // Attempt to get loads directly from the LoadMonitor.
116 CosLoadBalancing::LoadMonitor_var monitor =
117 lm->get_load_monitor (the_location);
119 CosLoadBalancing::Location_var cpu_mon_location =
120 monitor->the_location ();
122 if (cpu_mon_location.in () != the_location)
124 ACE_ERROR ((LM_ERROR,
125 "ERROR: Mismatched CPU load monitor location\n"));
127 throw CORBA::INTERNAL ();
130 ACE_DEBUG ((LM_INFO,
131 "Retrieving loads directly from LoadMonitor ..."));
133 loads = monitor->loads ();
135 ACE_DEBUG ((LM_INFO,
136 " DONE\n"));
138 ::check_loads (loads.in ());
140 catch (const CORBA::Exception& ex)
142 ex._tao_print_exception ("CPU Load Monitor test:");
143 return 1;
146 ACE_DEBUG ((LM_INFO, "CPU Load Monitor test passed.\n\n"));
148 return 0;