本文整理汇总了C++中Future::isDiscarded方法的典型用法代码示例。如果您正苦于以下问题:C++ Future::isDiscarded方法的具体用法?C++ Future::isDiscarded怎么用?C++ Future::isDiscarded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future::isDiscarded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
/*
* Class: org_apache_mesos_state_ZooKeeperState
* Method: __names_cancel
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_org_apache_mesos_state_ZooKeeperState__1_1names_1cancel
(JNIEnv* env, jobject thiz, jlong jfuture)
{
Future<vector<string> >* future = (Future<vector<string> >*) jfuture;
if (!future->isDiscarded()) {
future->discard();
return (jboolean) future->isDiscarded();
}
return (jboolean) true;
}
示例2: 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());
}
}
}
示例3: CHECK
Future<bool> LeaderContenderProcess::withdraw()
{
if (contending.isNone()) {
// Nothing to withdraw because the contender has not contended.
return false;
}
if (withdrawing.isSome()) {
// Repeated calls to withdraw get the same result.
return withdrawing.get();
}
withdrawing = new Promise<bool>();
CHECK(!candidacy.isDiscarded());
if (candidacy.isPending()) {
// If we have not obtained the candidacy yet, we withdraw after
// it is obtained.
LOG(INFO) << "Withdraw requested before the candidacy is obtained; will "
<< "withdraw after it happens";
candidacy.onAny(defer(self(), &Self::cancel));
} else if (candidacy.isReady()) {
cancel();
} else {
// We have failed to obtain the candidacy so we do not need to
// cancel it.
return false;
}
return withdrawing.get()->future();
}
示例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: 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;
}
示例6: if
/*
* Class: org_apache_mesos_state_ZooKeeperState
* Method: __expunge_get
* Signature: (J)Ljava/lang/Boolean;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_ZooKeeperState__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()) {
jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
env->ThrowNew(clazz, "Future was discarded");
return NULL;
}
CHECK(future->isReady());
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;"));
}
示例7: _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 {
示例8: 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;
}
示例9: 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;
}
示例10: watched
void LeaderDetectorProcess::watched(const Future<set<Group::Membership> >& memberships)
{
CHECK(!memberships.isDiscarded());
if (memberships.isFailed()) {
LOG(ERROR) << "Failed to watch memberships: " << memberships.failure();
// Setting this error stops the watch loop and the detector
// transitions to an erroneous state. Further calls to detect()
// will directly fail as a result.
error = Error(memberships.failure());
leader = None();
foreach (Promise<Option<Group::Membership> >* promise, promises) {
promise->fail(memberships.failure());
delete promise;
}
示例11: cleanup
// See the comment below as to why subprocess is passed to cleanup.
inline void cleanup(
const Future<Option<int> >& result,
Promise<Option<int> >* promise,
const Subprocess& subprocess)
{
CHECK(!result.isPending());
CHECK(!result.isDiscarded());
if (result.isFailed()) {
promise->fail(result.failure());
} else {
promise->set(result.get());
}
delete promise;
}
示例12: waited
void waited(const Future<T>& future)
{
if (future.isFailed()) {
promise->fail("Collect failed: " + future.failure());
terminate(this);
} else if (future.isDiscarded()) {
promise->fail("Collect failed: future discarded");
terminate(this);
} else {
assert(future.isReady());
values.push_back(future.get());
if (futures.size() == values.size()) {
promise->set(values);
terminate(this);
}
}
}
示例13: seconds
/*
* Class: org_apache_mesos_state_ZooKeeperState
* Method: __fetch_get_timeout
* Signature: (JJLjava/util/concurrent/TimeUnit;)Lorg/apache/mesos/state/Variable;
*/
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_ZooKeeperState__1_1fetch_1get_1timeout
(JNIEnv* env, jobject thiz, jlong jfuture, jlong jtimeout, jobject junit)
{
Future<Variable>* future = (Future<Variable>*) 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()) {
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();
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;
}
clazz = env->FindClass("java/util/concurrent/TimeoutException");
env->ThrowNew(clazz, "Failed to wait for future within timeout");
return NULL;
}
示例14: _read
void _read(const Pipe::Reader& reader, const Future<Result<Event>>& event)
{
CHECK(!event.isDiscarded());
// Ignore enqueued events from the previous Subscribe call reader.
if (subscribed.isNone() || subscribed->reader != reader) {
VLOG(1) << "Ignoring event from old stale connection";
return;
}
CHECK_EQ(SUBSCRIBED, state);
CHECK_SOME(connectionId);
// This could happen if the agent process died while sending a response.
if (event.isFailed()) {
LOG(ERROR) << "Failed to decode the stream of events: "
<< event.failure();
disconnected(connectionId.get(), event.failure());
return;
}
// This could happen if the agent failed over after sending an event.
if (event->isNone()) {
const string error = "End-Of-File received from agent. The agent closed "
"the event stream";
LOG(ERROR) << error;
disconnected(connectionId.get(), error);
return;
}
if (event->isError()) {
error("Failed to de-serialize event: " + event->error());
return;
}
receive(event.get().get(), false);
read();
}
示例15: joined
void LeaderContenderProcess::joined()
{
CHECK(!candidacy.isDiscarded());
// Cannot be watching because the candidacy is not obtained yet.
CHECK_NONE(watching);
CHECK_SOME(contending);
if (candidacy.isFailed()) {
// The promise 'withdrawing' will be set to false in cancel().
contending.get()->fail(candidacy.failure());
return;
}
if (withdrawing.isSome()) {
LOG(INFO) << "Joined group after the contender started withdrawing";
// The promise 'withdrawing' will be set to 'false' in subsequent
// 'cancel()' call.
return;
}
LOG(INFO) << "New candidate (id='" << candidacy->id()
<< "') has entered the contest for leadership";
// Transition to 'watching' state.
watching = new Promise<Nothing>();
// Notify the client.
if (contending.get()->set(watching.get()->future())) {
// Continue to watch that our membership is not removed (if the
// client still cares about it).
candidacy->cancelled()
.onAny(defer(self(), &Self::cancelled, lambda::_1));
}
}