/** * Retrieve the application Akka Actor system. */ public static ActorSystem system() { return play.api.libs.concurrent.Akka.system(Play.current()); }
/** * Create a provider for an actor implemented by the given class, with the given name. * * This will instantiate the actor using Play's injector, allowing it to be dependency injected itself. The returned * provider will provide the ActorRef for the actor, allowing it to be injected into other components. * * Typically, you will want to use this in combination with a named qualifier, so that multiple ActorRefs can be * bound, and the scope should be set to singleton or eager singleton. * * @param <T> the type of the actor * @param actorClass The class that implements the actor. * @param name The name of the actor. * @param props A function to provide props for the actor. The props passed in will just describe how to create the * actor, this function can be used to provide additional configuration such as router and dispatcher * configuration. * @return A provider for the actor. */ public static <T extends Actor> Provider<ActorRef> providerOf(Class<T> actorClass, String name, Function<Props, Props> props) { return new ActorRefProvider<T>(name, new AbstractFunction1<Props, Props>() { public Props apply(Props p) { return props.apply(p); } }, ClassTag$.MODULE$.apply(actorClass)); }
private ActorSystem createActorSystem() { return new ActorSystemProvider( environment().asScala(), configuration() ).get(); }
private CoordinatedShutdown createCoordinatedShutdown() { return new CoordinatedShutdownProvider( actorSystem(), applicationLifecycle().asScala() ).get(); }
@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))); }
/** * 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))); }
private ActorSystem createActorSystem() { return new ActorSystemProvider( environment().asScala(), configuration() ).get(); }
private CoordinatedShutdown createCoordinatedShutdown() { return new CoordinatedShutdownProvider( actorSystem(), applicationLifecycle().asScala() ).get(); }
/** * Create a provider for an actor implemented by the given class, with the given name. * * This will instantiate the actor using Play's injector, allowing it to be dependency injected itself. The returned * provider will provide the ActorRef for the actor, allowing it to be injected into other components. * * Typically, you will want to use this in combination with a named qualifier, so that multiple ActorRefs can be * bound, and the scope should be set to singleton or eager singleton. * * @param <T> the type of the actor * @param actorClass The class that implements the actor. * @param name The name of the actor. * @param props A function to provide props for the actor. The props passed in will just describe how to create the * actor, this function can be used to provide additional configuration such as router and dispatcher * configuration. * @return A provider for the actor. */ public static <T extends Actor> Provider<ActorRef> providerOf(Class<T> actorClass, String name, Function<Props, Props> props) { return new ActorRefProvider<T>(name, new AbstractFunction1<Props, Props>() { public Props apply(Props p) { return props.apply(p); } }, ClassTag$.MODULE$.apply(actorClass)); }
@Override public CompletionStage<Done> delay(Duration duration) { FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.delay(finiteDuration)); }
/** * Creates a CompletionStage that returns either the input stage, or a futures. * * Note that timeout is not the same as cancellation. Even in case of futures, * the given completion stage will still complete, even though that completed value * is not returned. * * @param stage the input completion stage that may time out. * @param amount The amount (expressed with the corresponding unit). * @param unit The time Unit. * @param <A> the completion's result type. * @return either the completed future, or a completion stage that failed with futures. */ @Override public <A> CompletionStage<A> timeout(final CompletionStage<A> stage, final long amount, final TimeUnit unit) { requireNonNull(stage, "Null stage"); requireNonNull(unit, "Null unit"); FiniteDuration duration = FiniteDuration.apply(amount, unit); return toJava(delegate.timeout(duration, Scala.asScalaWithFuture(() -> stage))); }
private ActorSystem createActorSystem() { return new ActorSystemProvider( environment().asScala(), configuration() ).get(); }
private CoordinatedShutdown createCoordinatedShutdown() { return new CoordinatedShutdownProvider( actorSystem(), applicationLifecycle().asScala() ).get(); }
/** * Create a provider for an actor implemented by the given class, with the given name. * * This will instantiate the actor using Play's injector, allowing it to be dependency injected itself. The returned * provider will provide the ActorRef for the actor, allowing it to be injected into other components. * * Typically, you will want to use this in combination with a named qualifier, so that multiple ActorRefs can be * bound, and the scope should be set to singleton or eager singleton. * * @param actorClass The class that implements the actor. * @param name The name of the actor. * @param props A function to provide props for the actor. The props passed in will just describe how to create the * actor, this function can be used to provide additional configuration such as router and dispatcher * configuration. * @return A provider for the actor. */ public static <T extends Actor> Provider<ActorRef> providerOf(Class<T> actorClass, String name, Function<Props, Props> props) { return new ActorRefProvider<T>(name, new AbstractFunction1<Props, Props>() { public Props apply(Props p) { return props.apply(p); } }, ClassTag$.MODULE$.apply(actorClass)); }
@Override public CompletionStage<Done> delay(long amount, TimeUnit unit) { FiniteDuration finiteDuration = FiniteDuration.apply(amount, unit); return toJava(delegate.delay(finiteDuration)); }
/** * Create a provider for an actor implemented by the given class, with the given name. * * This will instantiate the actor using Play's injector, allowing it to be dependency injected itself. The returned * provider will provide the ActorRef for the actor, allowing it to be injected into other components. * * Typically, you will want to use this in combination with a named qualifier, so that multiple ActorRefs can be * bound, and the scope should be set to singleton or eager singleton. * * @param <T> the type of the actor * @param actorClass The class that implements the actor. * @param name The name of the actor. * @param props A function to provide props for the actor. The props passed in will just describe how to create the * actor, this function can be used to provide additional configuration such as router and dispatcher * configuration. * @return A provider for the actor. */ public static <T extends Actor> Provider<ActorRef> providerOf(Class<T> actorClass, String name, Function<Props, Props> props) { return new ActorRefProvider<T>(name, new AbstractFunction1<Props, Props>() { public Props apply(Props p) { return props.apply(p); } }, ClassTag$.MODULE$.apply(actorClass)); }
@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(Duration duration) { FiniteDuration finiteDuration = FiniteDuration.apply(duration.toMillis(), TimeUnit.MILLISECONDS); return toJava(delegate.delay(finiteDuration)); }