Timer handler for periodically flushing a shared mutator. More...
#include <TableMutatorIntervalHandler.h>
Public Member Functions | |
TableMutatorIntervalHandler (Comm *comm, ApplicationQueueInterface *app_queue, TableMutatorShared *shared_mutator) | |
Constructor. More... | |
void | start () |
Starts interval timer. More... | |
virtual void | handle (EventPtr &event) |
Handles the timer interrupt. More... | |
void | flush () |
Flushes shared mutator shared_mutator. More... | |
void | stop () |
Stops the periodic flushing of the shared mutator. More... | |
Public Member Functions inherited from Hypertable::DispatchHandler | |
virtual | ~DispatchHandler () |
Destructor. More... | |
Private Attributes | |
std::mutex | mutex |
Mutex for serializing access to members More... | |
std::condition_variable | cond |
Condition variable signalled when complete is set to true More... | |
bool | active |
Set to false to deactivate and prevent further timer interrupts. More... | |
bool | complete |
Indicates if final timer interrupt has completed. More... | |
Comm * | comm |
Pointer to AsyncComm subsystem. More... | |
ApplicationQueueInterface * | app_queue |
Pointer to application queue. More... | |
TableMutatorShared * | shared_mutator |
Shared mutator to be periodically flushed. More... | |
Timer handler for periodically flushing a shared mutator.
This class is used as the timer handler for periodically flushing a shared mutator. The class is initialized with a shared mutator (shared_mutator) which it flushes on a periodic interval. It registers itself as the timer handler in a call to Comm::set_timer(), using shared_mutator->flush_interval() as the duration, and causes the shared mutator to get flushed each time the handle() method is called.
Definition at line 51 of file TableMutatorIntervalHandler.h.
TableMutatorIntervalHandler::TableMutatorIntervalHandler | ( | Comm * | comm, |
ApplicationQueueInterface * | app_queue, | ||
TableMutatorShared * | shared_mutator | ||
) |
Constructor.
Initializes members comm, app_queue, and shared_mutator with the comm
, app_queue
, and shared_mutator
parameters, respectively. It also picks a random number between 0 and shared_mutator->flush_interval() and schedules a timer interrupt for that many milliseconds in the future. It does this to smooth out the flush times of potentially hundreds or thousands of clients that start up at the same time.
comm | Pointer to AsyncComm subsystem |
app_queue | Application queue |
shared_mutator | Shared mutator |
Definition at line 39 of file TableMutatorIntervalHandler.cc.
void TableMutatorIntervalHandler::flush | ( | ) |
Flushes shared mutator shared_mutator.
If active is true, this method flushes shared_mutator, otherwise it does nothing. This method is typically called from a TableMutatorFlushHandler object that gets enqueued on app_queue from the handle() method.
Definition at line 75 of file TableMutatorIntervalHandler.cc.
|
virtual |
Handles the timer interrupt.
If active is true then a TableMutatorFlushHandler object will get created and enqueued on app_queue and then timer will be re-registered with a call to Comm::set_timer() using this object as the handler and shared_mutator->flush_interval() for the duration. Otherwise, if active is false, complete will get set to true and cond will be notified.
event | Event object generated from AsyncComm (usually TIMER event) |
Implements Hypertable::DispatchHandler.
Definition at line 60 of file TableMutatorIntervalHandler.cc.
void TableMutatorIntervalHandler::start | ( | ) |
Starts interval timer.
Definition at line 45 of file TableMutatorIntervalHandler.cc.
|
inline |
Stops the periodic flushing of the shared mutator.
This method sets active to false and then waits on cond until complete becomes true.
Definition at line 95 of file TableMutatorIntervalHandler.h.
|
private |
Set to false to deactivate and prevent further timer interrupts.
Definition at line 110 of file TableMutatorIntervalHandler.h.
|
private |
Pointer to application queue.
Definition at line 119 of file TableMutatorIntervalHandler.h.
|
private |
Pointer to AsyncComm subsystem.
Definition at line 116 of file TableMutatorIntervalHandler.h.
|
private |
Indicates if final timer interrupt has completed.
Definition at line 113 of file TableMutatorIntervalHandler.h.
|
private |
Condition variable signalled when complete is set to true
Definition at line 107 of file TableMutatorIntervalHandler.h.
|
private |
Mutex for serializing access to members
Definition at line 104 of file TableMutatorIntervalHandler.h.
|
private |
Shared mutator to be periodically flushed.
Definition at line 122 of file TableMutatorIntervalHandler.h.