Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / examples / LoadBalancing / RPS_Monitor.cpp
blobe004a72cedbe7cb51d92cd4384d338c43a3749e3
1 #include "RPS_Monitor.h"
2 #include "ServerRequestInterceptor.h"
3 #include "ace/UUID.h"
4 #include "tao/ORB_Constants.h"
5 #include "ace/OS_NS_sys_time.h"
7 RPS_Monitor::RPS_Monitor (ServerRequestInterceptor * interceptor)
8 : location_ (1),
9 interceptor_ (interceptor),
10 last_time_ (ACE_OS::gettimeofday ()),
11 lock_ ()
13 this->location_.length (1);
15 ACE_Utils::UUID_GENERATOR::instance ()->init ();
17 ACE_Utils::UUID uuid;
18 ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID (uuid);
20 this->location_[0].id = CORBA::string_dup (uuid.to_string ()->c_str ());
21 this->location_[0].kind = CORBA::string_dup ("UUID");
24 RPS_Monitor::~RPS_Monitor ()
28 CosLoadBalancing::Location *
29 RPS_Monitor::the_location ()
31 CosLoadBalancing::Location * location;
32 ACE_NEW_THROW_EX (location,
33 CosLoadBalancing::Location (this->location_),
34 CORBA::NO_MEMORY (
35 CORBA::SystemException::_tao_minor_code (
36 TAO::VMCID,
37 ENOMEM),
38 CORBA::COMPLETED_NO));
40 return location;
43 CosLoadBalancing::LoadList *
44 RPS_Monitor::loads ()
46 const ACE_Time_Value current_time = ACE_OS::gettimeofday ();
48 ACE_Time_Value elapsed_time;
51 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, monitor, this->lock_, 0);
53 elapsed_time = current_time - this->last_time_;
54 this->last_time_ = current_time;
57 const CORBA::Long request_count = this->interceptor_->request_count ();
59 CosLoadBalancing::LoadList * tmp;
60 ACE_NEW_THROW_EX (tmp,
61 CosLoadBalancing::LoadList (1),
62 CORBA::NO_MEMORY (
63 CORBA::SystemException::_tao_minor_code (
64 TAO::VMCID,
65 ENOMEM),
66 CORBA::COMPLETED_NO));
68 CosLoadBalancing::LoadList_var load_list = tmp;
70 load_list->length (1);
72 load_list[0].id = CosLoadBalancing::RequestsPerSecond;
74 // VC 7.1 gives a warning without an explicit cast.
75 load_list[0].value =
76 static_cast<CORBA::Float> (request_count / elapsed_time.msec () * 1000);
78 // Strictly for debugging or
79 ACE_DEBUG ((LM_DEBUG, "%f\n", load_list[0].value));
81 return load_list._retn ();