本文整理汇总了C++中folly::dynamic::get_ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ dynamic::get_ptr方法的具体用法?C++ dynamic::get_ptr怎么用?C++ dynamic::get_ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folly::dynamic
的用法示例。
在下文中一共展示了dynamic::get_ptr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: provider
ProxyConfig::ProxyConfig(proxy_t* proxy,
const folly::dynamic& json,
std::string configMd5Digest,
std::shared_ptr<PoolFactory> poolFactory)
: poolFactory_(std::move(poolFactory)),
configMd5Digest_(std::move(configMd5Digest)) {
McRouteHandleProvider provider(proxy, *proxy->destinationMap, *poolFactory_);
RouteHandleFactory<McrouterRouteHandleIf> factory(provider);
checkLogic(json.isObject(), "Config is not an object");
if (json.count("named_handles")) {
checkLogic(json["named_handles"].isArray(), "named_handles is not array");
for (const auto& it : json["named_handles"]) {
factory.create(it);
}
}
RouteSelectorMap routeSelectors;
auto jRoute = json.get_ptr("route");
auto jRoutes = json.get_ptr("routes");
checkLogic(!jRoute || !jRoutes,
"Invalid config: both 'route' and 'routes' are specified");
checkLogic(jRoute || jRoutes, "No route/routes in config");
if (jRoute) {
routeSelectors[proxy->getRouterOptions().default_route] =
std::make_shared<PrefixSelectorRoute>(factory, *jRoute);
} else { // jRoutes
checkLogic(jRoutes->isArray() || jRoutes->isObject(),
"Config: routes is not array/object");
if (jRoutes->isArray()) {
for (const auto& it : *jRoutes) {
checkLogic(it.isObject(), "RoutePolicy is not an object");
auto jCurRoute = it.get_ptr("route");
auto jAliases = it.get_ptr("aliases");
checkLogic(jCurRoute, "RoutePolicy: no route");
checkLogic(jAliases, "RoutePolicy: no aliases");
checkLogic(jAliases->isArray(), "RoutePolicy: aliases is not an array");
auto routeSelector =
std::make_shared<PrefixSelectorRoute>(factory, *jCurRoute);
for (const auto& alias : *jAliases) {
checkLogic(alias.isString(), "RoutePolicy: alias is not a string");
routeSelectors[alias.stringPiece()] = routeSelector;
}
}
} else { // object
for (const auto& it : jRoutes->items()) {
checkLogic(it.first.isString(), "RoutePolicy: alias is not a string");
routeSelectors[it.first.stringPiece()] =
std::make_shared<PrefixSelectorRoute>(factory, it.second);
}
}
}
asyncLogRoutes_ = provider.releaseAsyncLogRoutes();
proxyRoute_ = std::make_shared<ProxyRoute>(proxy, routeSelectors);
serviceInfo_ = std::make_shared<ServiceInfo>(proxy, *this);
}
示例2: parseQos
void PoolFactory::parseQos(std::string parentName, const folly::dynamic& jQos,
uint64_t& qosClass, uint64_t& qosPath) {
if (!jQos.isObject()) {
MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig,
"{}: qos must be an object.", parentName);
return;
}
uint64_t prevClass = qosClass;
if (auto jClass = jQos.get_ptr("class")) {
if (jClass->isInt() && isQosClassValid(jClass->getInt())) {
qosClass = jClass->getInt();
} else {
MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig,
"{}: qos.class must be an integer in the range [0, 4]",
parentName);
}
}
if (auto jPath = jQos.get_ptr("path")) {
if (jPath->isInt() && isQosPathValid(jPath->getInt())) {
qosPath = jPath->getInt();
} else {
MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig,
"{}: qos.path must be an integer in the range [0, 3]",
parentName);
qosClass = prevClass;
}
}
}
示例3: makeHashRoute
McrouterRouteHandlePtr makeHashRoute(
const folly::dynamic& json,
std::vector<McrouterRouteHandlePtr> rh,
size_t threadId) {
std::string salt;
folly::StringPiece funcType = Ch3HashFunc::type();
if (json.isObject()) {
if (auto jsalt = json.get_ptr("salt")) {
checkLogic(jsalt->isString(), "HashRoute: salt is not a string");
salt = jsalt->getString();
}
if (auto jhashFunc = json.get_ptr("hash_func")) {
checkLogic(jhashFunc->isString(),
"HashRoute: hash_func is not a string");
funcType = jhashFunc->stringPiece();
}
}
if (funcType == Ch3HashFunc::type()) {
return makeHashRouteCh3(std::move(rh), std::move(salt));
} else if (funcType == Crc32HashFunc::type()) {
return makeHashRouteCrc32(std::move(rh), std::move(salt));
} else if (funcType == WeightedCh3HashFunc::type()) {
WeightedCh3HashFunc func{json, rh.size()};
return makeHashRouteWeightedCh3(std::move(rh), std::move(salt),
std::move(func));
} else if (funcType == ConstShardHashFunc::type()) {
return makeHashRouteConstShard(std::move(rh), std::move(salt));
} else if (funcType == "Latest") {
return makeLatestRoute(json, std::move(rh), threadId);
}
throwLogic("Unknown hash function: {}", funcType);
}
示例4: makeFailoverWithExptimeRoute
McrouterRouteHandlePtr makeFailoverWithExptimeRoute(
RouteHandleFactory<McrouterRouteHandleIf>& factory,
const folly::dynamic& json) {
checkLogic(json.isObject(), "FailoverWithExptimeRoute is not an object");
auto jnormal = json.get_ptr("normal");
checkLogic(jnormal, "FailoverWithExptimeRoute: normal not found");
auto normal = factory.create(*jnormal);
int32_t failoverExptime = 60;
if (auto jexptime = json.get_ptr("failover_exptime")) {
checkLogic(jexptime->isInt(), "FailoverWithExptimeRoute: "
"failover_exptime is not an integer");
failoverExptime = jexptime->getInt();
}
std::vector<McrouterRouteHandlePtr> failover;
if (auto jfailover = json.get_ptr("failover")) {
failover = factory.createList(*jfailover);
}
auto children = getFailoverChildren(std::move(normal),
std::move(failover),
failoverExptime);
return makeFailoverRoute(json, std::move(children));
}
示例5: makeRateLimitRoute
McrouterRouteHandlePtr makeRateLimitRoute(
RouteHandleFactory<McrouterRouteHandleIf>& factory,
const folly::dynamic& json) {
checkLogic(json.isObject(), "RateLimitRoute is not an object");
auto jtarget = json.get_ptr("target");
checkLogic(jtarget, "RateLimitRoute: target not found");
auto target = factory.create(*jtarget);
auto jrates = json.get_ptr("rates");
checkLogic(jrates, "RateLimitRoute: rates not found");
return makeRateLimitRoute(std::move(target), RateLimiter(*jrates));
}
示例6: makeLatestRoute
McrouterRouteHandlePtr makeLatestRoute(
const folly::dynamic& json,
std::vector<McrouterRouteHandlePtr> targets) {
size_t failoverCount = 5;
FailoverErrorsSettings failoverErrors;
if (json.isObject()) {
if (auto jfailoverCount = json.get_ptr("failover_count")) {
checkLogic(jfailoverCount->isInt(),
"LatestRoute: failover_count is not an integer");
failoverCount = jfailoverCount->getInt();
}
if (auto jFailoverErrors = json.get_ptr("failover_errors")) {
failoverErrors = FailoverErrorsSettings(*jFailoverErrors);
}
}
return makeLatestRoute(std::move(targets), failoverCount,
std::move(failoverErrors));
}
示例7: checkLogic
FailoverErrorsSettings::FailoverErrorsSettings(const folly::dynamic& json) {
checkLogic(json.isObject() || json.isArray(),
"Failover errors must be either an array or an object.");
if (json.isObject()) {
if (auto jsonGets = json.get_ptr("gets")) {
gets_ = FailoverErrorsSettings::List(*jsonGets);
}
if (auto jsonUpdates = json.get_ptr("updates")) {
updates_ = FailoverErrorsSettings::List(*jsonUpdates);
}
if (auto jsonDeletes = json.get_ptr("deletes")) {
deletes_ = FailoverErrorsSettings::List(*jsonDeletes);
}
} else if (json.isArray()) {
gets_ = FailoverErrorsSettings::List(json);
updates_ = FailoverErrorsSettings::List(json);
deletes_ = FailoverErrorsSettings::List(json);
}
}
示例8: parsePool
PoolFactory::PoolJson PoolFactory::parsePool(const folly::dynamic& json) {
checkLogic(json.isString() || json.isObject(),
"Pool should be a string (name of pool) or an object");
if (json.isString()) {
return parseNamedPool(json.stringPiece());
}
auto jname = json.get_ptr("name");
checkLogic(jname && jname->isString(), "Pool should have string 'name'");
pools_.emplace(jname->stringPiece(), std::make_pair(json, PoolState::NEW));
return parseNamedPool(jname->stringPiece());
}
示例9: parseAsynclogRoute
/**
* @return target and asynclogName
* Caller may call makeAsynclogRoute afterwards.
*/
std::pair<McrouterRouteHandlePtr, std::string> parseAsynclogRoute(
RouteHandleFactory<McrouterRouteHandleIf>& factory,
const folly::dynamic& json) {
std::string asynclogName;
McrouterRouteHandlePtr target;
checkLogic(json.isObject() || json.isString(),
"AsynclogRoute should be object or string");
if (json.isString()) {
asynclogName = json.stringPiece().str();
target = factory.create(json);
} else { // object
auto jname = json.get_ptr("name");
checkLogic(jname && jname->isString(),
"AsynclogRoute: required string name");
auto jtarget = json.get_ptr("target");
checkLogic(jtarget, "AsynclogRoute: target not found");
asynclogName = jname->stringPiece().str();
target = factory.create(*jtarget);
}
return { std::move(target), std::move(asynclogName) };
}
示例10: parsePool
std::shared_ptr<ClientPool>
PoolFactory::parsePool(const folly::dynamic& json) {
checkLogic(json.isString() || json.isObject(),
"Pool should be a string (name of pool) or an object");
if (json.isString()) {
return parsePool(json.stringPiece().str(), json);
} else {
auto name = json.get_ptr("name");
checkLogic(name && name->isString(), "Pool should have string 'name'");
return parsePool(name->stringPiece().str(), json);
}
}
示例11: checkLogic
PoolFactory::PoolFactory(const folly::dynamic& config, ConfigApiIf& configApi)
: configApi_(configApi) {
checkLogic(config.isObject(), "config is not an object");
if (auto jpools = config.get_ptr("pools")) {
checkLogic(jpools->isObject(), "config: 'pools' is not an object");
for (const auto& it : jpools->items()) {
pools_.emplace(
it.first.stringPiece(), std::make_pair(it.second, PoolState::NEW));
}
}
}
示例12: ShadowSettings
std::shared_ptr<ShadowSettings>
ShadowSettings::create(const folly::dynamic& json, McrouterInstance& router) {
auto result = std::shared_ptr<ShadowSettings>(new ShadowSettings());
try {
checkLogic(json.isObject(), "json is not an object");
if (auto jKeyFractionRange = json.get_ptr("key_fraction_range")) {
checkLogic(jKeyFractionRange->isArray(),
"key_fraction_range is not an array");
auto ar = folly::convertTo<std::vector<double>>(*jKeyFractionRange);
checkLogic(ar.size() == 2, "key_fraction_range size is not 2");
result->setKeyRange(ar[0], ar[1]);
}
if (auto jIndexRange = json.get_ptr("index_range")) {
checkLogic(jIndexRange->isArray(), "index_range is not an array");
auto ar = folly::convertTo<std::vector<size_t>>(*jIndexRange);
checkLogic(ar.size() == 2, "index_range size is not 2");
checkLogic(ar[0] <= ar[1], "index_range start > end");
result->startIndex_ = ar[0];
result->endIndex_ = ar[1];
}
if (auto jKeyFractionRangeRv = json.get_ptr("key_fraction_range_rv")) {
checkLogic(jKeyFractionRangeRv->isString(),
"key_fraction_range_rv is not a string");
result->keyFractionRangeRv_ = jKeyFractionRangeRv->stringPiece().str();
}
if (auto jValidateReplies = json.get_ptr("validate_replies")) {
checkLogic(jValidateReplies->isBool(),
"validate_replies is not a bool");
result->validateReplies_ = jValidateReplies->getBool();
}
} catch (const std::logic_error& e) {
MC_LOG_FAILURE(router.opts(), failure::Category::kInvalidConfig,
"ShadowSettings: {}", e.what());
return nullptr;
}
result->registerOnUpdateCallback(router);
return result;
}
示例13: makeFailoverRoute
McrouterRouteHandlePtr makeFailoverRoute(
const folly::dynamic& json,
std::vector<McrouterRouteHandlePtr> children) {
FailoverErrorsSettings failoverErrors;
std::unique_ptr<FailoverRateLimiter> rateLimiter;
bool failoverTagging = false;
if (json.isObject()) {
if (auto jFailoverErrors = json.get_ptr("failover_errors")) {
failoverErrors = FailoverErrorsSettings(*jFailoverErrors);
}
if (auto jFailoverTag = json.get_ptr("failover_tag")) {
checkLogic(jFailoverTag->isBool(),
"Failover: failover_tag is not bool");
failoverTagging = jFailoverTag->getBool();
}
if (auto jFailoverLimit = json.get_ptr("failover_limit")) {
rateLimiter = folly::make_unique<FailoverRateLimiter>(*jFailoverLimit);
}
}
return makeFailoverRoute(std::move(children), std::move(failoverErrors),
std::move(rateLimiter), failoverTagging);
}
示例14: checkLogic
PoolFactory::PoolFactory(const folly::dynamic& config,
ConfigApi& configApi,
const McrouterOptions& opts)
: configApi_(configApi),
opts_(opts) {
checkLogic(config.isObject(), "config is not an object");
if (auto jpools = config.get_ptr("pools")) {
checkLogic(jpools->isObject(), "config: 'pools' is not an object");
for (const auto& it : jpools->items()) {
parsePool(it.first.stringPiece().str(), it.second);
}
}
}
示例15: makeFailoverWithExptimeRoute
McrouterRouteHandlePtr makeFailoverWithExptimeRoute(
RouteHandleFactory<McrouterRouteHandleIf>& factory,
const folly::dynamic& json) {
checkLogic(json.isObject(), "FailoverWithExptimeRoute is not an object");
McrouterRouteHandlePtr normal;
if (auto jnormal = json.get_ptr("normal")) {
normal = factory.create(*jnormal);
}
std::vector<McrouterRouteHandlePtr> failoverTargets;
if (auto jfailover = json.get_ptr("failover")) {
failoverTargets = factory.createList(*jfailover);
}
int32_t failoverExptime = 60;
if (auto jexptime = json.get_ptr("failover_exptime")) {
checkLogic(jexptime->isInt(), "FailoverWithExptimeRoute: "
"failover_exptime is not an integer");
failoverExptime = jexptime->getInt();
}
// Check if only one format is being used
checkLogic(!(json.count("settings") && // old
(json.count("failover_errors") || json.count("failover_tag"))), // new
"Use either 'settings' (old format) or 'failover_errors' / 'failover_tag'"
);
// new format
FailoverErrorsSettings failoverErrors;
bool failoverTagging = false;
if (auto jfailoverTag = json.get_ptr("failover_tag")) {
checkLogic(jfailoverTag->isBool(),
"FailoverWithExptime: failover_tag is not bool");
failoverTagging = jfailoverTag->getBool();
}
if (auto jfailoverErrors = json.get_ptr("failover_errors")) {
failoverErrors = FailoverErrorsSettings(*jfailoverErrors);
}
// old format
if (auto jsettings = json.get_ptr("settings")) {
VLOG(1) << "FailoverWithExptime: This config format is deprecated. "
"Use 'failover_errors' instead of 'settings'.";
auto oldSettings = FailoverWithExptimeSettings(*jsettings);
failoverTagging = oldSettings.failoverTagging;
failoverErrors = oldSettings.getFailoverErrors();
}
return makeFailoverWithExptimeRoute(
std::move(normal),
std::move(failoverTargets),
failoverExptime,
std::move(failoverErrors),
failoverTagging);
}