本文整理汇总了C++中Future::isFailed方法的典型用法代码示例。如果您正苦于以下问题:C++ Future::isFailed方法的具体用法?C++ Future::isFailed怎么用?C++ Future::isFailed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future::isFailed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Failure
Future<Nothing> NetworkCniIsolatorProcess::_detach(
const ContainerID& containerId,
const std::string& networkName,
const string& plugin,
const tuple<Future<Option<int>>, Future<string>>& t)
{
CHECK(infos.contains(containerId));
CHECK(infos[containerId]->containerNetworks.contains(networkName));
Future<Option<int>> status = std::get<0>(t);
if (!status.isReady()) {
return Failure(
"Failed to get the exit status of the CNI plugin '" +
plugin + "' subprocess: " +
(status.isFailed() ? status.failure() : "discarded"));
}
if (status->isNone()) {
return Failure(
"Failed to reap the CNI plugin '" + plugin + "' subprocess");
}
if (status.get() == 0) {
const string ifDir = paths::getInterfaceDir(
rootDir.get(),
containerId.value(),
networkName,
infos[containerId]->containerNetworks[networkName].ifName);
Try<Nothing> rmdir = os::rmdir(ifDir);
if (rmdir.isError()) {
return Failure(
"Failed to remove interface directory '" +
ifDir + "': " + rmdir.error());
}
return Nothing();
}
// CNI plugin will print result (in case of success) or error (in
// case of failure) to stdout.
Future<string> output = std::get<1>(t);
if (!output.isReady()) {
return Failure(
"Failed to read stdout from the CNI plugin '" +
plugin + "' subprocess: " +
(output.isFailed() ? output.failure() : "discarded"));
}
return Failure(
"The CNI plugin '" + plugin + "' failed to detach container "
"from network '" + networkName + "': " + output.get());
}
示例2: Failure
static Future<Nothing> _fetch(const Future<std::tuple<
Future<Option<int>>,
Future<string>,
Future<string>>>& future)
{
CHECK_READY(future);
Future<Option<int>> status = std::get<0>(future.get());
if (!status.isReady()) {
return Failure(
"Failed to get the exit status of the curl subprocess: " +
(status.isFailed() ? status.failure() : "discarded"));
}
if (status->isNone()) {
return Failure("Failed to reap the curl subprocess");
}
if (status->get() != 0) {
Future<string> error = std::get<2>(future.get());
if (!error.isReady()) {
return Failure(
"Failed to perform 'curl'. Reading stderr failed: " +
(error.isFailed() ? error.failure() : "discarded"));
}
return Failure("Failed to perform 'curl': " + error.get());
}
Future<string> output = std::get<1>(future.get());
if (!output.isReady()) {
return Failure(
"Failed to read stdout from 'curl': " +
(output.isFailed() ? output.failure() : "discarded"));
}
// Parse the output and get the HTTP response code.
Try<int> code = numify<int>(output.get());
if (code.isError()) {
return Failure("Unexpected output from 'curl': " + output.get());
}
if (code.get() != http::Status::OK) {
return Failure(
"Unexpected HTTP response code: " +
http::Status::string(code.get()));
}
return Nothing();
}
示例3: if
/*
* Class: org_apache_mesos_state_AbstractState
* Method: __fetch_get
* Signature: (J)Lorg/apache/mesos/state/Variable;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState__1_1fetch_1get
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<Variable>* future = (Future<Variable>*) jfuture;
future->await();
if (future->isFailed()) {
jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
return nullptr;
} else if (future->isDiscarded()) {
// TODO(benh): Consider throwing an ExecutionException since we
// never return true for 'isCancelled'.
jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
env->ThrowNew(clazz, "Future was discarded");
return nullptr;
}
CHECK_READY(*future);
Variable* variable = new Variable(future->get());
// Variable variable = new Variable();
jclass clazz = env->FindClass("org/apache/mesos/state/Variable");
jmethodID _init_ = env->GetMethodID(clazz, "<init>", "()V");
jobject jvariable = env->NewObject(clazz, _init_);
jfieldID __variable = env->GetFieldID(clazz, "__variable", "J");
env->SetLongField(jvariable, __variable, (jlong) variable);
return jvariable;
}
示例4: if
/*
* Class: org_apache_mesos_state_AbstractState
* Method: __expunge_get
* Signature: (J)Ljava/lang/Boolean;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState__1_1expunge_1get
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<bool>* future = (Future<bool>*) jfuture;
future->await();
if (future->isFailed()) {
jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
return NULL;
} else if (future->isDiscarded()) {
// TODO(benh): Consider throwing an ExecutionException since we
// never return true for 'isCancelled'.
jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
env->ThrowNew(clazz, "Future was discarded");
return NULL;
}
CHECK_READY(*future);
if (future->get()) {
jclass clazz = env->FindClass("java/lang/Boolean");
return env->GetStaticObjectField(
clazz, env->GetStaticFieldID(clazz, "TRUE", "Ljava/lang/Boolean;"));
}
jclass clazz = env->FindClass("java/lang/Boolean");
return env->GetStaticObjectField(
clazz, env->GetStaticFieldID(clazz, "FALSE", "Ljava/lang/Boolean;"));
}
示例5: cancelled
void LeaderContenderProcess::cancelled(const Future<bool>& result)
{
CHECK_READY(candidacy);
LOG(INFO) << "Membership cancelled: " << candidacy->id();
// Can be called as a result of either withdraw() or server side
// expiration.
CHECK(withdrawing.isSome() || watching.isSome());
CHECK(!result.isDiscarded());
if (result.isFailed()) {
if (withdrawing.isSome()) {
withdrawing.get()->fail(result.failure());
}
if (watching.isSome()) {
watching.get()->fail(result.failure());
}
} else {
if (withdrawing.isSome()) {
withdrawing.get()->set(result);
}
if (watching.isSome()) {
watching.get()->set(Nothing());
}
}
}
示例6: readyFuture
TEST(FutureTest, Chain)
{
Future<string> s = readyFuture()
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
s.await();
ASSERT_TRUE(s.isReady());
EXPECT_EQ("true", s.get());
s = failedFuture()
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
s.await();
ASSERT_TRUE(s.isFailed());
Promise<bool> promise;
s = pendingFuture(promise.future())
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
ASSERT_TRUE(s.isPending());
promise.discard();
AWAIT_DISCARDED(s);
}
示例7: if
/*
* Class: org_apache_mesos_state_ZooKeeperState
* Method: __fetch_get
* Signature: (J)Lorg/apache/mesos/state/Variable;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_ZooKeeperState__1_1fetch_1get
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<Variable>* future = (Future<Variable>*) jfuture;
future->await();
if (future->isFailed()) {
jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
return NULL;
} else if (future->isDiscarded()) {
jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
env->ThrowNew(clazz, "Future was discarded");
return NULL;
}
CHECK(future->isReady());
Variable* variable = new Variable(future->get());
// Variable variable = new Variable();
jclass clazz = env->FindClass("org/apache/mesos/state/Variable");
jmethodID _init_ = env->GetMethodID(clazz, "<init>", "()V");
jobject jvariable = env->NewObject(clazz, _init_);
jfieldID __variable = env->GetFieldID(clazz, "__variable", "J");
env->SetLongField(jvariable, __variable, (jlong) variable);
return jvariable;
}
示例8:
TEST(HTTPTest, PipeFailure)
{
http::Pipe pipe;
http::Pipe::Reader reader = pipe.reader();
http::Pipe::Writer writer = pipe.writer();
// Fail the writer after writing some data.
EXPECT_TRUE(writer.write("hello"));
EXPECT_TRUE(writer.write("world"));
EXPECT_TRUE(writer.fail("disconnected!"));
// The reader should read the data, followed by the failure.
AWAIT_EQ("hello", reader.read());
AWAIT_EQ("world", reader.read());
Future<string> read = reader.read();
EXPECT_TRUE(read.isFailed());
EXPECT_EQ("disconnected!", read.failure());
// The writer cannot close or fail an already failed pipe.
EXPECT_FALSE(writer.close());
EXPECT_FALSE(writer.fail("not again"));
// The writer shouldn't be notified of the reader closing,
// since the writer had already failed.
EXPECT_TRUE(reader.close());
EXPECT_TRUE(writer.readerClosed().isPending());
}
示例9: _recover
void RegistrarProcess::_recover(
const MasterInfo& info,
const Future<Variable<Registry> >& recovery)
{
updating = false;
CHECK(!recovery.isPending());
if (!recovery.isReady()) {
recovered.get()->fail("Failed to recover registrar: " +
(recovery.isFailed() ? recovery.failure() : "discarded"));
} else {
Duration elapsed = metrics.state_fetch.stop();
LOG(INFO) << "Successfully fetched the registry"
<< " (" << Bytes(recovery.get().get().ByteSize()) << ")"
<< " in " << elapsed;
// Save the registry.
variable = recovery.get();
// Perform the Recover operation to add the new MasterInfo.
Owned<Operation> operation(new Recover(info));
operations.push_back(operation);
operation->future()
.onAny(defer(self(), &Self::__recover, lambda::_1));
update();
}
}
示例10: coord
TEST(CoordinatorTest, Truncate)
{
const std::string path1 = utils::os::getcwd() + "/.log1";
const std::string path2 = utils::os::getcwd() + "/.log2";
utils::os::rmdir(path1);
utils::os::rmdir(path2);
Replica replica1(path1);
Replica replica2(path2);
Network network;
network.add(replica1.pid());
network.add(replica2.pid());
Coordinator coord(2, &replica1, &network);
{
Result<uint64_t> result = coord.elect(Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(0, result.get());
}
for (uint64_t position = 1; position <= 10; position++) {
Result<uint64_t> result =
coord.append(utils::stringify(position), Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(position, result.get());
}
{
Result<uint64_t> result = coord.truncate(7, Timeout(1.0));
ASSERT_TRUE(result.isSome());
EXPECT_EQ(11, result.get());
}
{
Future<std::list<Action> > actions = replica1.read(6, 10);
ASSERT_TRUE(actions.await(2.0));
ASSERT_TRUE(actions.isFailed());
EXPECT_EQ("Bad read range (truncated position)", actions.failure());
}
{
Future<std::list<Action> > actions = replica1.read(7, 10);
ASSERT_TRUE(actions.await(2.0));
ASSERT_TRUE(actions.isReady());
EXPECT_EQ(4, actions.get().size());
foreach (const Action& action, actions.get()) {
ASSERT_TRUE(action.has_type());
ASSERT_EQ(Action::APPEND, action.type());
EXPECT_EQ(utils::stringify(action.position()), action.append().bytes());
}
}
utils::os::rmdir(path1);
utils::os::rmdir(path2);
}
示例11: _healthCheck
void _healthCheck()
{
if (check.has_http()) {
promise.fail("HTTP health check is not supported");
} else if (check.has_command()) {
const CommandInfo& command = check.command();
map<string, string> environment;
foreach (const Environment_Variable& variable,
command.environment().variables()) {
environment[variable.name()] = variable.value();
}
VLOG(2) << "Launching health command: " << command.value();
Try<Subprocess> external =
process::subprocess(
command.value(),
// Reading from STDIN instead of PIPE because scripts
// seeing an open STDIN pipe might behave differently
// and we do not expect to pass any value from STDIN
// or PIPE.
Subprocess::FD(STDIN_FILENO),
Subprocess::FD(STDERR_FILENO),
Subprocess::FD(STDERR_FILENO),
environment);
if (external.isError()) {
promise.fail("Error creating subprocess for healthcheck");
} else {
Future<Option<int> > status = external.get().status();
status.await(Seconds(check.timeout_seconds()));
if (!status.isReady()) {
string msg = "Shell command check failed with reason: ";
if (status.isFailed()) {
msg += "failed with error: " + status.failure();
} else if (status.isDiscarded()) {
msg += "status future discarded";
} else {
msg += "status still pending after timeout " +
stringify(Seconds(check.timeout_seconds()));
}
promise.fail(msg);
return;
}
int statusCode = status.get().get();
if (statusCode != 0) {
string message = "Health command check " + WSTRINGIFY(statusCode);
failure(message);
} else {
success();
}
}
} else {
示例12: Nothing
Future<Nothing> _destroy(const Future<Option<int>>& future)
{
if (future.isReady()) {
return Nothing();
} else {
return Failure("Failed to kill all processes: " +
(future.isFailed() ? future.failure() : "unknown error"));
}
}
示例13: reaped
void reaped(
ExecutorDriver* driver,
const TaskID& taskId,
pid_t pid,
const Future<Option<int> >& status_)
{
TaskState state;
string message;
Timer::cancel(escalationTimer);
if (!status_.isReady()) {
state = TASK_FAILED;
message =
"Failed to get exit status for Command: " +
(status_.isFailed() ? status_.failure() : "future discarded");
} else if (status_.get().isNone()) {
state = TASK_FAILED;
message = "Failed to get exit status for Command";
} else {
int status = status_.get().get();
CHECK(WIFEXITED(status) || WIFSIGNALED(status)) << status;
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
state = TASK_FINISHED;
} else if (killed) {
// Send TASK_KILLED if the task was killed as a result of
// killTask() or shutdown().
state = TASK_KILLED;
} else {
state = TASK_FAILED;
}
message = string("Command") +
(WIFEXITED(status)
? " exited with status "
: " terminated with signal ") +
(WIFEXITED(status)
? stringify(WEXITSTATUS(status))
: strsignal(WTERMSIG(status)));
}
cout << message << " (pid: " << pid << ")" << endl;
TaskStatus taskStatus;
taskStatus.mutable_task_id()->MergeFrom(taskId);
taskStatus.set_state(state);
taskStatus.set_message(message);
driver->sendStatusUpdate(taskStatus);
// A hack for now ... but we need to wait until the status update
// is sent to the slave before we shut ourselves down.
os::sleep(Seconds(1));
driver->stop();
}
示例14: seconds
/*
* Class: org_apache_mesos_state_AbstractState
* Method: __names_get_timeout
* Signature: (JJLjava/util/concurrent/TimeUnit;)Ljava/util/Iterator;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState__1_1names_1get_1timeout
(JNIEnv* env, jobject thiz, jlong jfuture, jlong jtimeout, jobject junit)
{
Future<set<string> >* future = (Future<set<string> >*) jfuture;
jclass clazz = env->GetObjectClass(junit);
// long seconds = unit.toSeconds(time);
jmethodID toSeconds = env->GetMethodID(clazz, "toSeconds", "(J)J");
jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
Seconds seconds(jseconds);
if (future->await(seconds)) {
if (future->isFailed()) {
clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
return NULL;
} else if (future->isDiscarded()) {
// TODO(benh): Consider throwing an ExecutionException since we
// never return true for 'isCancelled'.
clazz = env->FindClass("java/util/concurrent/CancellationException");
env->ThrowNew(clazz, "Future was discarded");
return NULL;
}
CHECK_READY(*future);
// List names = new ArrayList();
clazz = env->FindClass("java/util/ArrayList");
jmethodID _init_ = env->GetMethodID(clazz, "<init>", "()V");
jobject jnames = env->NewObject(clazz, _init_);
jmethodID add = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");
foreach (const string& name, future->get()) {
jobject jname = convert<string>(env, name);
env->CallBooleanMethod(jnames, add, jname);
}
// Iterator iterator = jnames.iterator();
jmethodID iterator =
env->GetMethodID(clazz, "iterator", "()Ljava/util/Iterator;");
jobject jiterator = env->CallObjectMethod(jnames, iterator);
return jiterator;
}
clazz = env->FindClass("java/util/concurrent/TimeoutException");
env->ThrowNew(clazz, "Failed to wait for future within timeout");
return NULL;
}
示例15: watched
void LeaderDetectorProcess::watched(Future<set<Group::Membership> > memberships)
{
CHECK(!memberships.isDiscarded());
if (memberships.isFailed()) {
LOG(ERROR) << "Failed to watch memberships: " << memberships.failure();
leader = None();
foreach (Promise<Option<Group::Membership> >* promise, promises) {
promise->fail(memberships.failure());
delete promise;
}