Packages

  • package root
    Definition Classes
    root
  • package play

    Play framework.

    Play framework.

    Play

    http://www.playframework.com

    Definition Classes
    root
  • package api

    Contains the public API for Scala developers.

    Contains the public API for Scala developers.

    Access the current Play application
    import play.api.Play.current
    Read configuration
    val poolSize = configuration.getInt("engine.pool.size")
    Use the logger
    Logger.info("Hello!")
    Define a Plugin
    class MyPlugin(app: Application) extends Plugin
    Create adhoc applications (for testing)
    val application = Application(new File("."), this.getClass.getClassloader, None, Play.Mode.DEV)
    Definition Classes
    play
  • package libs

    Contains various APIs that are useful while developing web applications.

    Contains various APIs that are useful while developing web applications.

    Definition Classes
    api
  • package concurrent
    Definition Classes
    libs
  • ActorRefProvider
  • ActorSystemProvider
  • Akka
  • AkkaComponents
  • AkkaGuiceSupport
  • CoordinatedShutdownProvider
  • CustomExecutionContext
  • DefaultFutures
  • Execution
  • ExecutionContextProvider
  • Futures
  • InjectedActorSupport
  • LowPriorityFuturesImplicits
  • MaterializerProvider
  • Timeout
  • package crypto
    Definition Classes
    libs
  • package functional
    Definition Classes
    libs
  • package jcache
    Definition Classes
    libs
  • package json

    Json API For example:

    Json API For example:

    import play.api.libs.json._
    import play.api.libs.functional.syntax._
    
    case class User(id: Long, name: String, friends: Seq[User] = Seq.empty)
    object User {
    
      // In this format, an undefined friends property is mapped to an empty list
      implicit val format: Format[User] = (
        (__ \ "id").format[Long] and
        (__ \ "name").format[String] and
        (__ \ "friends").lazyFormatNullable(implicitly[Format[Seq[User]]])
          .inmap[Seq[User]](_ getOrElse Seq.empty, Some(_))
      )(User.apply, unlift(User.unapply))
    }
    
    //then in a controller:
    
    object MyController extends Controller {
       def displayUserAsJson(id: String) = Action {
          Ok(Json.toJson(User(id.toLong, "myName")))
       }
       def saveUser(jsonString: String)= Action {
         val user = Json.parse(jsonString).as[User]
         myDataStore.save(user)
         Ok
       }
    }
    Definition Classes
    libs
  • package logback
    Definition Classes
    libs
  • package openid
    Definition Classes
    libs
  • package streams
    Definition Classes
    libs
  • package typedmap
    Definition Classes
    libs
  • package ws

    Provides implicit type classes when you import the package.

    Provides implicit type classes when you import the package.

    Definition Classes
    libs
p

play.api.libs

concurrent

package concurrent

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

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

    Provider for creating actor refs

  2. class ActorSystemProvider extends Provider[ActorSystem]

    Provider for the actor system

    Provider for the actor system

    Annotations
    @Singleton()
  3. trait AkkaComponents extends AnyRef

    Components for configuring Akka.

  4. 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")
      }
    }

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

    class MyController @Inject() (@Named("myActor") myActor: ActorRef, val controllerComponents: ControllerComponents)
        extends BaseController {
      ...
    }
  5. class CoordinatedShutdownProvider extends Provider[CoordinatedShutdown]

    Provider for the coordinated shutdown

    Provider for the coordinated shutdown

    Annotations
    @Singleton()
  6. 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

  7. class DefaultFutures extends Futures

    ActorSystem based timeout.

  8. class ExecutionContextProvider extends Provider[ExecutionContextExecutor]

    Provider for the default execution context

    Provider for the default execution context

    Annotations
    @Singleton()
  9. 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

  10. trait InjectedActorSupport extends AnyRef

    Support for creating injected child actors.

  11. 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
    }
  12. class MaterializerProvider extends Provider[Materializer]

    Provider for the default flow materializer

    Provider for the default flow materializer

    Annotations
    @Singleton()
  13. trait Timeout extends AnyRef

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

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

    Please note that the play.api.Application default ActorSystem should be used as input here, as the actorSystem.scheduler is responsible for scheduling the timeout, using akka.pattern.actor under the hood.

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

    class MyService(val actorSystem: ActorSystem) extends Timeout {
    
      def calculateWithTimeout(timeoutDuration: FiniteDuration): Future[Int] = {
        timeout(actorSystem, timeoutDuration)(rawCalculation())
      }
    
      def rawCalculation(): Future[Int] = {
        import akka.pattern.after
        implicit val ec = actorSystem.dispatcher
        akka.pattern.after(300 millis, actorSystem.scheduler)(Future(42))(actorSystem.dispatcher)
      }
    }

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

    val future = myService.calculateWithTimeout(100 millis).recover {
      case _: TimeoutException =>
        -1
    }
    Annotations
    @deprecated
    Deprecated

    (Since version 2.6.0) Use play.api.libs.concurrent.Futures.timeout

    See also

    Futures and Promises

Value Members

  1. object ActorSystemProvider
  2. object Akka

    Helper to access the application defined Akka Actor system.

  3. object Futures extends LowPriorityFuturesImplicits

Deprecated Value Members

  1. object Execution
    Annotations
    @deprecated
    Deprecated

    (Since version 2.6.0) Please see https://www.playframework.com/documentation/2.6.x/Migration26#play.api.libs.concurrent.Execution-is-deprecated

  2. object Timeout extends Timeout with LowPriorityFuturesImplicits

    This is a static object that can be used to import timeout implicits, as a convenience.

    This is a static object that can be used to import timeout implicits, as a convenience.

    import play.api.libs.concurrent.Timeout._
    Annotations
    @deprecated
    Deprecated

    (Since version 2.6.0) Use play.api.libs.concurrent.Futures

Ungrouped