#include <Timer_Helper.h>
Inheritance diagram for Timer_Helper:
Public Member Functions | |
Timer_Helper (void) | |
Constructor. | |
~Timer_Helper (void) | |
Destructor. | |
Timer_Helper (TAO_Time_Service_Clerk *clerk) | |
Constructor that sets the clerk. | |
int | handle_timeout (const ACE_Time_Value &time, const void *arg) |
Protected Types | |
typedef ACE_Array_Base< CosTime::TimeService_var > | IORS |
The set of server IORs. | |
Protected Attributes | |
TAO_Time_Service_Clerk * | clerk_ |
Clerk's instance that this class helps to update time. |
The handle timeout method of this class is called periodically by the reactor. This method updates the clerk's notion of globally synchronized time by contacting the various Time Servers.
Definition at line 50 of file Timer_Helper.h.
typedef ACE_Array_Base<CosTime::TimeService_var> Timer_Helper::IORS [protected] |
TAO_BEGIN_VERSIONED_NAMESPACE_DECL Timer_Helper::Timer_Helper | ( | void | ) |
Timer_Helper::~Timer_Helper | ( | void | ) |
Timer_Helper::Timer_Helper | ( | TAO_Time_Service_Clerk * | clerk | ) |
Constructor that sets the clerk.
Definition at line 21 of file Timer_Helper.cpp.
00022 : clerk_ (clerk) 00023 { 00024 00025 }
int Timer_Helper::handle_timeout | ( | const ACE_Time_Value & | time, | |
const void * | arg | |||
) | [virtual] |
This method is called periodically by the Reactor to update the clerk's time.
Reimplemented from ACE_Event_Handler.
Definition at line 32 of file Timer_Helper.cpp.
References CORBA::Exception::_tao_print_exception(), ACE_DEBUG, ACE_UINT64_LITERAL, clerk_, ACE_OS::gettimeofday(), TAO_Time_Service_Clerk::inaccuracy(), LM_DEBUG, ACE_Time_Value::sec(), TAO_debug_level, time(), TAO_Time_Service_Clerk::time_, TAO_Time_Service_Clerk::time_displacement_factor(), ACE_OS::timezone(), ACE_OS::tzset(), TAO_Time_Service_Clerk::update_timestamp_, and ACE_Time_Value::usec().
00034 { 00035 int no_of_servers = 0; 00036 CORBA::ULongLong sum = 0; 00037 00038 // The following are used to keep a track of the inaccuracy 00039 // in synchronization. 00040 00041 #if defined (ACE_LACKS_LONGLONG_T) 00042 CORBA::ULongLong lowest_time (0xFFFFFFFF, 0xFFFFFFFF); 00043 #else 00044 CORBA::ULongLong lowest_time = ACE_UINT64_LITERAL (0xFFFFFFFFFFFFFFFF); 00045 #endif 00046 00047 CORBA::ULongLong highest_time = 0; 00048 00049 try 00050 { 00051 IORS::TYPE* value; 00052 for (IORS::ITERATOR server_iterator (this->clerk_->server_); 00053 server_iterator.next (value) != 0; 00054 server_iterator.advance ()) 00055 { 00056 // This is a remote call. 00057 CosTime::UTO_var UTO_server = 00058 (*value)->universal_time (); 00059 00060 #if defined (ACE_LACKS_LONGLONG_T) 00061 00062 if (TAO_debug_level > 0) 00063 ACE_DEBUG ((LM_DEBUG, 00064 "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n" 00065 "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n", 00066 ACE_U64_TO_U32 (UTO_server->time ()), 00067 ACE_U64_TO_U32 (UTO_server->inaccuracy ()), 00068 UTO_server->tdf (), 00069 ACE_U64_TO_U32 ((UTO_server->utc_time ()).time), 00070 (UTO_server->utc_time ()).inacclo, 00071 (UTO_server->utc_time ()).inacchi, 00072 (UTO_server->utc_time ()).tdf)); 00073 00074 #else 00075 00076 if (TAO_debug_level > 0) 00077 ACE_DEBUG ((LM_DEBUG, 00078 "\nTime = %Q\nInaccuracy = %Q\nTimeDiff = %d\nstruct.time = %Q\n" 00079 "struct.inacclo = %d\nstruct.inacchi = %d\nstruct.Tdf = %d\n", 00080 UTO_server->time (), 00081 UTO_server->inaccuracy (), 00082 UTO_server->tdf (), 00083 (UTO_server->utc_time ()).time, 00084 (UTO_server->utc_time ()).inacclo, 00085 (UTO_server->utc_time ()).inacchi, 00086 (UTO_server->utc_time ()).tdf)); 00087 #endif 00088 00089 CORBA::ULongLong curr_server_time = 00090 UTO_server->time (); 00091 00092 sum += curr_server_time; 00093 00094 ++no_of_servers; 00095 00096 // Set the highest time to the largest time seen so far. 00097 if (curr_server_time > highest_time) 00098 highest_time = curr_server_time; 00099 00100 // Set the lowest time to the smallest time seen so far. 00101 if (curr_server_time < lowest_time) 00102 lowest_time = curr_server_time; 00103 00104 } 00105 00106 if (TAO_debug_level > 0) 00107 ACE_DEBUG ((LM_DEBUG, 00108 "\nUpdated time from %d servers in the network", 00109 no_of_servers)); 00110 00111 // Return the average of the times retrieved from the various 00112 // servers. 00113 clerk_->time_ = sum / no_of_servers ; 00114 00115 // Set the Time Displacement Factor. The TZ environment variable is 00116 // read to set the time zone. We convert the timezone value from seconds 00117 // to minutes. 00118 00119 ACE_OS::tzset (); 00120 long arg = ACE_OS::timezone () / 60; 00121 CORBA::Short goodarg = static_cast<CORBA::Short> (arg); 00122 clerk_->time_displacement_factor (goodarg); 00123 00124 // Set the inaccuracy. 00125 if (highest_time > lowest_time) 00126 clerk_->inaccuracy (highest_time - lowest_time); 00127 else 00128 clerk_->inaccuracy (0); 00129 00130 const ACE_Time_Value timeofday = ACE_OS::gettimeofday (); 00131 00132 // Record the current time in a timestamp to know when global 00133 // updation of time was done. 00134 clerk_->update_timestamp_ = 00135 static_cast<CORBA::ULongLong> (timeofday.sec ()) * 00136 static_cast<ACE_UINT32> (10000000) + 00137 static_cast<CORBA::ULongLong> (timeofday.usec () * 10); 00138 } 00139 catch (const CORBA::Exception& ex) 00140 { 00141 if (TAO_debug_level > 0) 00142 ex._tao_print_exception ("Exception in handle_timeout()\n"); 00143 00144 return -1; 00145 } 00146 00147 return 0; 00148 }
TAO_Time_Service_Clerk* Timer_Helper::clerk_ [protected] |
Clerk's instance that this class helps to update time.
Definition at line 70 of file Timer_Helper.h.
Referenced by handle_timeout().