本文整理匯總了Java中com.google.common.util.concurrent.ListenableFuture.cancel方法的典型用法代碼示例。如果您正苦於以下問題:Java ListenableFuture.cancel方法的具體用法?Java ListenableFuture.cancel怎麽用?Java ListenableFuture.cancel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.util.concurrent.ListenableFuture
的用法示例。
在下文中一共展示了ListenableFuture.cancel方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: waitForAllPartUploads
import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public List<PartETag> waitForAllPartUploads() throws IOException {
try {
return Futures.allAsList(partETagsFutures).get();
} catch (InterruptedException ie) {
LOG.warn("Interrupted partUpload:" + ie, ie);
Thread.currentThread().interrupt();
} catch (ExecutionException ee) {
//there is no way of recovering so abort
//cancel all partUploads
for (ListenableFuture<PartETag> future : partETagsFutures) {
future.cancel(true);
}
//abort multipartupload
this.abort();
throw new IOException("Part upload failed in multi-part upload with " +
"id '" +uploadId + "':" + ee, ee);
}
//should not happen?
return null;
}
示例2: cancelOthers
import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
private void cancelOthers(ListenableFuture besidesThis) {
for (ListenableFuture future : futures) {
if (future != besidesThis) {
try {
future.cancel(true);
} catch (Exception e) {
}
}
}
}
示例3: cancelCurrentBlock
import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
protected synchronized void cancelCurrentBlock() {
for (ListenableFuture<MiningResult> task : currentMiningTasks) {
if (task != null && !task.isCancelled()) {
task.cancel(true);
}
}
currentMiningTasks.clear();
if (miningBlock != null) {
fireBlockCancelled(miningBlock);
logger.debug("Tainted block mining cancelled: {}", miningBlock.getShortDescr());
miningBlock = null;
}
}
示例4: backwardsCancelShouldWork
import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Test
public void backwardsCancelShouldWork() {
CompletableFuture<String> cf = new CompletableFuture<>();
ListenableFuture<String> lf = MoreFutures.fromCompletableFuture(cf);
lf.cancel(true);
assertThat(cf.isDone()).isTrue();
assertThat(cf.isCancelled()).isTrue();
}
示例5: interruptJob
import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
/**
* Interrupt the job and make it ACTIVE
* @param yadaJob
*/
public void interruptJob(Long yadaJobId) {
log.debug("Interrupting job id {}", yadaJobId);
ListenableFuture<?> jobHandle = jobHandles.get(yadaJobId);
if (jobHandle!=null) {
jobHandle.cancel(true);
} else {
log.debug("No job handle found for job id {} when interrupting", yadaJobId);
}
}