本文整理了Java中scala.compat.java8.FutureConverters.toJava()
方法的一些代码示例,展示了FutureConverters.toJava()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FutureConverters.toJava()
方法的具体详情如下:
包路径:scala.compat.java8.FutureConverters
类名称:FutureConverters
方法名:toJava
暂无
代码示例来源:origin: com.typesafe.play/play-test_2.12
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);
}
}
}
代码示例来源:origin: com.typesafe.play/play-test_2.11
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);
}
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
@Override
public CompletionStage<Done> delay(Duration duration) {
FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS);
return toJava(delegate.delay(finiteDuration));
}
代码示例来源:origin: com.typesafe.play/play
@Override
public CompletionStage<Done> delay(Duration duration) {
FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS);
return toJava(delegate.delay(finiteDuration));
}
代码示例来源:origin: com.typesafe.play/play_2.12
@Override
public CompletionStage<Done> delay(Duration duration) {
FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS);
return toJava(delegate.delay(finiteDuration));
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* 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)));
}
代码示例来源:origin: com.typesafe.play/play_2.12
@Override
public CompletionStage<Done> delay(long amount, TimeUnit unit) {
FiniteDuration finiteDuration = FiniteDuration.apply(amount, unit);
return toJava(delegate.delay(finiteDuration));
}
代码示例来源:origin: com.typesafe.play/play
@Override
public CompletionStage<Done> delay(long amount, TimeUnit unit) {
FiniteDuration finiteDuration = FiniteDuration.apply(amount, unit);
return toJava(delegate.delay(finiteDuration));
}
代码示例来源:origin: com.typesafe.play/play_2.11
@Override
public CompletionStage<Done> delay(long amount, TimeUnit unit) {
FiniteDuration finiteDuration = FiniteDuration.apply(amount, unit);
return toJava(delegate.delay(finiteDuration));
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* 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)));
}
代码示例来源:origin: com.typesafe.play/play
/**
* 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)));
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* 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)));
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* 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)));
}
代码示例来源:origin: com.typesafe.play/play
/**
* 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)));
}
代码示例来源:origin: com.typesafe.play/play_2.12
@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)
);
}
};
代码示例来源:origin: com.typesafe.play/play_2.11
@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)
);
}
};
代码示例来源:origin: com.typesafe.play/play
@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)
);
}
};
代码示例来源:origin: com.typesafe.play/play_2.12
@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);
}
})
));
}
代码示例来源:origin: com.typesafe.play/play
@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);
}
})
));
}
代码示例来源:origin: com.typesafe.play/play_2.11
@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);
}
})
));
}
内容来源于网络,如有侵权,请联系作者删除!