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

View File

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

View File

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

View File

@@ -173,7 +173,7 @@ class RootStoppable;
@note A Stoppable may not be restarted.
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:
@code
@@ -186,11 +186,12 @@ class RootStoppable;
|
JobQueue
|
+--------+-----------+-----------+-----------+-------+---+----------+
| | | | | | |
| NetworkOPs | InboundLedgers | OrderbookDB |
| | | |
Overlay InboundTransactions LedgerMaster Database
+------+---------+--------+----------+---+-----------+--+---+
| | | | | | | |
| NetworkOPs | InboundLedgers | | OrderbookDB |
| | | GRPCServer |
| | | Database
Overlay InboundTransactions LedgerMaster |
| | |
PeerFinder LedgerCleaner TaskQueue