26#ifndef I_RequestServiceTimer_h
27#define I_RequestServiceTimer_h 1
41class RequestServiceTimer {
43 static RequestServiceTimer *d_instance;
44 mutable std::recursive_mutex d_rst_lock_mutex;
46 std::chrono::milliseconds d_bes_timeout{0};
47 std::chrono::steady_clock::time_point start_time{std::chrono::steady_clock::now()};
48 bool timeout_enabled{
false};
50 RequestServiceTimer()=
default;
51 ~RequestServiceTimer()=
default;
53 static void delete_instance();
54 static void initialize_instance();
58 static RequestServiceTimer *
TheTimer();
60 void start(std::chrono::milliseconds timeout_ms);
62 std::chrono::steady_clock::time_point get_start_time()
const {
return start_time; }
64 std::chrono::milliseconds
elapsed()
const;
66 std::chrono::milliseconds
remaining()
const;
68 bool is_timeout_enabled()
const {
return timeout_enabled; }
74 std::string dump(
bool pretty=
false)
const ;
76 void dump( std::ostream &strm )
const ;
std::chrono::milliseconds remaining() const
If the time_out is enabled returns the time remaining. If the time_out is disabled returns 0.
static RequestServiceTimer * TheTimer()
Return a pointer to a singleton timer instance. If an instance does not exist it will create and init...
std::chrono::milliseconds elapsed() const
Return the time duration in milliseconds since the timer was started.
void throw_if_timeout_expired(const std::string &message, const std::string &file, const int line)
Checks the RequestServiceTimer to determine if the time spent servicing the request at this point has...
bool is_expired() const
if the time_out is disabled return false.
void start(std::chrono::milliseconds timeout_ms)
Set/Reset the timer start_time to now().
void disable_timeout()
Set the time_out is disabled.