本文整理汇总了C++中NodeManager::get_all_nodes方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeManager::get_all_nodes方法的具体用法?C++ NodeManager::get_all_nodes怎么用?C++ NodeManager::get_all_nodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeManager
的用法示例。
在下文中一共展示了NodeManager::get_all_nodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: default_method
void RaftStatImpl::default_method(::google::protobuf::RpcController* controller,
const ::braft::IndexRequest* /*request*/,
::braft::IndexResponse* /*response*/,
::google::protobuf::Closure* done) {
brpc::ClosureGuard done_guard(done);
brpc::Controller* cntl = (brpc::Controller*)controller;
std::string group_id = cntl->http_request().unresolved_path();
std::vector<scoped_refptr<NodeImpl> > nodes;
NodeManager* nm = NodeManager::GetInstance();
if (group_id.empty()) {
nm->get_all_nodes(&nodes);
} else {
nm->get_nodes_by_group_id(group_id, &nodes);
}
const bool html = brpc::UseHTML(cntl->http_request());
if (html) {
cntl->http_response().set_content_type("text/html");
} else {
cntl->http_response().set_content_type("text/plain");
}
butil::IOBufBuilder os;
if (html) {
os << "<!DOCTYPE html><html><head>\n"
<< "<script language=\"javascript\" type=\"text/javascript\" src=\"/js/jquery_min\"></script>\n"
<< brpc::TabsHead() << "</head><body>";
cntl->server()->PrintTabsBody(os, "raft");
}
if (nodes.empty()) {
if (html) {
os << "</body></html>";
}
os.move_to(cntl->response_attachment());
return;
}
std::string prev_group_id;
const char *newline = html ? "<br>" : "\r\n";
for (size_t i = 0; i < nodes.size(); ++i) {
const NodeId node_id = nodes[i]->node_id();
group_id = node_id.group_id;
if (group_id != prev_group_id) {
if (html) {
os << "<h1>" << group_id << "</h1>";
} else {
os << "[" << group_id << "]" << newline;
}
prev_group_id = group_id;
}
nodes[i]->describe(os, html);
os << newline;
}
if (html) {
os << "</body></html>";
}
os.move_to(cntl->response_attachment());
}