Go to the documentation of this file.
31 #include "absl/strings/str_cat.h"
32 #include "absl/strings/str_format.h"
33 #include "absl/strings/str_join.h"
34 #include "absl/strings/string_view.h"
46 void RegisterLoadBalancingPolicyFactory(
47 std::unique_ptr<LoadBalancingPolicyFactory> factory) {
56 LoadBalancingPolicyFactory* GetLoadBalancingPolicyFactory(
57 const char*
name)
const {
67 std::vector<std::unique_ptr<LoadBalancingPolicyFactory>>
factories_;
70 RegistryState*
g_state =
nullptr;
88 std::unique_ptr<LoadBalancingPolicyFactory> factory) {
104 if (factory ==
nullptr)
return nullptr;
110 const char*
name,
bool* requires_config) {
112 auto* factory =
g_state->GetLoadBalancingPolicyFactory(
name);
113 if (factory ==
nullptr) {
116 if (requires_config !=
nullptr) {
120 factory->ParseLoadBalancingConfig(
Json(), &
error) ==
nullptr;
131 const Json& lb_config_array, Json::Object::const_iterator*
result) {
136 std::vector<absl::string_view> policies_tried;
140 "child entry should be of type object");
142 if (lb_config.object_value().empty()) {
144 "no policy found in child entry");
146 if (lb_config.object_value().size() > 1) {
149 auto it = lb_config.object_value().begin();
152 "child entry should be of type object");
156 it->first.c_str(),
nullptr)) {
160 policies_tried.push_back(
it->first);
163 "No known policies in list: ",
absl::StrJoin(policies_tried,
" ")));
168 RefCountedPtr<LoadBalancingPolicy::Config>
173 Json::Object::const_iterator policy;
174 *
error = ParseLoadBalancingConfigHelper(json, &policy);
180 g_state->GetLoadBalancingPolicyFactory(policy->first.c_str());
181 if (factory ==
nullptr) {
183 absl::StrFormat(
"Factory not found for policy \"%s\"", policy->first));
static void RegisterLoadBalancingPolicyFactory(std::unique_ptr< LoadBalancingPolicyFactory > factory)
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec< Args... > &format, const Args &... args)
#define GPR_DEBUG_ASSERT(x)
virtual OrphanablePtr< LoadBalancingPolicy > CreateLoadBalancingPolicy(LoadBalancingPolicy::Args) const =0
Returns a new LB policy instance.
const Array & array_value() const
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
std::string StrJoin(Iterator start, Iterator end, absl::string_view sep, Formatter &&fmt)
JSON (JavaScript Object Notation).
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
Args used to instantiate an LB policy.
#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc)
static OrphanablePtr< LoadBalancingPolicy > CreateLoadBalancingPolicy(const char *name, LoadBalancingPolicy::Args args)
Creates an LB policy of the type specified by name.
static RefCountedPtr< LoadBalancingPolicy::Config > ParseLoadBalancingConfig(const Json &json, grpc_error_handle *error)
#define GRPC_ERROR_CREATE_FROM_CPP_STRING(desc)
std::unique_ptr< T, Deleter > OrphanablePtr
static void InitRegistry()
Global initialization and shutdown hooks.
#define GRPC_ERROR_UNREF(err)
static struct test_state g_state
std::vector< std::unique_ptr< LoadBalancingPolicyFactory > > factories_
static bool LoadBalancingPolicyExists(const char *name, bool *requires_config)
static void ShutdownRegistry()
#define GRPC_ERROR_IS_NONE(err)
virtual RefCountedPtr< LoadBalancingPolicy::Config > ParseLoadBalancingConfig(const Json &json, grpc_error_handle *error) const =0
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:15