1 #include "RPS_Monitor.h"
2 #include "ServerRequestInterceptor.h"
4 #include "tao/ORB_Constants.h"
5 #include "ace/OS_NS_sys_time.h"
7 RPS_Monitor::RPS_Monitor (ServerRequestInterceptor
* interceptor
)
9 interceptor_ (interceptor
),
10 last_time_ (ACE_OS::gettimeofday ()),
13 this->location_
.length (1);
15 ACE_Utils::UUID_GENERATOR::instance ()->init ();
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_
),
35 CORBA::SystemException::_tao_minor_code (
38 CORBA::COMPLETED_NO
));
43 CosLoadBalancing::LoadList
*
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),
63 CORBA::SystemException::_tao_minor_code (
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.
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 ();