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); } } }
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 CompletionStage<Done> delay(Duration duration) { FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.delay(finiteDuration)); }
@Override public CompletionStage<Done> delay(Duration duration) { FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.delay(finiteDuration)); }
@Override public CompletionStage<Done> delay(Duration duration) { FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.delay(finiteDuration)); }
/** * 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 CompletionStage<Done> delay(long amount, TimeUnit unit) { FiniteDuration finiteDuration = FiniteDuration.apply(amount, unit); return toJava(delegate.delay(finiteDuration)); }
@Override public CompletionStage<Done> delay(long amount, TimeUnit unit) { FiniteDuration finiteDuration = FiniteDuration.apply(amount, unit); return toJava(delegate.delay(finiteDuration)); }
@Override public CompletionStage<Done> delay(long amount, TimeUnit unit) { FiniteDuration finiteDuration = FiniteDuration.apply(amount, unit); return toJava(delegate.delay(finiteDuration)); }
/** * Create a CompletionStage which, after a delay, will be redeemed with the result of a * given supplier. The supplier will be called after the delay. * * @param callable the input completion stage that is delayed. * @param duration to wait. * @param <A> the type of the completion's result. * @return the delayed CompletionStage wrapping supplier. */ @Override public <A> CompletionStage<A> delayed(final Callable<CompletionStage<A>> callable, Duration duration) { requireNonNull(callable, "Null callable"); requireNonNull(duration, "Null duration"); FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.delayed(finiteDuration, Scala.asScalaWithFuture(callable))); }
/** * 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))); }
/** * Create a CompletionStage which, after a delay, will be redeemed with the result of a * given supplier. The supplier will be called after the delay. * * @param callable the input completion stage that is delayed. * @param duration to wait. * @param <A> the type of the completion's result. * @return the delayed CompletionStage wrapping supplier. */ @Override public <A> CompletionStage<A> delayed(final Callable<CompletionStage<A>> callable, Duration duration) { requireNonNull(callable, "Null callable"); requireNonNull(duration, "Null duration"); FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.delayed(finiteDuration, Scala.asScalaWithFuture(callable))); }
/** * 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))); }
/** * Create a CompletionStage which, after a delay, will be redeemed with the result of a * given supplier. The supplier will be called after the delay. * * @param callable the input completion stage that is delayed. * @param duration to wait. * @param <A> the type of the completion's result. * @return the delayed CompletionStage wrapping supplier. */ @Override public <A> CompletionStage<A> delayed(final Callable<CompletionStage<A>> callable, Duration duration) { requireNonNull(callable, "Null callable"); requireNonNull(duration, "Null duration"); FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.delayed(finiteDuration, Scala.asScalaWithFuture(callable))); }
@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<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<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 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 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 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); } }) )); }