|
cluck 1.0.1
The cluster lock service.
|
Implementation of the cluck class. More...
#include "cluck/cluck.h"#include "cluck/exception.h"#include "cluck/names.h"#include <eventdispatcher/names.h>#include <communicator/communicator_connection.h>#include <communicator/names.h>#include <cppthread/guard.h>#include <cppthread/mutex.h>#include <cppthread/thread.h>#include <snapdev/not_reached.h>#include <snapdev/poison.h>
Go to the source code of this file.
Namespaces | |
| namespace | cluck |
| namespace | cluck::anonymous_namespace{cluck.cpp} |
Functions | |
| timeout_t | cluck::get_lock_duration_timeout () |
| timeout_t | cluck::get_lock_obtention_timeout () |
| cluck::serial_t | cluck::anonymous_namespace{cluck.cpp}::get_next_serial () |
| timeout_t | cluck::get_unlock_timeout () |
| ed::match_t | cluck::anonymous_namespace{cluck.cpp}::match_command_and_tag (ed::dispatcher_match const *m, ed::message &msg) |
| void | cluck::set_lock_duration_timeout (timeout_t timeout) |
| void | cluck::set_lock_obtention_timeout (timeout_t timeout) |
| void | cluck::set_unlock_timeout (timeout_t timeout) |
A cluck object is used to obtain a cluster lock.
This allows programs to run code in a cluster safe manner. In other words, it ensures that a single instance of a function runs in an entire cluster of computers. This can also be useful as a lock between processes running on a single computer, although in that case an flock(2) call is likely much more efficient (if you can guarantee that all said processes will be running on the same computer). See the snapdev/lockfile.h for such a lock object.
The implementation creates a LOCK message and sends it to the cluck service. The service then either immediately replies with a LOCKED message or waits for the lock to be released by another program. Once done with a lock, a program sends the UNLOCK message to release the lock.
The process can timeout or fail, in which case the lock_failed() function gets called instead of the lock_obtained() one. It is also possible to run common code after the lock is released by implementing the finally() function. By default, those functions call your callbacks, which can be much more practical than deriving this class.
Note that the cluck class is a communicator connection of type ed::timer. You are responsible for adding that class to the communicator.
You must have a messenger object with a dispatcher to create a cluck object. The name passed to the cluck constructor is the name of the lock. Different names create different locks. In other words, a lock named A does not prevent a lock named B from being obtained.
Definition in file cluck.cpp.
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.