0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Attributes | List of all members
Hypertable::TimeWindow Class Reference

Defines a time window. More...

#include <TimeWindow.h>

Collaboration diagram for Hypertable::TimeWindow:
Collaboration graph
[legend]

Public Member Functions

 TimeWindow ()
 Default constructor. More...
 
 TimeWindow (std::vector< String > crontab_specs)
 Constructor initialized with crontab specs. More...
 
bool update_current_time (time_t now=0)
 Logically sets the current time. More...
 
bool within_window () const
 Tests to see if current time is within the window. More...
 
void enable_window (bool enable)
 Enables or disables this time window. More...
 
bool is_window_enabled () const
 Indicates if the time window is enabled or disabled. More...
 

Private Attributes

std::vector< Crontabm_crontabs
 Vector of Crontab objects that define each subwindow. More...
 
bool m_within_window
 Set to true if currently within the time window. More...
 
bool m_enabled
 Set to true if the time window is enabled. More...
 

Detailed Description

Defines a time window.

This class can be used to define a time window (or set of discontiguous time windows) that can be used, for example, to define times when certain activities can take place. It can be initialized with a set of crontab entries that define the time window(s) and has member functions for setting the current time and testing to see if the current time falls within the defined time window(s). The motivating use case for this class was to allow the Hypertable RangeServers to define the daily period of low activity and have it change it's maintenance algorithm to be more aggressive during these periods. Example usage:

vector<String> specs;
specs.push_back("* 2-5 * * *");
TimeWindow low_activity_time(specs);
...
time_t now = time(0);
low_activity_time.set_current_time(now);
if (low_activity_time.within_window()) {
  ... perform heavy mainteance activity ...
}

Definition at line 61 of file TimeWindow.h.

Constructor & Destructor Documentation

Hypertable::TimeWindow::TimeWindow ( )
inline

Default constructor.

Definition at line 65 of file TimeWindow.h.

TimeWindow::TimeWindow ( std::vector< String crontab_specs)

Constructor initialized with crontab specs.

This function constructs a Crontab object with each of the specs in crontab_specs and pushes them onto m_crontabs. It wraps each Crontab object construction in a try/catch block and asserts with a message indicating the bad entry that caused the constructor to throw an exception.

Parameters
crontab_specsCrontab specs that define the time window(s)

Definition at line 41 of file TimeWindow.cc.

Member Function Documentation

void Hypertable::TimeWindow::enable_window ( bool  enable)
inline

Enables or disables this time window.

Parameters
enabletrue if to enable, false otherwise

Definition at line 97 of file TimeWindow.h.

bool Hypertable::TimeWindow::is_window_enabled ( ) const
inline

Indicates if the time window is enabled or disabled.

Returns
true if enabled, false otherwise

Definition at line 101 of file TimeWindow.h.

bool TimeWindow::update_current_time ( time_t  now = 0)

Logically sets the current time.

This function fetches the current time (or uses now if non-zero) and determines if it falls within the time window by checking it against all of the Crontab objects in m_crontabs. For each Crontab object in m_crontabs, it calls Crontab::next_event() and if any of them report that the next event is within 60 seconds of the current time, it sets m_within_window to true, otherwise it sets it to false.

Parameters
nowTime to use for checking if we're within the time window
Returns
true if updating the current time has caused an entry or exit from the window, false otherwise.

Definition at line 58 of file TimeWindow.cc.

bool Hypertable::TimeWindow::within_window ( ) const
inline

Tests to see if current time is within the window.

Checks to see if the current time (as set by set_current_time()) is within the time window.

Returns
true if within enabled time window, false otherwise

Definition at line 93 of file TimeWindow.h.

Member Data Documentation

std::vector<Crontab> Hypertable::TimeWindow::m_crontabs
private

Vector of Crontab objects that define each subwindow.

Definition at line 106 of file TimeWindow.h.

bool Hypertable::TimeWindow::m_enabled
private

Set to true if the time window is enabled.

Definition at line 112 of file TimeWindow.h.

bool Hypertable::TimeWindow::m_within_window
private

Set to true if currently within the time window.

Definition at line 109 of file TimeWindow.h.


The documentation for this class was generated from the following files: