当前位置: 首页>>代码示例>>Scala>>正文


Scala ApplicationLifecycle类代码示例

本文整理汇总了Scala中play.api.inject.ApplicationLifecycle的典型用法代码示例。如果您正苦于以下问题:Scala ApplicationLifecycle类的具体用法?Scala ApplicationLifecycle怎么用?Scala ApplicationLifecycle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ApplicationLifecycle类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: ApplicationTimer

//设置package包名称以及导入依赖的类
package services

import java.time.{Clock, Instant}
import javax.inject._
import play.api.Logger
import play.api.inject.ApplicationLifecycle
import scala.concurrent.Future


@Singleton
class ApplicationTimer @Inject() (clock: Clock, appLifecycle: ApplicationLifecycle) {

  // This code is called when the application starts.
  private val start: Instant = clock.instant
  Logger.info(s"ApplicationTimer demo: Starting application at $start.")

  // When the application starts, register a stop hook with the
  // ApplicationLifecycle object. The code inside the stop hook will
  // be run when the application stops.
  appLifecycle.addStopHook { () =>
    val stop: Instant = clock.instant
    val runningTime: Long = stop.getEpochSecond - start.getEpochSecond
    Logger.info(s"ApplicationTimer demo: Stopping application at ${clock.instant} after ${runningTime}s.")
    Future.successful(())
  }
} 
开发者ID:sarathraj-coder,项目名称:play2_6curd_rest,代码行数:27,代码来源:ApplicationTimer.scala

示例2: ApplicationTimer

//设置package包名称以及导入依赖的类
package services

import java.time.{Clock, Instant}
import javax.inject._
import play.api.Logger
import play.api.inject.ApplicationLifecycle
import scala.concurrent.Future


@Singleton
class ApplicationTimer @Inject() (clock: Clock, appLifecycle: ApplicationLifecycle) {

  // This code is called when the application starts.
  private val start: Instant = clock.instant
  Logger.info(s"ApplicationTimer demo: Starting application at ${start}.")

  // When the application starts, register a stop hook with the
  // ApplicationLifecyle object. The code inside the stop hook wil
  // be run when the application stops.
  appLifecycle.addStopHook { () =>
    val stop: Instant = clock.instant
    val runningTime: Long = stop.getEpochSecond - start.getEpochSecond
    Logger.info(s"ApplicationTimer demo: Stopping application at ${clock.instant} after ${runningTime}s.")
    Future.successful(())
  }
} 
开发者ID:mendelmiranda,项目名称:play-scala-crud,代码行数:27,代码来源:ApplicationTimer.scala

示例3: ApplicationTimer

//设置package包名称以及导入依赖的类
package services

import java.time.{Clock, Instant}
import javax.inject._

import play.api.Logger
import play.api.inject.ApplicationLifecycle

import scala.concurrent.Future


@Singleton
class ApplicationTimer @Inject() (clock: Clock, appLifecycle: ApplicationLifecycle) {

  // This code is called when the application starts.
  private val start: Instant = clock.instant
  Logger.info(s"ApplicationTimer demo: Starting application at $start.")

  // When the application starts, register a stop hook with the
  // ApplicationLifecycle object. The code inside the stop hook will
  // be run when the application stops.
  appLifecycle.addStopHook { () =>
    val stop: Instant = clock.instant
    val runningTime: Long = stop.getEpochSecond - start.getEpochSecond
    Logger.info(s"ApplicationTimer demo: Stopping application at ${clock.instant} after ${runningTime}s.")
    Future.successful(())
  }
} 
开发者ID:aNkM,项目名称:homework-pokemon,代码行数:29,代码来源:ApplicationTimer.scala

示例4: ApplicationTimer

//设置package包名称以及导入依赖的类
package services

import java.time.{Clock, Instant}
import javax.inject._
import play.api.Logger
import play.api.inject.ApplicationLifecycle
import scala.concurrent.Future


@Singleton
class ApplicationTimer @Inject() (clock: Clock, appLifecycle: ApplicationLifecycle) {

  // This code is called when the application starts.
  private val start: Instant = clock.instant
  Logger.info(s"ApplicationTimer demo: Starting application at $start.")

  // When the application starts, register a stop hook with the
  // ApplicationLifecycle object. The code inside the stop hook wil
  // be run when the application stops.
  appLifecycle.addStopHook { () =>
    val stop: Instant = clock.instant
    val runningTime: Long = stop.getEpochSecond - start.getEpochSecond
    Logger.info(s"ApplicationTimer demo: Stopping application at ${clock.instant} after ${runningTime}s.")
    Future.successful(())
  }
} 
开发者ID:kunalherkal,项目名称:rental-manager,代码行数:27,代码来源:ApplicationTimer.scala

示例5: ApplicationTimer

//设置package包名称以及导入依赖的类
package services

import java.time.{Clock, Instant}
import javax.inject._
import play.api.Logger
import play.api.inject.ApplicationLifecycle
import scala.concurrent.Future


@Singleton
class ApplicationTimer @Inject()(clock: Clock, appLifecycle: ApplicationLifecycle) {

  // This code is called when the application starts.
  private val start: Instant = clock.instant
  Logger.info(s"ApplicationTimer demo: Starting application at $start.")

  // When the application starts, register a stop hook with the
  // ApplicationLifecycle object. The code inside the stop hook will
  // be run when the application stops.
  appLifecycle.addStopHook { () =>
    val stop: Instant     = clock.instant
    val runningTime: Long = stop.getEpochSecond - start.getEpochSecond
    Logger.info(s"ApplicationTimer demo: Stopping application at ${clock.instant} after ${runningTime}s.")
    Future.successful(())
  }
} 
开发者ID:digital-wonderland,项目名称:play-webpack-typescript-react,代码行数:27,代码来源:ApplicationTimer.scala

示例6: ApplicationTimer

//设置package包名称以及导入依赖的类
package modules.samples

import java.time.{Clock, Instant}
import java.util.concurrent.TimeUnit
import javax.inject.{Inject, Singleton}

import akka.actor.ActorSystem
import com.github.sample.utils.Loggable
import play.api.inject.ApplicationLifecycle

import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration._

@Singleton
class ApplicationTimer @Inject() (clock: Clock, appLifecycle: ApplicationLifecycle, actorSystem: ActorSystem) extends Loggable {

  implicit val myExecutionContext: ExecutionContext = actorSystem.dispatcher

  private val start: Instant = clock.instant
  logger.info(s"ApplicationTimer demo: Starting application at $start.")

  actorSystem.scheduler.schedule(Duration.Zero, Duration.create(10, TimeUnit.SECONDS)) {
    logger.info(clock.instant.toString)
  }

  // When the application starts, register a stop hook with the
  // ApplicationLifecycle object. The code inside the stop hook will
  // be run when the application stops.
  appLifecycle.addStopHook { () =>
    val stop: Instant = clock.instant
    val runningTime: Long = stop.getEpochSecond - start.getEpochSecond
    logger.info(s"ApplicationTimer demo: Stopping application at ${clock.instant} after ${runningTime}s.")
    Future.successful(())
  }
} 
开发者ID:tm-sukehiro,项目名称:play2-sandbox,代码行数:36,代码来源:ApplicationTimer.scala

示例7: CassandraAsyncContextImpl

//设置package包名称以及导入依赖的类
package data

import javax.inject.{Inject, Singleton}

import com.datastax.driver.core.{Cluster, Session}
import com.typesafe.config.Config
import io.getquill.{CassandraAsyncContext, SnakeCase}
import play.api.inject.ApplicationLifecycle
import play.api.{Configuration, Environment, Logger}
import util.FutureUtils.toFutureUnit

import scala.concurrent.ExecutionContext

@Singleton
class CassandraAsyncContextImpl @Inject()(cassandra: CassandraCluster, conf: CassandraConfig)
  extends CassandraAsyncContext[SnakeCase](cassandra.cluster, conf.keySpace, 100L)

@Singleton
class CassandraCluster @Inject()(conf: CassandraConfig, appLifecycle: ApplicationLifecycle)(implicit executor: ExecutionContext) {

  import conf._

  private[data] val cluster =
    Cluster.builder()
      .addContactPoints(hosts: _*)
      .withPort(port)
      .build()

  private[data] def noKeySpaceSession: Session = cluster.connect()

  private[data] def stop() = toFutureUnit(cluster.closeAsync())

  Logger.info(s"Cassandra host to be used: '${hosts.mkString(",")}' with port:$port")
  appLifecycle.addStopHook(() => stop())
}

@Singleton
class CassandraConfig @Inject()(configuration: Configuration, environment: Environment) {
  val config: Config = configuration.underlying

  val keySpace = config.getString("devgym.db.cassandra.keyspace")
  val port = config.getInt("devgym.db.cassandra.port")

  val hosts: Seq[String] =
    configuration.getStringSeq("devgym.db.cassandra.hosts").get
} 
开发者ID:DmytroOrlov,项目名称:devgym,代码行数:47,代码来源:CassandraCluster.scala

示例8: ApplicationTimer

//设置package包名称以及导入依赖的类
package com.ddn.wechat.service

import java.time.{Clock, Instant}
import javax.inject._
import play.api.Logger
import play.api.inject.ApplicationLifecycle
import scala.concurrent.Future


@Singleton
class ApplicationTimer @Inject() (clock: Clock, appLifecycle: ApplicationLifecycle) {

  // This code is called when the application starts.
  private val start: Instant = clock.instant
  Logger.info(s"ApplicationTimer demo: Starting application at ${start}.")

  // When the application starts, register a stop hook with the
  // ApplicationLifecyle object. The code inside the stop hook wil
  // be run when the application stops.
  appLifecycle.addStopHook { () =>
    val stop: Instant = clock.instant
    val runningTime: Long = stop.getEpochSecond - start.getEpochSecond
    Logger.info(s"ApplicationTimer demo: Stopping application at ${clock.instant} after ${runningTime}s.")
    Future.successful(())
  }
} 
开发者ID:ivyy,项目名称:ddn-wechat,代码行数:27,代码来源:ApplicationTimer.scala

示例9: DatabaseProductService

//设置package包名称以及导入依赖的类
package service

import javax.inject.{Inject, Singleton}

import com.outworkers.phantom.dsl.context
import com.typesafe.scalalogging.StrictLogging
import model.db.ProdDb
import model.domain.{Category, CategoryDistribution, StoreProduct}
import play.api.Environment
import play.api.inject.ApplicationLifecycle

import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NoStackTrace

@Singleton
class DatabaseProductService @Inject()(
  environment: Environment,
  applicationLifecycle: ApplicationLifecycle
)(
  implicit exec: ExecutionContext
) extends StoreFront with StrictLogging with ProdDb {

  
  override def getProduct(title: String): Future[Option[StoreProduct]] = {
    database.products.findByTitle(title)
  }

  override def addProductToCategory(title: String, category: Category): Future[Unit] = {
    getProduct(title) flatMap {
      case Some(product) =>
        for {
          cat <- database.productsByCategory.store(category, product)
          prod <- database.products.addCategory(title, category)
        } yield ()

      case None => Future.failed(new Exception(s"Could not find product with title $title") with NoStackTrace)
    }
  }

  override def addProduct(product: StoreProduct): Future[Unit] = {
    for {
      _ <- database.products.store(product)
      cats <- Future.sequence(product.categories.values.map(c => database.productsByCategory.store(c, product)))
    } yield ()

  }
} 
开发者ID:alexflav23,项目名称:exercises,代码行数:48,代码来源:DatabaseProductService.scala


注:本文中的play.api.inject.ApplicationLifecycle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。