diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientBidiReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientBidiReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientBidiReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientBidiReactorBase.h @@ -28,8 +28,8 @@ virtual std::unique_ptr prepareRequest( Request &request, std::shared_ptr previousResponse) = 0; - virtual void doneCallback() { - } + virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; template @@ -51,6 +51,7 @@ template void ClientBidiReactorBase::terminate( const grpc::Status &status) { + this->terminateCallback(); if (this->done) { return; } diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientReadReactorBase.h @@ -24,13 +24,14 @@ virtual std::unique_ptr readResponse(const Response &response) = 0; - virtual void doneCallback() { - } + virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; template void ClientReadReactorBase::terminate( const grpc::Status &status) { + this->terminateCallback(); if (this->done) { return; } diff --git a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/client/base-reactors/ClientWriteReactorBase.h @@ -22,8 +22,8 @@ void OnDone(const grpc::Status &status) override; virtual std::unique_ptr prepareRequest(Request &request) = 0; - virtual void doneCallback() { - } + virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; template @@ -53,6 +53,7 @@ template void ClientWriteReactorBase::terminate( const grpc::Status &status) { + this->terminateCallback(); if (this->done) { return; } diff --git a/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerBidiReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerBidiReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerBidiReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerBidiReactorBase.h @@ -43,6 +43,7 @@ handleRequest(Request request, Response *response) = 0; virtual void initialize(){}; virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; template @@ -60,6 +61,7 @@ template void ServerBidiReactorBase::terminate( ServerBidiReactorStatus status) { + this->terminateCallback(); this->status = status; if (!this->status.status.ok()) { std::cout << "error: " << this->status.status.error_message() << std::endl; diff --git a/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerReadReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerReadReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerReadReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerReadReactorBase.h @@ -29,10 +29,12 @@ virtual std::unique_ptr readRequest(Request request) = 0; virtual void initialize(){}; virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; template void ServerReadReactorBase::terminate(grpc::Status status) { + this->terminateCallback(); if (!this->status.ok()) { std::cout << "error: " << this->status.error_message() << std::endl; } diff --git a/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerWriteReactorBase.h b/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerWriteReactorBase.h --- a/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerWriteReactorBase.h +++ b/services/backup/docker-server/contents/server/src/Reactors/server/base-reactors/ServerWriteReactorBase.h @@ -32,10 +32,12 @@ virtual std::unique_ptr writeResponse(Response *response) = 0; virtual void initialize(){}; virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; template void ServerWriteReactorBase::terminate(grpc::Status status) { + this->terminateCallback(); if (!this->status.ok()) { std::cout << "error: " << this->status.error_message() << std::endl; } diff --git a/services/blob/src/Reactors/server/base-reactors/ServerBidiReactorBase.h b/services/blob/src/Reactors/server/base-reactors/ServerBidiReactorBase.h --- a/services/blob/src/Reactors/server/base-reactors/ServerBidiReactorBase.h +++ b/services/blob/src/Reactors/server/base-reactors/ServerBidiReactorBase.h @@ -43,6 +43,7 @@ handleRequest(Request request, Response *response) = 0; virtual void initialize(){}; virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; template @@ -60,6 +61,7 @@ template void ServerBidiReactorBase::terminate( ServerBidiReactorStatus status) { + this->terminateCallback(); this->status = status; if (!this->status.status.ok()) { std::cout << "error: " << this->status.status.error_message() << std::endl; diff --git a/services/blob/src/Reactors/server/base-reactors/ServerReadReactorBase.h b/services/blob/src/Reactors/server/base-reactors/ServerReadReactorBase.h --- a/services/blob/src/Reactors/server/base-reactors/ServerReadReactorBase.h +++ b/services/blob/src/Reactors/server/base-reactors/ServerReadReactorBase.h @@ -29,10 +29,12 @@ virtual std::unique_ptr readRequest(Request request) = 0; virtual void initialize(){}; virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; template void ServerReadReactorBase::terminate(grpc::Status status) { + this->terminateCallback(); if (!this->status.ok()) { std::cout << "error: " << this->status.error_message() << std::endl; } diff --git a/services/blob/src/Reactors/server/base-reactors/ServerWriteReactorBase.h b/services/blob/src/Reactors/server/base-reactors/ServerWriteReactorBase.h --- a/services/blob/src/Reactors/server/base-reactors/ServerWriteReactorBase.h +++ b/services/blob/src/Reactors/server/base-reactors/ServerWriteReactorBase.h @@ -15,6 +15,8 @@ Response response; bool initialized = false; + void terminate(grpc::Status status); + protected: // this is a const ref since it's not meant to be modified const Request &request; @@ -30,8 +32,19 @@ virtual std::unique_ptr writeResponse(Response *response) = 0; virtual void initialize(){}; virtual void doneCallback(){}; + virtual void terminateCallback(){}; }; +template +void ServerWriteReactorBase::terminate(grpc::Status status) { + this->terminateCallback(); + if (!this->status.ok()) { + std::cout << "error: " << this->status.error_message() << std::endl; + } + this->status = status; + this->Finish(status); +} + template ServerWriteReactorBase::ServerWriteReactorBase( const Request *request) @@ -53,13 +66,13 @@ this->response = Response(); std::unique_ptr status = this->writeResponse(&this->response); if (status != nullptr) { - this->Finish(*status); + this->terminate(*status); return; } this->StartWrite(&this->response); } catch (std::runtime_error &e) { std::cout << "error: " << e.what() << std::endl; - this->Finish(grpc::Status(grpc::StatusCode::INTERNAL, e.what())); + this->terminate(grpc::Status(grpc::StatusCode::INTERNAL, e.what())); } } @@ -72,14 +85,10 @@ template void ServerWriteReactorBase::OnWriteDone(bool ok) { if (!ok) { - this->Finish(grpc::Status(grpc::StatusCode::INTERNAL, "writing error")); + this->terminate(grpc::Status(grpc::StatusCode::INTERNAL, "writing error")); return; } - try { - this->NextWrite(); - } catch (std::runtime_error &e) { - this->Finish(grpc::Status(grpc::StatusCode::INTERNAL, e.what())); - } + this->NextWrite(); } } // namespace reactor