Refine search
/** * An alias for futures(stage, delay, unit) that uses a java.time.Duration. * * @param stage the input completion stage that may time out. * @param duration The duration after which there is a timeout. * @param <A> the completion stage that should be wrapped with a future. * @return the completion stage, or a completion stage that failed with futures. */ @Override public <A> CompletionStage<A> timeout(final CompletionStage<A> stage, final Duration duration) { requireNonNull(stage, "Null stage"); requireNonNull(duration, "Null duration"); FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.timeout(finiteDuration, Scala.asScalaWithFuture(() -> stage))); }
@Override public Future<play.api.mvc.Result> apply( Function1<play.api.mvc.RequestHeader, Future<play.api.mvc.Result>> next, play.api.mvc.RequestHeader requestHeader) { return FutureConverters.toScala( Filter.this.apply( (rh) -> FutureConverters.toJava(next.apply(rh.asScala())).thenApply(play.api.mvc.Result::asJava), requestHeader.asJava() ).thenApply(Result::asScala) ); } };
private static Result wrapScalaResult(scala.concurrent.Future<play.api.mvc.Result> result, long timeout) { if (result == null) { return null; } else { try { final play.api.mvc.Result scalaResult = FutureConverters.toJava(result).toCompletableFuture().get(timeout, TimeUnit.MILLISECONDS); return scalaResult.asJava(); } catch (ExecutionException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } else { throw new RuntimeException(e.getCause()); } } catch (InterruptedException | TimeoutException e) { throw new RuntimeException(e); } } }
@Override public <T> CompletionStage<T> getOrElseUpdate(String key, Callable<CompletionStage<T>> block, int expiration) { return toJava( asyncCacheApi.getOrElseUpdate(key, intToDuration(expiration), Scala.asScalaWithFuture(block), Scala.<T>classTag())); }
/** * Retrieve the URL where the user should be redirected to start the OpenID authentication process */ @Override public CompletionStage<String> redirectURL( String openID, String callbackURL, Map<String, String> axRequired, Map<String, String> axOptional, String realm) { if (axRequired == null) axRequired = new HashMap<>(); if (axOptional == null) axOptional = new HashMap<>(); return FutureConverters.toJava(client.redirectURL(openID, callbackURL, JavaConversions.mapAsScalaMap(axRequired).toSeq(), JavaConversions.mapAsScalaMap(axOptional).toSeq(), Scala.Option(realm))); }
/** * Convert this promise to a Scala future. * <p> * This is equivalent to FutureConverters.toScala(this), however, it converts the wrapped completion stage to * a future rather than this, which means if the wrapped completion stage itself wraps a Scala future, it will * simply return that wrapped future. * * @return A Scala future that is completed when this promise is completed. */ public Future<A> asScala() { return FutureConverters.toScala(wrapped); }
private static Result wrapScalaResult(scala.concurrent.Future<play.api.mvc.Result> result, long timeout) { if (result == null) { return null; } else { try { final play.api.mvc.Result scalaResult = FutureConverters.toJava(result).toCompletableFuture().get(timeout, TimeUnit.MILLISECONDS); return scalaResult.asJava(); } catch (ExecutionException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } else { throw new RuntimeException(e.getCause()); } } catch (InterruptedException | TimeoutException e) { throw new RuntimeException(e); } } }
@Override public <T> CompletionStage<T> getOrElseUpdate(String key, Callable<CompletionStage<T>> block, int expiration) { return toJava( asyncCacheApi.getOrElseUpdate(key, intToDuration(expiration), Scala.asScalaWithFuture(block), Scala.<T>classTag())); }
@Override public Future<A> apply(Option<E> v1) { return FutureConverters.toScala(strictHandler.apply(OptionConverters.toJava(v1))); } },
/** * An alias for futures(stage, delay, unit) that uses a java.time.Duration. * * @param stage the input completion stage that may time out. * @param duration The duration after which there is a timeout. * @param <A> the completion stage that should be wrapped with a future. * @return the completion stage, or a completion stage that failed with futures. */ @Override public <A> CompletionStage<A> timeout(final CompletionStage<A> stage, final Duration duration) { requireNonNull(stage, "Null stage"); requireNonNull(duration, "Null duration"); FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.timeout(finiteDuration, Scala.asScalaWithFuture(() -> stage))); }
@Override public Accumulator<ByteString, F.Either<Result, A>> apply(Http.RequestHeader request) { Flow<ByteString, ByteString, Future<MaxSizeStatus>> takeUpToFlow = Flow.fromGraph(play.api.mvc.BodyParsers$.MODULE$.takeUpTo(maxLength)); Sink<ByteString, CompletionStage<F.Either<Result, A>>> result = apply1(request).toSink(); return Accumulator.fromSink(takeUpToFlow.toMat(result, (statusFuture, resultFuture) -> FutureConverters.toJava(statusFuture).thenCompose(status -> { if (status instanceof MaxSizeNotExceeded$) { return resultFuture; } else { return errorHandler.onClientError(request, Status$.MODULE$.REQUEST_ENTITY_TOO_LARGE(), "Request entity too large") .thenApply(F.Either::<Result, A>Left); } }) )); }
@Override public <T> CompletionStage<T> getOrElseUpdate(String key, Callable<CompletionStage<T>> block, int expiration) { return toJava( asyncCacheApi.getOrElseUpdate(key, intToDuration(expiration), Scala.asScalaWithFuture(block), Scala.<T>classTag())); }
@Override public Future<play.api.mvc.Result> apply( Function1<play.api.mvc.RequestHeader, Future<play.api.mvc.Result>> next, play.api.mvc.RequestHeader requestHeader) { return FutureConverters.toScala( Filter.this.apply( (rh) -> FutureConverters.toJava(next.apply(rh.asScala())).thenApply(play.api.mvc.Result::asJava), requestHeader.asJava() ).thenApply(Result::asScala) ); } };
@Override public Future<A> apply(Option<E> v1) { return FutureConverters.toScala(strictHandler.apply(OptionConverters.toJava(v1))); } },