com.google.common.util.concurrent.AbstractFuture.cancel()方法的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(30)

本文整理了Java中com.google.common.util.concurrent.AbstractFuture.cancel()方法的一些代码示例,展示了AbstractFuture.cancel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractFuture.cancel()方法的具体详情如下:
包路径:com.google.common.util.concurrent.AbstractFuture
类名称:AbstractFuture
方法名:cancel

AbstractFuture.cancel介绍

[英]Subclasses should invoke this method to mark the future as cancelled. This will set the state of the future to AbstractFuture.Sync#CANCELLED and call #done() if the state was successfully changed.
[中]子类应该调用此方法来将未来标记为已取消。这将把未来的状态设置为抽象的未来。如果状态已成功更改,则同步#取消并调用#完成()。

代码示例

代码示例来源:origin: google/guava

@Override
public boolean cancel(boolean interruptIfRunning) {
 InCompletionOrderState<T> localState = state;
 if (super.cancel(interruptIfRunning)) {
  localState.recordOutputCancellation(interruptIfRunning);
  return true;
 }
 return false;
}

代码示例来源:origin: google/j2objc

@Override
public boolean cancel(boolean interruptIfRunning) {
 InCompletionOrderState<T> localState = state;
 if (super.cancel(interruptIfRunning)) {
  localState.recordOutputCancellation(interruptIfRunning);
  return true;
 }
 return false;
}

代码示例来源:origin: wildfly/wildfly

@Override
public boolean cancel(boolean interruptIfRunning) {
 InCompletionOrderState<T> localState = state;
 if (super.cancel(interruptIfRunning)) {
  localState.recordOutputCancellation(interruptIfRunning);
  return true;
 }
 return false;
}

代码示例来源:origin: google/guava

@CanIgnoreReturnValue
 @Override
 public final boolean cancel(boolean mayInterruptIfRunning) {
  return super.cancel(mayInterruptIfRunning);
 }
}

代码示例来源:origin: google/j2objc

@CanIgnoreReturnValue
 @Override
 public final boolean cancel(boolean mayInterruptIfRunning) {
  return super.cancel(mayInterruptIfRunning);
 }
}

代码示例来源:origin: google/guava

@Override
 public Void call() {
  if (currentFuture.get().cancel(true)) {
   numSuccessfulSetCalls.incrementAndGet();
  }
  awaitUnchecked(barrier);
  return null;
 }
};

代码示例来源:origin: google/guava

@Override
 public Void call() {
  cancellationSucess.set(currentFuture.get().cancel(true));
  awaitUnchecked(barrier);
  return null;
 }
};

代码示例来源:origin: google/guava

@Override
 public void run() {
  cancellationSucess.set(currentFuture.get().cancel(true));
  awaitUnchecked(barrier);
 }
};

代码示例来源:origin: wildfly/wildfly

@CanIgnoreReturnValue
 @Override
 public final boolean cancel(boolean mayInterruptIfRunning) {
  return super.cancel(mayInterruptIfRunning);
 }
}

代码示例来源:origin: google/guava

@Override
 public void run() {
  future.cancel(true);
  if (!future.isDone()) {
   errorMessage.set("Cancel call exited before future was complete.");
  }
 }
});

代码示例来源:origin: google/guava

private static void assertCannotCancel(AbstractFuture<Integer> future) {
  assertThat(future.cancel(true)).isFalse();
  assertThat(future.cancel(false)).isFalse();
 }
}

代码示例来源:origin: google/guava

public void testGetFailure_CanceledNoCause() {
 AbstractFuture<String> future = new AbstractFuture<String>() {};
 future.cancel(false);
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

public void testSetFutureDelegateAlreadyCancelled() throws Exception {
 delegate.cancel(
   false
   /** mayInterruptIfRunning */
   );
 assertThat(future.setFuture(delegate)).isTrue();
 assertCancelled(future, false);
}

代码示例来源:origin: google/guava

public void testSetFutureDelegateLaterInterrupted() throws Exception {
 assertThat(future.setFuture(delegate)).isTrue();
 delegate.cancel(
   true
   /** mayInterruptIfRunning */
   );
 assertCancelled(future, /* expectWasInterrupted= */ false);
}

代码示例来源:origin: google/guava

public void testSetFutureDelegateLaterCancelled() throws Exception {
 assertThat(future.setFuture(delegate)).isTrue();
 delegate.cancel(
   false
   /** mayInterruptIfRunning */
   );
 assertCancelled(future, false);
}

代码示例来源:origin: google/guava

public void testSetFutureDelegateAlreadyInterrupted() throws Exception {
 delegate.cancel(
   true
   /** mayInterruptIfRunning */
   );
 assertThat(future.setFuture(delegate)).isTrue();
 assertCancelled(future, /* expectWasInterrupted= */ false);
}

代码示例来源:origin: google/guava

public void testListenLaterSetAsynchronouslyLaterDelegateInterrupted() {
 CountingRunnable before = new CountingRunnable();
 CountingRunnable inBetween = new CountingRunnable();
 CountingRunnable after = new CountingRunnable();
 future.addListener(before, directExecutor());
 future.setFuture(delegate);
 future.addListener(inBetween, directExecutor());
 delegate.cancel(true);
 future.addListener(after, directExecutor());
 before.assertRun();
 inBetween.assertRun();
 after.assertRun();
}

代码示例来源:origin: google/guava

public void testListenLaterSetAsynchronouslyLaterDelegateCancelled() {
 CountingRunnable before = new CountingRunnable();
 CountingRunnable inBetween = new CountingRunnable();
 CountingRunnable after = new CountingRunnable();
 future.addListener(before, directExecutor());
 future.setFuture(delegate);
 future.addListener(inBetween, directExecutor());
 delegate.cancel(false);
 future.addListener(after, directExecutor());
 before.assertRun();
 inBetween.assertRun();
 after.assertRun();
}

代码示例来源:origin: google/guava

public void testCancel_done() throws Exception {
 AbstractFuture<String> future =
   new AbstractFuture<String>() {
    {
     set("foo");
    }
   };
 assertFalse(future.cancel(true));
 assertFalse(future.isCancelled());
 assertTrue(future.isDone());
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
 return (source == null || source.cancel(mayInterruptIfRunning))
   && super.cancel(mayInterruptIfRunning);
}

相关文章