diff --git a/services/lib/src/client-base-reactors/ClientBidiReactorBase.h b/services/lib/src/client-base-reactors/ClientBidiReactorBase.h --- a/services/lib/src/client-base-reactors/ClientBidiReactorBase.h +++ b/services/lib/src/client-base-reactors/ClientBidiReactorBase.h @@ -8,6 +8,11 @@ namespace network { namespace reactor { +// This is how this type of reactor works: +// - repeat: +// - write a request to the server +// - read a response from the server +// - terminate the connection template class ClientBidiReactorBase : public grpc::ClientBidiReactor, public BaseReactor { @@ -21,18 +26,29 @@ public: grpc::ClientContext context; + // this should be called explicitly right after the reactor is created void start(); + // these methods come from the BaseReactor(go there for more information) void validate() override{}; void doneCallback() override{}; void terminateCallback() override{}; + std::shared_ptr getStatusHolder() override; + // these methods come from gRPC + // https://github.com/grpc/grpc/blob/v1.39.x/include/grpcpp/impl/codegen/client_callback.h#L237 void OnWriteDone(bool ok) override; void OnReadDone(bool ok) override; void terminate(const grpc::Status &status) override; void OnDone(const grpc::Status &status) override; - std::shared_ptr getStatusHolder() override; + // this method must be implemented in every reactor deriving from this one + // - argument request - request that's about to be prepared for the next cycle + // - argument previousResponse - response received during the previous cycle + // (may be nullptr) + // - returns status - if the connection is about to be + // continued, nullptr should be returned. Any other returned value will + // terminate the connection with a given status virtual std::unique_ptr prepareRequest( Request &request, std::shared_ptr previousResponse) = 0; diff --git a/services/lib/src/client-base-reactors/ClientReadReactorBase.h b/services/lib/src/client-base-reactors/ClientReadReactorBase.h --- a/services/lib/src/client-base-reactors/ClientReadReactorBase.h +++ b/services/lib/src/client-base-reactors/ClientReadReactorBase.h @@ -8,6 +8,10 @@ namespace network { namespace reactor { +// This is how this type of reactor works: +// - send a request to the server +// - read N responses from the server +// - terminate the connection template class ClientReadReactorBase : public grpc::ClientReadReactor, public BaseReactor { @@ -18,17 +22,27 @@ Request request; grpc::ClientContext context; + // this should be called explicitly right after the reactor is created void start(); + // these methods come from the BaseReactor(go there for more information) void validate() override{}; void doneCallback() override{}; void terminateCallback() override{}; + std::shared_ptr getStatusHolder() override; + // these methods come from gRPC + // https://github.com/grpc/grpc/blob/v1.39.x/include/grpcpp/impl/codegen/client_callback.h#L237 void OnReadDone(bool ok) override; void terminate(const grpc::Status &status) override; void OnDone(const grpc::Status &status) override; - std::shared_ptr getStatusHolder() override; + // this method must be implemented in every reactor deriving from this one + // - argument response - response from the server that was read during the + // current cycle + // - returns status - if the connection is about to be + // continued, nullptr should be returned. Any other returned value will + // terminate the connection with a given status virtual std::unique_ptr readResponse(Response &response) = 0; }; diff --git a/services/lib/src/client-base-reactors/ClientWriteReactorBase.h b/services/lib/src/client-base-reactors/ClientWriteReactorBase.h --- a/services/lib/src/client-base-reactors/ClientWriteReactorBase.h +++ b/services/lib/src/client-base-reactors/ClientWriteReactorBase.h @@ -8,6 +8,9 @@ namespace network { namespace reactor { +// This is how this type of reactor works: TODO +// - write N requests to the server +// - terminate the connection template class ClientWriteReactorBase : public grpc::ClientWriteReactor, public BaseReactor { @@ -20,17 +23,27 @@ Response response; grpc::ClientContext context; + // this should be called explicitly right after the reactor is created void start(); + // these methods come from the BaseReactor(go there for more information) void validate() override{}; void doneCallback() override{}; void terminateCallback() override{}; + std::shared_ptr getStatusHolder() override; + // these methods come from gRPC + // https://github.com/grpc/grpc/blob/v1.39.x/include/grpcpp/impl/codegen/client_callback.h#L237 void OnWriteDone(bool ok) override; void terminate(const grpc::Status &status) override; void OnDone(const grpc::Status &status) override; - std::shared_ptr getStatusHolder() override; + // this method must be implemented in every reactor deriving from this one + // - argument request - request that should be edited and is going to be sent + // in the current cycle to the server + // - returns status - if the connection is about to be + // continued, nullptr should be returned. Any other returned value will + // terminate the connection with a given status virtual std::unique_ptr prepareRequest(Request &request) = 0; }; diff --git a/services/lib/src/server-base-reactors/ServerBidiReactorBase.h b/services/lib/src/server-base-reactors/ServerBidiReactorBase.h --- a/services/lib/src/server-base-reactors/ServerBidiReactorBase.h +++ b/services/lib/src/server-base-reactors/ServerBidiReactorBase.h @@ -23,6 +23,11 @@ } }; +// This is how this type of reactor works: +// - repeat: +// - read a request from the client +// - write a response to the client +// - terminate the connection template class ServerBidiReactorBase : public grpc::ServerBidiReactor, public BaseReactor { @@ -37,20 +42,31 @@ public: ServerBidiReactorBase(); + // these methods come from the BaseReactor(go there for more information) void terminate(const grpc::Status &status) override; void validate() override{}; void doneCallback() override{}; void terminateCallback() override{}; + std::shared_ptr getStatusHolder() override; + // these methods come from gRPC + // https://github.com/grpc/grpc/blob/v1.39.x/include/grpcpp/impl/codegen/client_callback.h#L237 void OnDone() override; void OnReadDone(bool ok) override; void OnWriteDone(bool ok) override; - std::shared_ptr getStatusHolder() override; void terminate(ServerBidiReactorStatus status); ServerBidiReactorStatus getStatus() const; void setStatus(const ServerBidiReactorStatus &status); + // this method must be implemented in every reactor deriving from this one + // - argument request - request that was sent by the client and received by + // the server in the current cycle + // - argument response - response that will be sent to the client in the + // current cycle + // - returns status - if the connection is about to be + // continued, nullptr should be returned. Any other returned value will + // terminate the connection with a given status virtual std::unique_ptr handleRequest(Request request, Response *response) = 0; }; diff --git a/services/lib/src/server-base-reactors/ServerReadReactorBase.h b/services/lib/src/server-base-reactors/ServerReadReactorBase.h --- a/services/lib/src/server-base-reactors/ServerReadReactorBase.h +++ b/services/lib/src/server-base-reactors/ServerReadReactorBase.h @@ -13,6 +13,10 @@ namespace network { namespace reactor { +// This is how this type of reactor works: +// - read N requests from the client +// - write a final response to the client (may be empty) +// - terminate the connection template class ServerReadReactorBase : public grpc::ServerReadReactor, public BaseReactor { @@ -25,15 +29,23 @@ public: ServerReadReactorBase(Response *response); + // these methods come from the BaseReactor(go there for more information) void validate() override{}; void doneCallback() override{}; void terminateCallback() override{}; + std::shared_ptr getStatusHolder() override; + // these methods come from gRPC + // https://github.com/grpc/grpc/blob/v1.39.x/include/grpcpp/impl/codegen/client_callback.h#L237 void OnReadDone(bool ok) override; void terminate(const grpc::Status &status) override; void OnDone() override; - std::shared_ptr getStatusHolder() override; + // this method must be implemented in every reactor deriving from this one + // - argument request - data read from the client in the current cycle + // - returns status - if the connection is about to be + // continued, nullptr should be returned. Any other returned value will + // terminate the connection with a given status virtual std::unique_ptr readRequest(Request request) = 0; }; diff --git a/services/lib/src/server-base-reactors/ServerWriteReactorBase.h b/services/lib/src/server-base-reactors/ServerWriteReactorBase.h --- a/services/lib/src/server-base-reactors/ServerWriteReactorBase.h +++ b/services/lib/src/server-base-reactors/ServerWriteReactorBase.h @@ -13,6 +13,10 @@ namespace network { namespace reactor { +// This is how this type of reactor works: +// - read a request from the client +// - write N responses to the client +// - terminate the connection template class ServerWriteReactorBase : public grpc::ServerWriteReactor, public BaseReactor { @@ -29,18 +33,28 @@ public: ServerWriteReactorBase(const Request *request); + // this should be called explicitly right after the reactor is created void start(); + // these methods come from the BaseReactor(go there for more information) void validate() override{}; void doneCallback() override{}; void terminateCallback() override{}; + std::shared_ptr getStatusHolder() override; + // these methods come from gRPC + // https://github.com/grpc/grpc/blob/v1.39.x/include/grpcpp/impl/codegen/client_callback.h#L237 virtual void initialize(){}; void OnWriteDone(bool ok) override; void terminate(const grpc::Status &status); void OnDone() override; - std::shared_ptr getStatusHolder() override; + // this method must be implemented in every reactor deriving from this one + // - argument response - should be filled with data that will be sent to the + // client in the current cycle + // - returns status - if the connection is about to be + // continued, nullptr should be returned. Any other returned value will + // terminate the connection with a given status virtual std::unique_ptr writeResponse(Response *response) = 0; };