diff --git a/build/includes/summa_actor/client.hpp b/build/includes/summa_actor/client.hpp index 7b7e9496e91c89128e9662224e47fd73cb2c4b31..fc413a59c376fe36cb4b2edd1c1afb2e21917e3f 100644 --- a/build/includes/summa_actor/client.hpp +++ b/build/includes/summa_actor/client.hpp @@ -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 diff --git a/build/source/actors/summa_actor/client.cpp b/build/source/actors/summa_actor/client.cpp index ecf776b1e3b1bd72cd2483c8d4c8fd41448a76ae..ac926c7a925184ddc51d6ad9710c2c6e71f87f20 100644 --- a/build/source/actors/summa_actor/client.cpp +++ b/build/source/actors/summa_actor/client.cpp @@ -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; +} diff --git a/build/source/actors/summa_actor/summa_server.cpp b/build/source/actors/summa_actor/summa_server.cpp index 98bf019e5e5dee131e008295f2f9b4817eb1566e..7130168166352bf8795624256b717be545fd6c6c 100644 --- a/build/source/actors/summa_actor/summa_server.cpp +++ b/build/source/actors/summa_actor/summa_server.cpp @@ -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(); + } } } };