本文整理汇总了C++中Duration::ms方法的典型用法代码示例。如果您正苦于以下问题:C++ Duration::ms方法的具体用法?C++ Duration::ms怎么用?C++ Duration::ms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duration
的用法示例。
在下文中一共展示了Duration::ms方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ZooKeeperImpl
ZooKeeperImpl(ZooKeeper* zk,
const string& servers,
const Duration& timeout,
Watcher* watcher)
: servers(servers),
zk(zk),
watcher(watcher)
{
if (watcher == NULL) {
LOG(FATAL) << "Cannot instantiate ZooKeeper with NULL watcher";
}
// Lookup PID of the WatcherProcess associated with the Watcher.
pid = process::dispatch(manager->self(),
&WatcherProcessManager::lookup,
watcher).get();
// N.B. The Watcher and thus WatcherProcess may already be gone,
// in which case, each dispatch to the WatcherProcess that we do
// will just get dropped on the floor.
// TODO(benh): Link with WatcherProcess PID?
zh = zookeeper_init(
servers.c_str(),
event,
static_cast<int>(timeout.ms()),
NULL,
this,
0);
if (zh == NULL) {
PLOG(FATAL) << "Failed to create ZooKeeper, zookeeper_init";
}
}
示例2: setMinSessionTimeout
void ZooKeeperTestServer::setMinSessionTimeout(const Duration& min)
{
// ZooKeeper server uses int representation of milliseconds for
// session timeouts.
// See http://zookeeper.apache.org/doc/trunk/zookeeperAdmin.html
zooKeeperServer->setMinSessionTimeout(static_cast<int>(min.ms()));
}
示例3: ZooKeeperImpl
ZooKeeperImpl(ZooKeeper* zk,
const string& servers,
const Duration& timeout,
Watcher* watcher)
: servers(servers),
zk(zk),
watcher(watcher)
{
if (watcher == NULL) {
LOG(FATAL) << "Cannot instantiate ZooKeeper with NULL watcher";
}
zh = zookeeper_init(
servers.c_str(),
event,
static_cast<int>(timeout.ms()),
NULL,
this,
0);
if (zh == NULL) {
PLOG(FATAL) << "Failed to create ZooKeeper, zookeeper_init";
}
}
示例4: Nothing
// Suspends execution for the given duration.
// NOTE: This implementation features a millisecond-resolution sleep API, while
// the POSIX version uses a nanosecond-resolution sleep API. As of this writing,
// Mesos only requires millisecond resolution, so this is ok for now.
inline Try<Nothing> sleep(const Duration& duration)
{
::Sleep(static_cast<DWORD>(duration.ms()));
return Nothing();
}
示例5: if
inline std::ostream& operator<<(std::ostream& stream, const Duration& duration_)
{
// Output the duration in full double precision and save the old precision.
std::streamsize precision =
stream.precision(std::numeric_limits<double>::digits10);
// Parse the duration as the sign and the absolute value.
Duration duration = duration_;
if (duration_ < Duration::zero()) {
stream << "-";
// Duration::min() may not be representable as a positive Duration.
if (duration_ == Duration::min()) {
duration = Duration::max();
} else {
duration = duration_ * -1;
}
}
// First determine which bucket of time unit the duration falls into
// then check whether the duration can be represented as a whole
// number with this time unit or a smaller one.
// e.g. 1.42857142857143weeks falls into the 'Weeks' bucket but
// reads better with a smaller unit: '10days'. So we use 'days'
// instead of 'weeks' to output the duration.
int64_t nanoseconds = duration.ns();
if (duration < Microseconds(1)) {
stream << duration.ns() << Nanoseconds::units();
} else if (duration < Milliseconds(1)) {
if (nanoseconds % Duration::MICROSECONDS != 0) {
// We can't get a whole number using this unit but we can at
// one level down.
stream << duration.ns() << Nanoseconds::units();
} else {
stream << duration.us() << Microseconds::units();
}
} else if (duration < Seconds(1)) {
if (nanoseconds % Duration::MILLISECONDS != 0 &&
nanoseconds % Duration::MICROSECONDS == 0) {
stream << duration.us() << Microseconds::units();
} else {
stream << duration.ms() << Milliseconds::units();
}
} else if (duration < Minutes(1)) {
if (nanoseconds % Duration::SECONDS != 0 &&
nanoseconds % Duration::MILLISECONDS == 0) {
stream << duration.ms() << Milliseconds::units();
} else {
stream << duration.secs() << Seconds::units();
}
} else if (duration < Hours(1)) {
if (nanoseconds % Duration::MINUTES != 0 &&
nanoseconds % Duration::SECONDS == 0) {
stream << duration.secs() << Seconds::units();
} else {
stream << duration.mins() << Minutes::units();
}
} else if (duration < Days(1)) {
if (nanoseconds % Duration::HOURS != 0 &&
nanoseconds % Duration::MINUTES == 0) {
stream << duration.mins() << Minutes::units();
} else {
stream << duration.hrs() << Hours::units();
}
} else if (duration < Weeks(1)) {
if (nanoseconds % Duration::DAYS != 0 &&
nanoseconds % Duration::HOURS == 0) {
stream << duration.hrs() << Hours::units();
} else {
stream << duration.days() << Days::units();
}
} else {
if (nanoseconds % Duration::WEEKS != 0 &&
nanoseconds % Duration::DAYS == 0) {
stream << duration.days() << Days::units();
} else {
stream << duration.weeks() << Weeks::units();
}
}
// Return the stream to original formatting state.
stream.precision(precision);
return stream;
}
示例6: setMaxSessionTimeout
void ZooKeeperTestServer::setMaxSessionTimeout(const Duration& max)
{
// See the comment for setMinSessionTimeout.
zooKeeperServer->setMaxSessionTimeout(static_cast<int>(max.ms()));
}