@Test public void testSetResultOnCompletedFuture() { ArrayList<Future<Object>> futures = new ArrayList<>(); futures.add(Future.succeededFuture()); futures.add(Future.succeededFuture()); futures.add(Future.succeededFuture(new Object())); futures.add(Future.succeededFuture(new Object())); futures.add(Future.failedFuture(new Exception())); futures.add(Future.failedFuture(new Exception())); for (Future<Object> future : futures) { try { future.complete(new Object()); fail(); } catch (IllegalStateException ignore) { } assertFalse(future.tryComplete(new Object())); try { future.complete(null); fail(); } catch (IllegalStateException ignore) { } assertFalse(future.tryComplete(null)); try { future.fail(new Exception()); fail(); } catch (IllegalStateException ignore) { } assertFalse(future.tryFail(new Exception())); } }
void handle(DnsResponse msg) { DnsResponseCode code = DnsResponseCode.valueOf(msg.code().intValue()); if (code == DnsResponseCode.NOERROR) { inProgressMap.remove(msg.id()); if (timerID >= 0) { vertx.cancelTimer(timerID); } int count = msg.count(DnsSection.ANSWER); List<T> records = new ArrayList<>(count); for (int idx = 0;idx < count;idx++) { DnsRecord a = msg.recordAt(DnsSection.ANSWER, idx); T record = RecordDecoder.decode(a); if (isRequestedType(a.type(), types)) { records.add(record); } } if (records.size() > 0 && (records.get(0) instanceof MxRecordImpl || records.get(0) instanceof SrvRecordImpl)) { Collections.sort((List) records); } actualCtx.executeFromIO(v -> { fut.tryComplete(records); }); } else { actualCtx.executeFromIO(new DnsException(code), this::fail); } }
@Override public boolean tryComplete() { return future.tryComplete(); }
@Override public boolean tryComplete(Boolean result) { return future.tryComplete(result); }
@Override public void end() { if (stream instanceof AsyncFile) { AsyncFile file = (AsyncFile) stream; file.close(ar -> { if (ar.succeeded()) { fut.tryComplete(); } else { fut.tryFail(ar.cause()); } }); } else { stream.end(); fut.tryComplete(); } }
@Test public void testSetResultOnCompletedFuture() { ArrayList<Future<Object>> futures = new ArrayList<>(); futures.add(Future.succeededFuture()); futures.add(Future.succeededFuture()); futures.add(Future.succeededFuture(new Object())); futures.add(Future.succeededFuture(new Object())); futures.add(Future.failedFuture(new Exception())); futures.add(Future.failedFuture(new Exception())); for (Future<Object> future : futures) { try { future.complete(new Object()); fail(); } catch (IllegalStateException ignore) { } assertFalse(future.tryComplete(new Object())); try { future.complete(null); fail(); } catch (IllegalStateException ignore) { } assertFalse(future.tryComplete(null)); try { future.fail(new Exception()); fail(); } catch (IllegalStateException ignore) { } assertFalse(future.tryFail(new Exception())); } }
void handle(DnsResponse msg) { DnsResponseCode code = DnsResponseCode.valueOf(msg.code().intValue()); if (code == DnsResponseCode.NOERROR) { inProgressMap.remove(msg.id()); if (timerID >= 0) { vertx.cancelTimer(timerID); } int count = msg.count(DnsSection.ANSWER); List<T> records = new ArrayList<>(count); for (int idx = 0;idx < count;idx++) { DnsRecord a = msg.recordAt(DnsSection.ANSWER, idx); T record = RecordDecoder.decode(a); if (isRequestedType(a.type(), types)) { records.add(record); } } if (records.size() > 0 && (records.get(0) instanceof MxRecordImpl || records.get(0) instanceof SrvRecordImpl)) { Collections.sort((List) records); } actualCtx.executeFromIO(v -> { fut.tryComplete(records); }); } else { actualCtx.executeFromIO(new DnsException(code), this::fail); } }
/** * Try to set the result. When it happens, any handler will be called, if there is one, and the future will be marked as completed. * @return false when the future is already completed */ public boolean tryComplete() { boolean ret = delegate.tryComplete(); return ret; }
/** * Try to set the result. When it happens, any handler will be called, if there is one, and the future will be marked as completed. * @return false when the future is already completed */ public boolean tryComplete() { boolean ret = delegate.tryComplete(); return ret; }
@Override public boolean tryComplete(Boolean result) { return future.tryComplete(result); }
@Override public boolean tryComplete() { return future.tryComplete(); }
@Override public boolean tryComplete() { return future.tryComplete(); }
@Override public boolean tryComplete(Boolean result) { return future.tryComplete(result); }
@Override public boolean tryComplete(Boolean result) { return future.tryComplete(result); }
@Override public boolean tryComplete() { return future.tryComplete(); }
/** * Set the failure. Any handler will be called, if there is one, and the future will be marked as completed. * @param result the result * @return false when the future is already completed */ public boolean tryComplete(T result) { boolean ret = delegate.tryComplete(__typeArg_0.<T>unwrap(result)); return ret; }
/** * Set the failure. Any handler will be called, if there is one, and the future will be marked as completed. * @param result the result * @return false when the future is already completed */ public boolean tryComplete(T result) { boolean ret = delegate.tryComplete(__typeArg_0.<T>unwrap(result)); return ret; }
public static boolean tryComplete(io.vertx.core.Future<Object> j_receiver, java.lang.Object result) { return j_receiver.tryComplete(io.vertx.core.impl.ConversionHelper.toObject(result)); } public static java.lang.Object result(io.vertx.core.Future<Object> j_receiver) {
@Override public void end() { if (stream instanceof AsyncFile) { AsyncFile file = (AsyncFile) stream; file.close(ar -> { if (ar.succeeded()) { fut.tryComplete(); } else { fut.tryFail(ar.cause()); } }); } else { stream.end(); fut.tryComplete(); } }
private Future<String> getToken(Vertx vertx, JsonObject conf) { Future<String> result = Future.future(); String token = conf.getString("token"); if (token != null && !token.trim().isEmpty()) { result.complete(token); return result; } // Read from file vertx.fileSystem().readFile(OPENSHIFT_KUBERNETES_TOKEN_FILE, ar -> { if (ar.failed()) { result.tryFail(ar.cause()); } else { result.tryComplete(ar.result().toString()); } }); return result; }