public CompletableFuture<?> getFinishFuture() { checkState(process != null, "getFinishFuture called on null pager"); CompletableFuture<?> result = new CompletableFuture<>(); new Thread(() -> { try { process.waitFor(); } catch (InterruptedException e) { // ignore exception because thread is exiting } finally { result.complete(null); } }).start(); return unmodifiableFuture(result); }
/** * Returns a future that can not be completed or canceled. */ public static <V> CompletableFuture<V> unmodifiableFuture(CompletableFuture<V> future) { return unmodifiableFuture(future, false); }
/** * Returns a future that can not be completed or canceled. */ @Deprecated public static <V> CompletableFuture<V> unmodifiableFuture(CompletableFuture<V> future) { return unmodifiableFuture(future, false); }
/** * Returns a future that can not be completed or canceled. */ @Deprecated public static <V> CompletableFuture<V> unmodifiableFuture(CompletableFuture<V> future) { return unmodifiableFuture(future, false); }
public CompletableFuture<?> getFinishFuture() { checkState(process != null, "getFinishFuture called on null pager"); CompletableFuture<?> result = new CompletableFuture<>(); new Thread(() -> { try { process.waitFor(); } catch (InterruptedException e) { // ignore exception because thread is exiting } finally { result.complete(null); } }).start(); return unmodifiableFuture(result); }
public CompletableFuture<?> getFinishFuture() { checkState(process != null, "getFinishFuture called on null pager"); CompletableFuture<?> result = new CompletableFuture<>(); new Thread(() -> { try { process.waitFor(); } catch (InterruptedException e) { // ignore exception because thread is exiting } finally { result.complete(null); } }).start(); return unmodifiableFuture(result); }
private CompletableFuture<?> abortInternal() { CompletableFuture<List<Void>> futures = allAsList(connectorIdToMetadata.values().stream() .map(connection -> runAsync(() -> safeAbort(connection), finishingExecutor)) .collect(toList())); return unmodifiableFuture(futures); }
public CompletableFuture<?> asyncAbort(TransactionId transactionId) { return unmodifiableFuture(removeTransactionMetadataAsFuture(transactionId) .thenCompose(metadata -> metadata.asyncAbort())); }
public CompletableFuture<?> asyncCommit(TransactionId transactionId) { return unmodifiableFuture(removeTransactionMetadataAsFuture(transactionId) .thenCompose(metadata -> metadata.asyncCommit())); }
@Test public void testCompleteUnmodifiableFuture() throws Exception { CompletableFuture<String> future = new CompletableFuture<>(); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertTrue(future.complete("done")); assertEquals(future.getNow(null), "done"); assertTrue(unmodifiableFuture.isDone()); assertEquals(unmodifiableFuture.getNow(null), "done"); }
@Test public void testCompleteUnmodifiableFuture() throws Exception { CompletableFuture<String> future = new CompletableFuture<>(); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertTrue(future.complete("done")); assertEquals(future.getNow(null), "done"); assertTrue(unmodifiableFuture.isDone()); assertEquals(unmodifiableFuture.getNow(null), "done"); }
@Test public void testAlreadyCompleteUnmodifiableFuture() throws Exception { CompletableFuture<String> future = completedFuture("done"); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertEquals(future.getNow(null), "done"); assertTrue(unmodifiableFuture.isDone()); assertEquals(unmodifiableFuture.getNow(null), "done"); }
@Test public void testCompleteUnmodifiableFuture() throws Exception { CompletableFuture<String> future = new CompletableFuture<>(); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertTrue(future.complete("done")); assertEquals(future.getNow(null), "done"); assertTrue(unmodifiableFuture.isDone()); assertEquals(unmodifiableFuture.getNow(null), "done"); }
@Test public void testAlreadyCompleteUnmodifiableFuture() throws Exception { CompletableFuture<String> future = completedFuture("done"); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertEquals(future.getNow(null), "done"); assertTrue(unmodifiableFuture.isDone()); assertEquals(unmodifiableFuture.getNow(null), "done"); }
@Test public void testAlreadyCompleteUnmodifiableFuture() throws Exception { CompletableFuture<String> future = completedFuture("done"); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertEquals(future.getNow(null), "done"); assertTrue(unmodifiableFuture.isDone()); assertEquals(unmodifiableFuture.getNow(null), "done"); }
@Test public void testCompleteExceptionallyUnmodifiableFuture() throws Exception { CompletableFuture<String> future = new CompletableFuture<>(); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertTrue(future.completeExceptionally(new SQLException("foo"))); assertFailure(() -> getFutureValue(future, SQLException.class), e -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); assertTrue(unmodifiableFuture.isDone()); assertFailure(() -> getFutureValue(unmodifiableFuture, SQLException.class), e -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); }
@Test public void testCompleteExceptionallyUnmodifiableFuture() throws Exception { CompletableFuture<String> future = new CompletableFuture<>(); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertTrue(future.completeExceptionally(new SQLException("foo"))); assertFailure(() -> getFutureValue(future, SQLException.class), e -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); assertTrue(unmodifiableFuture.isDone()); assertFailure(() -> getFutureValue(unmodifiableFuture, SQLException.class), e -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); }
@Test public void testAlreadyCompleteExceptionallyUnmodifiableFuture() throws Exception { CompletableFuture<String> future = failedFuture(new SQLException("foo")); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertFailure(() -> getFutureValue(future, SQLException.class), e -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); assertTrue(unmodifiableFuture.isDone()); assertFailure(() -> getFutureValue(unmodifiableFuture, SQLException.class), e -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); }
@Test public void testAlreadyCompleteExceptionallyUnmodifiableFuture() throws Exception { CompletableFuture<String> future = failedFuture(new SQLException("foo")); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertFailure(() -> getFutureValue(future, SQLException.class), (e) -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); assertTrue(unmodifiableFuture.isDone()); assertFailure(() -> getFutureValue(unmodifiableFuture, SQLException.class), (e) -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); }
@Test public void testAlreadyCompleteExceptionallyUnmodifiableFuture() throws Exception { CompletableFuture<String> future = failedFuture(new SQLException("foo")); CompletableFuture<String> unmodifiableFuture = unmodifiableFuture(future); assertFailure(() -> getFutureValue(future, SQLException.class), e -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); assertTrue(unmodifiableFuture.isDone()); assertFailure(() -> getFutureValue(unmodifiableFuture, SQLException.class), e -> { assertInstanceOf(e, SQLException.class); assertEquals(e.getMessage(), "foo"); }); }