Add GRPCServer to Stoppable Hierarchy

This commit is contained in:
Nathan Nichols
2020-07-17 10:50:27 -05:00
committed by Nik Bougalis
parent 795de3a75a
commit a26a175957
4 changed files with 36 additions and 18 deletions

View File

@@ -439,7 +439,7 @@ public:
logs_->journal("Application"), logs_->journal("Application"),
std::chrono::milliseconds(100), std::chrono::milliseconds(100),
get_io_service()) get_io_service())
, grpcServer_(std::make_unique<GRPCServer>(*this)) , grpcServer_(std::make_unique<GRPCServer>(*this, *m_jobQueue))
{ {
add(m_resourceManager.get()); add(m_resourceManager.get());
@@ -1316,7 +1316,6 @@ ApplicationImp::setup()
logs_->silent(config_->silent()); logs_->silent(config_->silent());
m_jobQueue->setThreadCount(config_->WORKERS, config_->standalone()); m_jobQueue->setThreadCount(config_->WORKERS, config_->standalone());
grpcServer_->run();
if (!config_->standalone()) if (!config_->standalone())
timeKeeper_->run(config_->SNTP_SERVERS); timeKeeper_->run(config_->SNTP_SERVERS);

View File

@@ -18,6 +18,7 @@
//============================================================================== //==============================================================================
#include <ripple/app/main/GRPCServer.h> #include <ripple/app/main/GRPCServer.h>
#include <ripple/beast/core/CurrentThreadName.h>
#include <ripple/resource/Fees.h> #include <ripple/resource/Fees.h>
namespace ripple { namespace ripple {
@@ -438,25 +439,35 @@ GRPCServerImpl::start()
} }
void void
GRPCServer::run() GRPCServer::onStart()
{ {
// Start the server and setup listeners // Start the server and setup listeners
if ((running_ = impl_.start())) if (running_ = impl_.start(); running_)
{ {
thread_ = std::thread([this]() { thread_ = std::thread([this]() {
// Start the event loop and begin handling requests // Start the event loop and begin handling requests
beast::setCurrentThreadName("rippled: grpc");
this->impl_.handleRpcs(); this->impl_.handleRpcs();
}); });
} }
} }
GRPCServer::~GRPCServer() void
GRPCServer::onStop()
{ {
if (running_) if (running_)
{ {
impl_.shutdown(); impl_.shutdown();
thread_.join(); thread_.join();
running_ = false;
} }
stopped();
}
GRPCServer::~GRPCServer()
{
assert(!running_);
} }
} // namespace ripple } // namespace ripple

View File

@@ -22,6 +22,7 @@
#include <ripple/app/main/Application.h> #include <ripple/app/main/Application.h>
#include <ripple/core/JobQueue.h> #include <ripple/core/JobQueue.h>
#include <ripple/core/Stoppable.h>
#include <ripple/net/InfoSub.h> #include <ripple/net/InfoSub.h>
#include <ripple/protocol/ErrorCodes.h> #include <ripple/protocol/ErrorCodes.h>
#include <ripple/resource/Charge.h> #include <ripple/resource/Charge.h>
@@ -234,10 +235,13 @@ private:
}; // GRPCServerImpl }; // GRPCServerImpl
class GRPCServer class GRPCServer : public Stoppable
{ {
public: public:
explicit GRPCServer(Application& app) : impl_(app){}; explicit GRPCServer(Application& app, Stoppable& parent)
: Stoppable("GRPCServer", parent), impl_(app)
{
}
GRPCServer(const GRPCServer&) = delete; GRPCServer(const GRPCServer&) = delete;
@@ -245,14 +249,17 @@ public:
operator=(const GRPCServer&) = delete; operator=(const GRPCServer&) = delete;
void void
run(); onStart() override;
~GRPCServer(); void
onStop() override;
~GRPCServer() override;
private: private:
GRPCServerImpl impl_; GRPCServerImpl impl_;
std::thread thread_; std::thread thread_;
bool running_; bool running_ = false;
}; };
} // namespace ripple } // namespace ripple
#endif #endif

View File

@@ -173,7 +173,7 @@ class RootStoppable;
@note A Stoppable may not be restarted. @note A Stoppable may not be restarted.
The form of the Stoppable tree in the rippled application evolves as The form of the Stoppable tree in the rippled application evolves as
the source code changes and reacts to new demands. As of March in 2017 the source code changes and reacts to new demands. As of July in 2020
the Stoppable tree had this form: the Stoppable tree had this form:
@code @code
@@ -186,13 +186,14 @@ class RootStoppable;
| |
JobQueue JobQueue
| |
+--------+-----------+-----------+-----------+-------+---+----------+ +------+---------+--------+----------+---+-----------+--+---+
| | | | | | | | | | | | | | |
| NetworkOPs | InboundLedgers | OrderbookDB | | NetworkOPs | InboundLedgers | | OrderbookDB |
| | | | | | | GRPCServer |
Overlay InboundTransactions LedgerMaster Database | | | Database
| | | Overlay InboundTransactions LedgerMaster |
PeerFinder LedgerCleaner TaskQueue | | |
PeerFinder LedgerCleaner TaskQueue
@endcode @endcode
*/ */