本文整理汇总了C++中HostAndPort::initialize方法的典型用法代码示例。如果您正苦于以下问题:C++ HostAndPort::initialize方法的具体用法?C++ HostAndPort::initialize怎么用?C++ HostAndPort::initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HostAndPort
的用法示例。
在下文中一共展示了HostAndPort::initialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ConnectionString
StatusWith<ConnectionString> ConnectionString::parse(const std::string& url) {
const std::string::size_type i = url.find('/');
// Replica set
if (i != std::string::npos && i != 0) {
return ConnectionString(SET, url.substr(i + 1), url.substr(0, i));
}
const int numCommas = str::count(url, ',');
// Single host
if (numCommas == 0) {
HostAndPort singleHost;
Status status = singleHost.initialize(url);
if (!status.isOK()) {
return status;
}
return ConnectionString(singleHost);
}
// Sharding config server
if (numCommas == 2) {
return ConnectionString(SYNC, url, "");
}
return Status(ErrorCodes::FailedToParse, str::stream() << "invalid url [" << url << "]");
}
示例2:
StatusWith<HostAndPort> HostAndPort::parse(const StringData& text) {
HostAndPort result;
Status status = result.initialize(text);
if (!status.isOK()) {
return StatusWith<HostAndPort>(status);
}
return StatusWith<HostAndPort>(result);
}
示例3: run
virtual bool run(OperationContext* txn, const string&,
BSONObj& cmdObj,
int,
string& errmsg,
BSONObjBuilder& result,
bool fromRepl) {
Status status = getGlobalReplicationCoordinator()->checkReplEnabledForCommand(&result);
if (!status.isOK())
return appendCommandStatus(result, status);
HostAndPort targetHostAndPort;
status = targetHostAndPort.initialize(cmdObj["replSetSyncFrom"].valuestrsafe());
if (!status.isOK())
return appendCommandStatus(result, status);
return appendCommandStatus(
result,
getGlobalReplicationCoordinator()->processReplSetSyncFrom(targetHostAndPort,
&result));
}
示例4: doMemberHeartbeat
void ReplicationCoordinatorImpl::doMemberHeartbeat(ReplicationExecutor::CallbackData cbData,
const HostAndPort& hap) {
if (cbData.status == ErrorCodes::CallbackCanceled) {
return;
}
// Are we blind, or do we have a failpoint setup to ignore this member?
bool dontHeartbeatMember = false; // TODO: replSetBlind should be here as the default
MONGO_FAIL_POINT_BLOCK(rsHeartbeatRequestNoopByMember, member) {
const StringData& stopMember = member.getData()["member"].valueStringData();
HostAndPort ignoreHAP;
Status status = ignoreHAP.initialize(stopMember);
// Ignore
if (status.isOK()) {
if (hap == ignoreHAP) {
dontHeartbeatMember = true;
}
} else {
log() << "replset: Bad member for rsHeartbeatRequestNoopByMember failpoint "
<< member.getData() << ". 'member' failed to parse into HostAndPort -- "
<< status;
}
}
if (dontHeartbeatMember) {
// Don't issue real heartbeats, just call start again after the timeout.
ReplicationExecutor::CallbackFn restartCB = stdx::bind(
&ReplicationCoordinatorImpl::doMemberHeartbeat,
this,
stdx::placeholders::_1,
hap);
CBHStatus status = _replExecutor->scheduleWorkAt(
Date_t(curTimeMillis64() + heartbeatFrequencyMillis),
restartCB);
if (!status.isOK()) {
log() << "replset: aborting heartbeats for " << hap << " due to scheduling error"
<< " -- "<< status;
return;
}
_trackHeartbeatHandle(status.getValue());
return;
}
// Compose heartbeat command message
BSONObj hbCommandBSON;
{
// take lock to build request
boost::lock_guard<boost::mutex> lock(_mutex);
BSONObjBuilder cmdBuilder;
const MemberConfig me = _rsConfig.getMemberAt(_thisMembersConfigIndex);
cmdBuilder.append("replSetHeartbeat", _rsConfig.getReplSetName());
cmdBuilder.append("v", _rsConfig.getConfigVersion());
cmdBuilder.append("pv", 1);
cmdBuilder.append("checkEmpty", false);
cmdBuilder.append("from", me.getHostAndPort().toString());
cmdBuilder.append("fromId", me.getId());
hbCommandBSON = cmdBuilder.done();
}
const ReplicationExecutor::RemoteCommandRequest request(hap, "admin", hbCommandBSON);
ReplicationExecutor::RemoteCommandCallbackFn callback = stdx::bind(
&ReplicationCoordinatorImpl::_handleHeartbeatResponse,
this,
stdx::placeholders::_1,
hap,
curTimeMillis64(),
heartbeatRetries);
CBHStatus status = _replExecutor->scheduleRemoteCommand(request, callback);
if (!status.isOK()) {
log() << "replset: aborting heartbeats for " << hap << " due to scheduling error"
<< status;
return;
}
_trackHeartbeatHandle(status.getValue());
}