Packages

p

play.api.libs

concurrent

package concurrent

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. Protected

Type Members

  1. trait ActorModule extends AbstractModule

    Facilitates runtime dependency injection of "functional programming"-style actor behaviors.

    Facilitates runtime dependency injection of "functional programming"-style actor behaviors.

    1. Mix this trait into the object defining the actor message(s) and behavior(s); 2. Define the Message type with actor message class; 3. Annotate with Provides the "create" method that returns the (possibly just initial) Behavior of the actor; 4. Use the bindTypedActor in AkkaGuiceSupport, passing the object as the actor module.

    For example:

    object ConfiguredActor extends ActorModule {
      type Message = GetConfig
    
      final case class GetConfig(replyTo: ActorRef[String])
    
      @Provides def apply(configuration: Configuration): Behavior[GetConfig] = {
        // TODO: Define ConfiguredActor's behavior using the injected configuration.
        Behaviors.empty
      }
    }
    
    final class AppModule extends AbstractModule with AkkaGuiceSupport {
      override def configure() = {
        bindTypedActor(ConfiguredActor, "configured-actor")
      }
    }

    Message is a type member rather than a type parameter is because you can't define, using the example above, GetConfig inside the object and also have the object extend ActorModule[ConfiguredActor.GetConfig].

    Annotations
    @ApiMayChange()
    See also

    https://doc.akka.io/docs/akka/2.6/typed/style-guide.html#functional-versus-object-oriented-style

  2. class ActorRefProvider[T <: Actor] extends Provider[ActorRef]

    Provider for creating actor refs

  3. class ActorSystemProvider extends Provider[ActorSystem]

    Provider for the actor system

    Provider for the actor system

    Annotations
    @Singleton()
  4. trait AkkaComponents extends AnyRef

    Components for configuring Akka.

  5. trait AkkaGuiceSupport extends AnyRef

    Support for binding actors with Guice.

    Support for binding actors with Guice.

    Mix this trait in with a Guice AbstractModule to get convenient support for binding actors. For example:

    class MyModule extends AbstractModule with AkkaGuiceSupport {
      def configure = {
        bindActor[MyActor]("myActor")
        bindTypedActor(HelloActor(), "hello-actor")
      }
    }

    Then to use the above actor in your application, add a qualified injected dependency, like so:

    class MyController @Inject() (
        @Named("myActor") myActor: ActorRef,
        helloActor: ActorRef[HelloActor.SayHello],
        val controllerComponents: ControllerComponents,
    ) extends BaseController {
      ...
    }
  6. class AkkaSchedulerProvider extends Provider[Scheduler]

    Provider for an Akka Typed Scheduler.

    Provider for an Akka Typed Scheduler.

    Annotations
    @Singleton()
  7. trait AkkaTypedComponents extends AnyRef

    Akka Typed components.

  8. class ClassicActorSystemProviderProvider extends Provider[ClassicActorSystemProvider]

    Provider for a classic actor system provide

    Provider for a classic actor system provide

    Annotations
    @Singleton()
  9. class CoordinatedShutdownProvider extends Provider[CoordinatedShutdown]

    Provider for the coordinated shutdown

    Provider for the coordinated shutdown

    Annotations
    @Singleton()
  10. abstract class CustomExecutionContext extends ExecutionContextExecutor

    This class defines a custom execution context that delegates to an akka.actor.ActorSystem.

    This class defines a custom execution context that delegates to an akka.actor.ActorSystem.

    It is very useful for situations in which the default execution context should not be used, for example if a database or blocking I/O is being used.

    To define a custom context, subclass CustomExecutionContext with the dispatcher name:

    @Singleton
    class DatabaseExecutionContext @Inject()(system: ActorSystem)
       extends CustomExecutionContext(system, "database-dispatcher")

    and then bind it in dependency injection:

    bind[DatabaseExecutionContext].to(classOf[DatabaseExecutionContext]).asEagerSingleton()

    Then have the execution context passed in as an implicit parameter:

    class DatabaseService @Inject()(implicit executionContext: DatabaseExecutionContext) {
      ...
    }
    See also

    Dispatchers

    Thread Pools

  11. class DefaultFutures extends Futures

    ActorSystem based timeout.

  12. class ExecutionContextProvider extends Provider[ExecutionContextExecutor]

    Provider for the default execution context

    Provider for the default execution context

    Annotations
    @Singleton()
  13. trait Futures extends AnyRef

    This trait is used to provide non-blocking timeouts and delays on an operation that returns a Future.

    This trait is used to provide non-blocking timeouts and delays on an operation that returns a Future.

    You can dependency inject the Futures as follows to create a Future that will timeout after a certain period of time:

    class MyService @Inject()(futures: Futures, piCalculator: PiCalculator) extends Timeout {
      def calculateWithTimeout(timeoutDuration: FiniteDuration): Future[Int] = {
        futures.timeout(timeoutDuration)(piCalculator.rawCalculation())
      }
    }

    And you can also use a delay to return data after a given period of time.

    class PiCalculator @Inject()(futures: Futures) {
      def rawCalculation(): Future[Int] = {
        futures.delay(300 millis) { Future.successful(42) }
      }
    }

    You should check for timeout by using scala.concurrent.Future.recover or scala.concurrent.Future.recoverWith and checking for scala.concurrent.TimeoutException:

    val future = myService.calculateWithTimeout(100 millis).recover {
      case _: TimeoutException =>
        -1
    }
    See also

    Futures and Promises

  14. trait InjectedActorSupport extends AnyRef

    Support for creating injected child actors.

  15. trait LowPriorityFuturesImplicits extends AnyRef

    Low priority implicits to add withTimeout methods to scala.concurrent.Future.

    Low priority implicits to add withTimeout methods to scala.concurrent.Future.

    You can dependency inject the ActorSystem as follows to create a Future that will timeout after a certain period of time:

    class MyService @Inject()(piCalculator: PiCalculator)(implicit futures: Futures) {
    
      def calculateWithTimeout(timeoutDuration: FiniteDuration): Future[Int] = {
         piCalculator.rawCalculation().withTimeout(timeoutDuration)
      }
    }

    You should check for timeout by using scala.concurrent.Future.recover or scala.concurrent.Future.recoverWith and checking for scala.concurrent.TimeoutException:

    val future = myService.calculateWithTimeout(100 millis).recover {
      case _: TimeoutException =>
        -1
    }
  16. class MaterializerProvider extends Provider[Materializer]

    Provider for the default flow materializer

    Provider for the default flow materializer

    Annotations
    @Singleton()
  17. final class TypedActorRefProvider[T] extends Provider[ActorRef[T]]

    A singleton Provider of the typed ActorRef[T] resulting from spawning an actor with the Behavior[T] in dependency scope and the given name, in the ActorSystem in dependency scope.

    A singleton Provider of the typed ActorRef[T] resulting from spawning an actor with the Behavior[T] in dependency scope and the given name, in the ActorSystem in dependency scope.

    T

    The class of the messages the typed actor can handle.

    Annotations
    @Singleton() @ApiMayChange()

Value Members

  1. object ActorModule

    The companion object to hold ActorModule's ActorModule.Aux type alias.

    The companion object to hold ActorModule's ActorModule.Aux type alias.

    Annotations
    @ApiMayChange()
  2. object ActorSystemProvider
  3. object Akka

    Helper to access the application defined Akka Actor system.

  4. object Futures extends LowPriorityFuturesImplicits

Ungrouped