/** * Combine the given promises into a single promise for the list of results. * <p> * The sequencing operations are performed in the default ExecutionContext. * * @param promises The promises to combine * @return A single promise whose methods act on the list of redeemed promises * Use {@link Futures#sequence(Iterable)} instead. */ public static <A> Promise<List<A>> sequence(Iterable<Promise<A>> promises) { return wrap(Futures.sequence(promises)); }
/** * Create a Promise timer that throws a PromiseTimeoutException after * a given timeout. * <p> * The returned Promise is usually combined with other Promises. * * @param delay The delay expressed in milliseconds. * Use {@link Futures#timeout(long, TimeUnit)} instead. * @return a promise without a real value */ public static Promise<Void> timeout(long delay) { return wrap(Futures.timeout(delay, TimeUnit.MILLISECONDS)); }
/** * Combine the given promises into a single promise for the list of results. * <p> * The sequencing operations are performed in the default ExecutionContext. * * @param promises The promises to combine * @return A single promise whose methods act on the list of redeemed promises * Use {@link Futures#sequence(CompletionStage[])} instead. */ public static <A> Promise<List<A>> sequence(Promise<A>... promises) { return wrap(Futures.sequence(Arrays.asList(promises))); }
/** * Create a Promise that is redeemed after a timeout. * * @param message The message to use to redeem the Promise. * @param delay The delay expressed in milliseconds. * Use {@link Futures#timeout(Object, long, TimeUnit)} instead. */ public static <A> Promise<A> timeout(A message, long delay) { return wrap(Futures.timeout(message, delay, TimeUnit.MILLISECONDS)); }
/** * Create a Promise which, after a delay, will be redeemed with the result of a * given function. The function will be called after the delay. * * @param function The function to call to fulfill the Promise. * @param delay The time to wait. * @param unit The units to use for the delay. * Use {@link Futures#delayed(Supplier, long, TimeUnit, Executor)} instead. */ public static <A> Promise<A> delayed(Supplier<A> function, long delay, TimeUnit unit, Executor ec) { return wrap(Futures.delayed(function, delay, unit, (ec))); }
/** * Create a Promise timer that throws a PromiseTimeoutException after * a given timeout. * <p> * The returned Promise is usually combined with other Promises. * * @param delay The delay (expressed with the corresponding unit). * @param unit The Unit. * @return a promise without a real value * Use {@link Futures#timeout(long, TimeUnit)} instead. */ public static Promise<Void> timeout(long delay, TimeUnit unit) { return wrap(Futures.timeout(delay, unit)); }
public Promise<A> getPromise(){ return Promise.wrap(promise.future()); }
/** * Create a Promise which, after a delay, will be redeemed with the result of a * given function. The function will be called after the delay. * <p> * The function will be run in the default ExecutionContext. * * @param function The function to call to fulfill the Promise. * @param delay The time to wait. * @param unit The units to use for the delay. * Use {@link Futures#delayed(Supplier, long, TimeUnit, Executor)} with * {@link Execution#httpPromiseContext()} instead. */ public static <A> Promise<A> delayed(Supplier<A> function, long delay, TimeUnit unit) { return wrap(Futures.delayed(function, delay, unit, Execution.httpPromiseContext())); }
@Override public Promise<HttpResponse> execute(HttpHost host, HttpUriRequest req) { lastAccessAt = System.currentTimeMillis(); final scala.concurrent.Promise<HttpResponse> promise = Futures.promise(); HystrixCmd cmd = new HystrixCmd(httpclient,host,req,this); cmd.observe().subscribe(new Observer<HttpResponse>() { @Override public void onCompleted() {} @Override public void onError(Throwable throwable) { promise.failure(throwable); } @Override public void onNext(HttpResponse o) { promise.success(o); } }); return Promise.wrap(promise.future()); }
httpclient.execute(req, new NFutureCallback(circuitBreaker, xPromise)); return Promise.wrap(xPromise.future()); }else{ Throwable shortCircuitException = new RuntimeException("Hystrix circuit short-circuited and is OPEN");
public static <A> Promise<A> makeHTTP(final Tracer tracer,final HttpUriRequest req, final HTTPHandler<A> handler, final HTTPInvokerContext context){ final scala.concurrent.Promise<A> xPromise = handler.getPromise(); final CompletableFuture<A> xFuture = null; final Promise<A> promise = Promise.wrap(xFuture); try{ final ILoadBalancer loadBalancer = context.getLoadBalancer() == null ? HostLoadBalancer.getLoadBalancer(req.getURI()) : context.getLoadBalancer(); final HTTPInvoker invoke = HTTPInvoker.builder() .withHttpClient(context.getHttpClient()) .withLoadBalancer(loadBalancer) .withRetryHandler(context.getRetryHandler()) .withHttpRequest(req) .withHttpHandler(handler) .withExecutionContext(context.getExecutionContext()) .withTracer(tracer) .build(); invoke.run(); }catch (Throwable e){ xPromise.failure(e); } return promise; } }