Skip to content
Snippets Groups Projects
Commit e984289c authored by KyleKlenk's avatar KyleKlenk
Browse files

Can use heartbeating to determine if client has exited

parent 88f48c98
No related branches found
No related tags found
No related merge requests found
......@@ -13,26 +13,76 @@ class Client {
caf::actor client_actor;
std::string hostname;
int current_batch_id;
int lost_Potential_indicator; // value to indicate the Potential that a client is lost.
// The greater the lost_Potential_indicator the greater chances the client has been lost.
public:
/**
* @brief Construct a new Client object
*
* @param id
* @param client_actor
* @param hostname
*/
Client(int id, caf::actor client_actor, std::string hostname);
void updateCurrentBatchID(int batch_id);
// Getters
/**
* @brief Returns the actor_reference of the client
*/
caf::actor getActor();
/**
* @brief Get the value of the lost_Potential_indicator variable.
* @return int
*/
int getLostPotentialIndicator();
/**
* @brief Returns the ID of the client
*/
int getID();
/**
* @brief Get the Hostname of the client
*/
std::string getHostname();
// Setters
/**
* @brief Sets the batch_id of the batch the client is currently computing
*/
void updateCurrentBatchID(int batch_id);
// methods
/**
* @brief Increments the lost_likley_hood indicator variable
* this is done everytime a client is sent a heartbeat message
*
* checks if the client is likely lost or not
*/
void incrementLostPotential();
/**
* @brief Decrement the lost_likley_hood indicator variables
* this is done everytime a client sends a heartbeat message back
* to the server
*/
void decrementLostPotential();
};
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
class Client_Container {
private:
int num_clients = 0;
int lost_client_threshold = 3; // value to determine if client is lost
std::vector<Client> client_list;
......@@ -42,31 +92,14 @@ class Client_Container {
*/
Client_Container();
/**
* @brief add a client to the client vector
* increment the number of clients
*
* @param client_actor connecting cleint actor_ref
* @param hostname name of the host that client actor is connecting
* from
*/
void addClient(caf::actor client_actor, std::string hostname);
/**
* @brief Update the current batch id the client is working on
*
* @param client_id The id of the client we want to update the batch for
* @param batch_id The id of the batch
*/
void updateCurrentBatch(int client_id, int batch_id);
// Getters
/**
* @brief Get the number of connected clients
*
* @return int
*/
int getNumClients();
/**
* @brief Get the Client ID of a cleint from its actor ref
*
......@@ -74,7 +107,7 @@ class Client_Container {
* @return int
*/
int getClientID(caf::actor client_actor);
/**
* @brief Get a client from the client list
* This is used when we need to get all of the
......@@ -85,6 +118,38 @@ class Client_Container {
*/
Client getClient(int index);
// Methods
/**
* @brief add a client to the client vector
* increment the number of clients
*
* @param client_actor connecting cleint actor_ref
* @param hostname name of the host that client actor is connecting
* from
*/
void addClient(caf::actor client_actor, std::string hostname);
/**
* @brief Update the current batch id the client is working on
*
* @param client_id The id of the client we want to update the batch for
* @param batch_id The id of the batch
*/
void updateCurrentBatch(int client_id, int batch_id);
/**
* @brief Increments the lost_potential indicator variable
* this is done everytime a client is sent a heartbeat message
*/
bool checkForLostClient(int index);
/**
* @brief Decrement the lost_likley_hood indicator variables
* this is done everytime a client sends a heartbeat message back
* to the server
*/
void decrementLostPotential(int client_id);
/**
* @brief Removes a client from the back of the list
* Used when we are finished and want to pop the clients
......@@ -109,4 +174,11 @@ class Client_Container {
*/
bool isEmpty();
/**
* @brief Find the index of a client in the client_list
*
* @param client_id
* @return int
*/
int findClientByID(int client_id);
};
\ No newline at end of file
......@@ -9,13 +9,13 @@ Client::Client(int id, caf::actor client_actor, std::string hostname) {
this->connected = true;
}
// Getters
caf::actor Client::getActor() {
return this->client_actor;
}
void Client::updateCurrentBatchID(int batch_id) {
this->current_batch_id = batch_id;
int Client::getLostPotentialIndicator() {
return this->lost_Potential_indicator;
}
int Client::getID() {
......@@ -26,6 +26,26 @@ std::string Client::getHostname() {
return this->hostname;
}
// Setters
void Client::updateCurrentBatchID(int batch_id) {
this->current_batch_id = batch_id;
}
// Methods
void Client::incrementLostPotential() {
this->lost_Potential_indicator++;
}
void Client::decrementLostPotential() {
this->lost_Potential_indicator--;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
Client_Container::Client_Container() {}
......@@ -51,6 +71,21 @@ Client Client_Container::getClient(int index) {
return this->client_list[index];
}
// Needs to be used direclty after getClient so same index is used
bool Client_Container::checkForLostClient(int index) {
this->client_list[index].incrementLostPotential();
if (this->lost_client_threshold < this->client_list[index].getLostPotentialIndicator()) {
return true;
} else {
return false;
}
}
void Client_Container::decrementLostPotential(int client_id) {
int index = findClientByID(client_id);
this->client_list[index].decrementLostPotential();
}
int Client_Container::getClientID(caf::actor client_actor) {
for (int i = 0; i < num_clients; i++) {
......@@ -76,12 +111,21 @@ Client Client_Container::removeClient_fromBack() {
}
void Client_Container::updateCurrentBatch(int client_id, int batch_id) {
for (int i = 0; i < num_clients; i++) {
int index = findClientByID(client_id);
this->client_list[index].updateCurrentBatchID(batch_id);;
}
int Client_Container::findClientByID(int client_id) {
for(int i = 0; i < this->num_clients; i++) {
if (client_id == this->client_list[i].getID()){
this->client_list[i].updateCurrentBatchID(batch_id);
return i;
}
}
throw "Cannot Find Client";
}
......@@ -108,7 +108,12 @@ behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Sett
[=](check_on_clients) {
for (int i = 0; i < self->state.client_container->getNumClients(); i++) {
Client client = self->state.client_container->getClient(i);
self->send(client.getActor(), heartbeat_v);
if(self->state.client_container->checkForLostClient(i)) {
// Client May Be Lost
aout(self) << "Client " << client.getID() << " is considered lost\n";
} else {
self->send(client.getActor(), heartbeat_v);
}
}
self->send(self->state.health_check_reminder_actor,
start_health_check_v, self, self->state.heartbeat_interval);
......@@ -116,7 +121,7 @@ behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Sett
[=](heartbeat, int client_id) {
aout(self) << "Received HeartBeat From: " << client_id << "\n";
self->state.client_container->decrementLostPotential(client_id);
},
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment