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

Clients now exit when all batches are solved

parent 6797b1e5
No related branches found
No related tags found
No related merge requests found
......@@ -50,8 +50,12 @@ class Client_Container {
*/
void addClient(caf::actor client_actor, std::string hostname);
int getClientID(caf::actor);
Client removeClient_fromBack();
std::string getHostname_ByClientID(int client_id);
bool isEmpty();
};
\ No newline at end of file
......@@ -48,3 +48,13 @@ int Client_Container::getClientID(caf::actor client_actor) {
std::string Client_Container::getHostname_ByClientID(int client_id) {
return this->client_list[client_id].getHostname();
}
bool Client_Container::isEmpty() {
return this->client_list.empty();
}
Client Client_Container::removeClient_fromBack() {
Client client = this->client_list.back();
this->client_list.pop_back();
return client;
}
......@@ -67,11 +67,30 @@ behavior summa_server(stateful_actor<summa_server_state>* self, Distributed_Sett
std::optional<Batch> new_batch = self->state.batch_container->assignBatch(
self->state.client_container->getHostname_ByClientID(client_id), client_actor);
if (new_batch.has_value()) {
self->send(client_actor, new_batch.value());
} else {
aout(self) << "no more batches left to assign\n";
aout(self) << "we are not done yet. Clients could Fail\n";
if (self->state.batch_container->getBatchesRemaining() > 0) {
aout(self) << "no more batches left to assign\n";
aout(self) << "we are not done yet. Clients could Fail\n";
} else {
aout(self) << "Telling Clients To Exit\n";
while(!self->state.client_container->isEmpty()) {
Client client = self->state.client_container->removeClient_fromBack();
caf::actor client_actor = client.getActor();
self->send(client_actor, time_to_exit_v);
}
aout(self) << "SERVER EXITING!!\n";
self->quit();
}
}
}
};
......
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