List of usage examples for java.util.concurrent CompletableFuture completeExceptionally
public boolean completeExceptionally(Throwable ex)
From source file:com.ikanow.aleph2.aleph2_rest_utils.DataStoreCrudService.java
@Override public CompletableFuture<Boolean> deleteObjectById(Object id) { try {//from w w w . ja v a 2 s .co m final Path path = new Path(output_directory + id.toString()); _logger.debug("Trying to delete: " + path.toString()); final boolean delete_success = fileContext.delete(path, false); //this is always returning false _logger.debug("success deleteing: " + delete_success); return CompletableFuture.completedFuture(!doesPathExist(path, fileContext)); //if file does not exist, delete was a success } catch (IllegalArgumentException | IOException e) { final CompletableFuture<Boolean> fut = new CompletableFuture<Boolean>(); fut.completeExceptionally(e); return fut; } }
From source file:com.ikanow.aleph2.aleph2_rest_utils.DataStoreCrudService.java
@Override public CompletableFuture<Cursor<FileDescriptor>> getObjectsBySpec(QueryComponent<FileDescriptor> spec) { try {/*ww w. j av a 2s. c o m*/ return CompletableFuture .completedFuture(new DataStoreCursor(getFolderFilenames(output_directory, fileContext))); } catch (IllegalArgumentException | IOException e) { final CompletableFuture<Cursor<FileDescriptor>> fut = new CompletableFuture<Cursor<FileDescriptor>>(); fut.completeExceptionally(e); return fut; } }
From source file:com.ikanow.aleph2.aleph2_rest_utils.DataStoreCrudService.java
@Override public CompletableFuture<Cursor<FileDescriptor>> getObjectsBySpec(QueryComponent<FileDescriptor> spec, List<String> field_list, boolean include) { try {/*from w ww . jav a 2 s. c o m*/ return CompletableFuture .completedFuture(new DataStoreCursor(getFolderFilenames(output_directory, fileContext))); } catch (IllegalArgumentException | IOException e) { final CompletableFuture<Cursor<FileDescriptor>> fut = new CompletableFuture<Cursor<FileDescriptor>>(); fut.completeExceptionally(e); return fut; } }
From source file:com.canoo.dolphin.client.impl.ClientContextImpl.java
@Override public synchronized CompletableFuture<Void> disconnect() { checkForInitializedState();//from w w w.j a v a2s .c o m state = State.DESTROYING; clientDolphin.stopPushListening(); final CompletableFuture<Void> result = new CompletableFuture<>(); Executors.newSingleThreadExecutor().execute(() -> { state = State.DESTROYED; dolphinCommandHandler.invokeDolphinCommand(PlatformConstants.DESTROY_CONTEXT_COMMAND_NAME) .handle((v, t) -> { if (t != null) { result.completeExceptionally(new DolphinRemotingException("Can't disconnect", t)); } else { result.complete(null); } return null; }); //TODO: Stop communication in client connector }); return result; }
From source file:io.sqp.client.impl.SqpConnectionImpl.java
private boolean checkOpenAndNoErrors(CompletableFuture<?> future) { if (_pendingError != null) { future.completeExceptionally(_pendingError); _pendingError = null;//from w w w . ja v a 2 s .c o m return false; } if (!_state.equals(ConnectionState.ReadyToSend) && !_state.equals(ConnectionState.Connecting)) { future.completeExceptionally(new ConnectionException(_state.getDescription())); return false; } return true; }
From source file:io.sqp.client.impl.SqpConnectionImpl.java
private CompletableFuture<Void> finishTransaction(boolean commit) { String mode = commit ? "commit" : "rollback"; CompletableFuture<Void> future = new CompletableFuture<>(); if (_autocommit) { future.completeExceptionally( new InvalidOperationException("Cannot " + mode + " a transaction in autocommit mode")); return future; }//from w w w . j ava 2 s .co m if (!checkOpenAndNoErrors(future)) { return future; } SqpMessage finishMessage = commit ? new CommitTransactionMessage() : new RollbackTransactionMessage(); send(finishMessage, new ConfirmationResponseHandler(future, MessageType.TransactionFinishedMessage, "waiting for a " + mode + " complete confirmation")); return future; }
From source file:co.runrightfast.vertx.demo.testHarness.jmx.DemoMXBeanImpl.java
@Override public String lookupIPAddress(final String dnsServer, final String host) { final DnsClient client = vertx.createDnsClient(53, dnsServer); final CompletableFuture<String> future = new CompletableFuture<>(); client.lookup("vertx.io", result -> { if (result.succeeded()) { future.complete(result.result()); } else {/*from www. ja v a 2 s.co m*/ future.completeExceptionally(result.cause()); } }); try { return future.get(); } catch (final InterruptedException | ExecutionException ex) { throw new RuntimeException(ex); } }
From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.RenovatorTest.java
@Test public void testHaltingScenario() throws DeserializeException, LoginException, RepositoryException, InterruptedException, ExecutionException, PersistenceException { assertEquals("Renovator: relocator test", instance.getName()); Map<String, Object> values = new HashMap<>(); values.put("sourceJcrPath", "/content/dam/folderA"); values.put("destinationJcrPath", "/content/dam/folderB"); instance.init(rr, values);//from w w w.j a va 2s.c o m CompletableFuture<Boolean> f = new CompletableFuture<>(); instance.defineAction("Halt", rr, am -> { instance.halt(); try { assertTrue(instance.updateProgress() < 1.0); assertFalse(instance.getInfo().isIsRunning()); f.complete(true); } catch (Throwable t) { f.completeExceptionally(t); } }); instance.run(rr); assertTrue(f.get()); verify(rr, atLeastOnce()).commit(); }
From source file:io.pravega.client.stream.mock.MockController.java
private CompletableFuture<Void> createSegmentTx(UUID txId, Segment segment) { CompletableFuture<Void> result = new CompletableFuture<>(); FailingReplyProcessor replyProcessor = new FailingReplyProcessor() { @Override// ww w . j a va 2 s . c o m public void connectionDropped() { result.completeExceptionally(new ConnectionClosedException()); } @Override public void wrongHost(WrongHost wrongHost) { result.completeExceptionally(new NotImplementedException()); } @Override public void transactionCreated(TransactionCreated transactionCreated) { result.complete(null); } @Override public void processingFailure(Exception error) { result.completeExceptionally(error); } }; sendRequestOverNewConnection(new CreateTransaction(idGenerator.get(), segment.getScopedName(), txId), replyProcessor, result); return result; }
From source file:io.pravega.client.stream.mock.MockController.java
private CompletableFuture<Void> commitTxSegment(UUID txId, Segment segment) { CompletableFuture<Void> result = new CompletableFuture<>(); FailingReplyProcessor replyProcessor = new FailingReplyProcessor() { @Override//from ww w. j ava 2 s . c om public void connectionDropped() { result.completeExceptionally(new ConnectionClosedException()); } @Override public void wrongHost(WrongHost wrongHost) { result.completeExceptionally(new NotImplementedException()); } @Override public void transactionCommitted(TransactionCommitted transactionCommitted) { result.complete(null); } @Override public void transactionAborted(TransactionAborted transactionAborted) { result.completeExceptionally(new TxnFailedException("Transaction already aborted.")); } @Override public void processingFailure(Exception error) { result.completeExceptionally(error); } }; sendRequestOverNewConnection(new CommitTransaction(idGenerator.get(), segment.getScopedName(), txId), replyProcessor, result); return result; }