本文整理汇总了C++中SharedRefPtr类的典型用法代码示例。如果您正苦于以下问题:C++ SharedRefPtr类的具体用法?C++ SharedRefPtr怎么用?C++ SharedRefPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SharedRefPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: protocol_version_
Value::Value(int protocol_version,
const SharedRefPtr<const DataType>& data_type,
char* data, int32_t size)
: protocol_version_(protocol_version)
, data_type_(data_type) {
if (size > 0 && data_type->is_collection()) {
data_ = decode_size(protocol_version, data, count_);
if (protocol_version_ >= 3) {
size_ = size - sizeof(int32_t);
} else {
size_ = size - sizeof(uint16_t);
}
} else {
if (data_type->is_tuple()) {
SharedRefPtr<const SubTypesDataType> sub_types(data_type);
count_ = sub_types->types().size();
} else if (data_type->is_user_type()) {
SharedRefPtr<const UserType> user_type(data_type);
count_ = user_type->fields().size();
} else {
count_ = 0;
}
data_ = data;
size_ = size;
}
}
示例2: uv_hrtime
SharedRefPtr<Host> LatencyAwarePolicy::LatencyAwareQueryPlan::compute_next() {
int64_t min = policy_->min_average_.load();
const Settings& settings = policy_->settings_;
uint64_t now = uv_hrtime();
SharedRefPtr<Host> host;
while ((host = child_plan_->compute_next())) {
TimestampedAverage latency = host->get_current_average();
if (min < 0 ||
latency.average < 0 ||
latency.num_measured < settings.min_measured ||
(now - latency.timestamp) > settings.retry_period_ns) {
return host;
}
if (latency.average <= static_cast<int64_t>(settings.exclusion_threshold * min)) {
return host;
}
skipped_.push_back(host);
}
if (skipped_index_ < skipped_.size()) {
return skipped_[skipped_index_++];
}
return SharedRefPtr<Host>();
}
示例3: on_remove
void DCAwarePolicy::on_remove(const SharedRefPtr<Host>& host) {
const std::string& dc = host->dc();
if (dc == local_dc_) {
remove_host(local_dc_live_hosts_, host);
} else {
per_remote_dc_live_hosts_.remove_host_from_dc(host->dc(), host);
}
}
示例4: on_remove
void Session::on_remove(SharedRefPtr<Host> host) {
load_balancing_policy_->on_remove(host);
{ // Lock hosts
ScopedMutex l(&hosts_mutex_);
hosts_.erase(host->address());
}
for (IOWorkerVec::iterator it = io_workers_.begin(),
end = io_workers_.end(); it != end; ++it) {
(*it)->remove_pool_async(host->address(), true);
}
}
示例5: init
void DCAwarePolicy::init(const SharedRefPtr<Host>& connected_host, const HostMap& hosts) {
if (local_dc_.empty() && !connected_host->dc().empty()) {
LOG_INFO("Using '%s' for the local data center "
"(if this is incorrect, please provide the correct data center)",
connected_host->dc().c_str());
local_dc_ = connected_host->dc();
}
for (HostMap::const_iterator i = hosts.begin(),
end = hosts.end(); i != end; ++i) {
on_add(i->second);
}
}
示例6: on_up
void Session::on_up(SharedRefPtr<Host> host) {
host->set_up();
if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
return;
}
load_balancing_policy_->on_up(host);
for (IOWorkerVec::iterator it = io_workers_.begin(),
end = io_workers_.end(); it != end; ++it) {
(*it)->add_pool_async(host->address(), false);
}
}
示例7: on_add
void DCAwarePolicy::on_add(const SharedRefPtr<Host>& host) {
const std::string& dc = host->dc();
if (local_dc_.empty() && !dc.empty()) {
LOG_INFO("Using '%s' for local data center "
"(if this is incorrect, please provide the correct data center)",
host->dc().c_str());
local_dc_ = dc;
}
if (dc == local_dc_) {
local_dc_live_hosts_->push_back(host);
} else {
per_remote_dc_live_hosts_.add_host_to_dc(dc, host);
}
}
示例8: distance
CassHostDistance DCAwarePolicy::distance(const SharedRefPtr<Host>& host) const {
if (local_dc_.empty() || host->dc() == local_dc_) {
return CASS_HOST_DISTANCE_LOCAL;
}
const CopyOnWriteHostVec& hosts = per_remote_dc_live_hosts_.get_hosts(host->dc());
size_t num_hosts = std::min(hosts->size(), used_hosts_per_remote_dc_);
for (size_t i = 0; i < num_hosts; ++i) {
if ((*hosts)[i]->address() == host->address()) {
return CASS_HOST_DISTANCE_REMOTE;
}
}
return CASS_HOST_DISTANCE_IGNORE;
}
示例9: on_down
void Session::on_down(SharedRefPtr<Host> host) {
host->set_down();
load_balancing_policy_->on_down(host);
bool cancel_reconnect = false;
if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
// This permanently removes a host from all IO workers by stopping
// any attempt to reconnect to that host.
cancel_reconnect = true;
}
for (IOWorkerVec::iterator it = io_workers_.begin(),
end = io_workers_.end(); it != end; ++it) {
(*it)->remove_pool_async(host->address(), cancel_reconnect);
}
}
示例10: on_add
void Session::on_add(SharedRefPtr<Host> host, bool is_initial_connection) {
host->set_up();
if (load_balancing_policy_->distance(host) == CASS_HOST_DISTANCE_IGNORE) {
return;
}
if (is_initial_connection) {
pending_pool_count_ += io_workers_.size();
} else {
load_balancing_policy_->on_add(host);
}
for (IOWorkerVec::iterator it = io_workers_.begin(),
end = io_workers_.end(); it != end; ++it) {
(*it)->add_pool_async(host->address(), is_initial_connection);
}
}
示例11: while
SharedRefPtr<Host> TokenAwarePolicy::TokenAwareQueryPlan::compute_next() {
while (remaining_ > 0) {
--remaining_;
const SharedRefPtr<Host>& host((*replicas_)[index_++ % replicas_->size()]);
if (host->is_up() && child_policy_->distance(host) == CASS_HOST_DISTANCE_LOCAL) {
return host;
}
}
SharedRefPtr<Host> host;
while ((host = child_plan_->compute_next())) {
if (!contains(replicas_, host->address()) ||
child_policy_->distance(host) != CASS_HOST_DISTANCE_LOCAL) {
return host;
}
}
return SharedRefPtr<Host>();
}
示例12: is_valid_host
bool BlacklistDCPolicy::is_valid_host(const SharedRefPtr<Host>& host) const {
const std::string& host_dc = host->dc();
for (DcList::const_iterator it = dcs_.begin(),
end = dcs_.end(); it != end; ++it) {
if (host_dc.compare(*it) == 0) {
return false;
}
}
return true;
}
示例13: is_valid_host
bool BlacklistPolicy::is_valid_host(const SharedRefPtr<Host>& host) const {
const std::string& host_address = host->address().to_string(false);
for (ContactPointList::const_iterator it = hosts_.begin(),
end = hosts_.end();
it != end; ++it) {
if (host_address.compare(*it) == 0) {
return false;
}
}
return true;
}
示例14: UserTypeValue
UserTypeValue(const SharedRefPtr<const UserType>& data_type)
: AbstractData(data_type->fields().size())
, data_type_(data_type) { }
示例15: on_add
void LatencyAwarePolicy::on_add(const SharedRefPtr<Host>& host) {
host->enable_latency_tracking(settings_.scale_ns, settings_.min_measured);
add_host(hosts_, host);
ChainedLoadBalancingPolicy::on_add(host);
}