31#include <eventdispatcher/message.h>
52 cluckd(
int argc,
char * argv[]);
75 void stop(
bool quitting);
112 ed::message
const & message
113 , std::string * object_name
114 , ed::dispatcher_match::tag_t * tag
118 , std::string * source);
Class handling intercomputer locking.
void msg_get_max_ticket(ed::message &msg)
Search for the largest ticket.
bool is_daemon_ready() const
Check whether the cluck daemon is ready to process lock requests.
void add_connections()
Finish the cluck daemon initialization.
void msg_lock_status(ed::message &msg)
A service asked about the lock status.
void msg_lock_entered(ed::message &msg)
Tell the specified ticket LOCK_ENTERED was received.
std::string const & get_server_name() const
Get the name of the server we are running on.
time_t f_pace_lockstarted
void run()
Run the cluck daemon.
void cleanup()
Clean timed out entries if any.
void lock_exiting(ed::message &msg)
Used to simulate a LOCK_EXITING message.
computer::pointer_t get_leader_b() const
Get pointer to leader B.
void msg_max_ticket(ed::message &msg)
Got the largest ticket from another leader.
void msg_add_ticket(ed::message &msg)
Add a ticket from another cluckd.
ed::communicator::pointer_t f_communicator
void msg_ticket_ready(ed::message &msg)
Let other leaders know that the ticket is ready.
void msg_cluster_down(ed::message &msg)
The communicatord lost too many connections.
ticket::ticket_id_t get_last_ticket(std::string const &lock_name)
Determine the last ticket defined in this cluck daemon.
void msg_absolutely(ed::message &msg)
Lock the resource after confirmation that client is alive.
ticket::object_map_t f_entering_tickets
std::string ticket_list() const
Generate the output for "cluck-status --list".
void msg_activate_lock(ed::message &msg)
Acknowledge the ACTIVATE_LOCK with what we think is our first lock.
std::size_t f_neighbors_count
snapdev::timespec_ex f_election_date
void set_my_ip_address(addr::addr const &a)
addr::addr f_my_ip_address
void msg_unlock(ed::message &msg)
Unlock the resource.
computer::map_t f_computers
void msg_info(ed::message &msg)
Return a JSON with the state of this cluckd object.
ticket::object_map_t f_tickets
void msg_lock_started(ed::message &msg)
Called whenever a cluck computer is acknowledging itself.
void stop(bool quitting)
Called whenever we receive the STOP command or equivalent.
std::string f_server_name
void synchronize_leaders()
Synchronize leaders.
std::shared_ptr< cluckd > pointer_t
void msg_lock_leaders(ed::message &msg)
The list of leaders.
void election_status()
Check the status of the election.
void msg_lock_activated(ed::message &msg)
Acknowledgement of the lock to activate.
void forward_message_to_leader(ed::message &message)
Forward a user message to a leader.
virtual ~cluckd()
Do some clean ups.
ticket::serial_t f_ticket_serial
computer::vector_t f_leaders
std::string serialized_tickets()
void send_lock_started(ed::message const *msg)
void msg_ticket_added(ed::message &msg)
Acknowledgement that the ticket was properly added.
int get_computer_count() const
Return the number of known computers running cluckd.
messenger::pointer_t f_messenger
void msg_lock_entering(ed::message &msg)
Create an entering ticket.
ticket::key_map_t const get_entering_tickets(std::string const &lock_name)
Get a reference to the list of entering tickets.
void msg_list_tickets(ed::message &msg)
Reply to the LIST_TICKETS message with the TICKET_LIST.
void msg_lock_exiting(ed::message &msg)
Exit a ticket.
void msg_server_gone(ed::message &msg)
Called whenever a remote connection is disconnected.
void msg_lock(ed::message &msg)
Lock the named resource.
void msg_clock_stable(ed::message &msg)
Message telling us whether the clock is stable.
computer::pointer_t is_leader(std::string id=std::string()) const
Search for a leader.
cluck::timeout_t f_start_time
void activate_first_lock(std::string const &object_name)
Make sure the very first ticket is marked as LOCKED.
cluckd(cluckd const &rhs)=delete
void set_ticket(std::string const &object_name, std::string const &key, ticket::pointer_t ticket)
Set the ticket.
void msg_cluster_up(ed::message &msg)
Cluster is ready, send the LOCK_STARTED message.
void msg_drop_ticket(ed::message &msg)
One of the cluckd processes asked for a ticket to be dropped.
bool get_parameters(ed::message const &message, std::string *object_name, ed::dispatcher_match::tag_t *tag, pid_t *client_pid, cluck::timeout_t *timeout, std::string *key, std::string *source)
Try to get a set of parameters.
void msg_lock_failed(ed::message &msg)
Acknowledge a lock failure.
interrupt::pointer_t f_interrupt
void msg_lock_tickets(ed::message &msg)
Another cluckd is sending us its list of tickets.
void msg_status(ed::message &msg)
With the STATUS message we know of new communicatord services.
computer::pointer_t get_leader_a() const
Get pointer to leader A.
std::size_t f_neighbors_quorum
cluckd & operator=(cluckd const &rhs)=delete
message_cache::list_t f_message_cache
ticket::pointer_t find_first_lock(std::string const &lock_name)
std::vector< pointer_t > vector_t
std::map< std::string, pointer_t > map_t
std::shared_ptr< computer > pointer_t
std::shared_ptr< interrupt > pointer_t
std::shared_ptr< messenger > pointer_t
Handle the ticket messages.
std::map< std::string, key_map_t > object_map_t
std::uint32_t ticket_id_t
std::shared_ptr< ticket > pointer_t
std::map< std::string, pointer_t > key_map_t
std::shared_ptr< ed::timer > pointer_t
snapdev::timespec_ex timeout_t
A timeout delay.
std::list< message_cache > list_t