• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala _类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: HermesGameTickerConfig

//设置package包名称以及导入依赖的类
package proton.game.hermes

import java.time.LocalDateTime
import java.util.UUID

import proton.game._

import scala.concurrent.duration.{FiniteDuration, _}

class HermesGameTickerConfig(val gameFile: UUID, override val players: Seq[Player],
                             override val startTime: Option[LocalDateTime],
                             override val tickDuration: FiniteDuration,
                             override val timeoutDuration: Option[FiniteDuration]) extends GameTickerConfig {
  override val minPlayers: Option[Int] = Some(1)
  override val maxPlayers: Option[Int] = None
}

case class HermesGameTickerConfigFactory(gameFile: UUID, players: Seq[PlayerIdentity], startTime: Option[LocalDateTime],
                                         tickDuration: Option[FiniteDuration], timeoutDuration: Option[FiniteDuration])
  extends GameTickerConfigFactory[HermesGameTickerConfig] {

  override def build(): HermesGameTickerConfig = {
    new HermesGameTickerConfig(gameFile, players.map(p => Player(p)), startTime,
      tickDuration.getOrElse(200.milliseconds), timeoutDuration)
  }
} 
开发者ID:Morgan-Stanley,项目名称:proton,代码行数:27,代码来源:HermesGameConfig.scala


示例2: ServiceMockFacade

//设置package包名称以及导入依赖的类
package mesosphere.marathon.integration.setup

import akka.actor.ActorSystem
import mesosphere.marathon.integration.facades.ITEnrichedTask
import org.slf4j.LoggerFactory
import play.api.libs.json.{ JsValue, Json }
import spray.client.pipelining._
import spray.http.HttpResponse

import scala.concurrent.duration.{ Duration, _ }

class ServiceMockFacade(task: ITEnrichedTask, waitTime: Duration = 30.seconds)(implicit system: ActorSystem) {
  import scala.concurrent.ExecutionContext.Implicits.global

  val log = LoggerFactory.getLogger(classOf[ServiceMockFacade])

  val baseUrl = s"http://${task.host}:${task.ports.map(_.head).get}"

  val pipeline = sendReceive

  def continue(): RestResult[HttpResponse] = {
    log.info(s"Continue with the service migration: $baseUrl/v1/plan/continue")
    RestResult.await(pipeline(Post(s"$baseUrl/v1/plan/continue")), waitTime)
  }

  def plan(): RestResult[JsValue] = {
    RestResult.await(pipeline(Get(s"$baseUrl/v1/plan")), waitTime).map(_.entity.asString).map(Json.parse)
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:30,代码来源:ServiceMockFacade.scala


示例3: AppMockFacade

//设置package包名称以及导入依赖的类
package mesosphere.marathon.integration.setup

import akka.actor.ActorSystem
import org.slf4j.LoggerFactory
import spray.client.pipelining._

import scala.concurrent.duration.{ Duration, _ }
import scala.util.Try

class AppMockFacade(https: Boolean = false, waitTime: Duration = 30.seconds)(implicit system: ActorSystem) {
  import scala.concurrent.ExecutionContext.Implicits.global

  private[this] val log = LoggerFactory.getLogger(getClass)

  private[this] def retry[T](retries: Int = 200, waitForNextTry: Duration = 50.milliseconds)(block: => T): T = {
    val attempts = Iterator(Try(block)) ++ Iterator.continually(Try {
      Thread.sleep(waitForNextTry.toMillis)
      block
    })
    val firstSuccess = attempts.take(retries - 1).find(_.isSuccess).flatMap(_.toOption)
    firstSuccess.getOrElse(block)
  }

  val pipeline = sendReceive
  def ping(host: String, port: Int): RestResult[String] = custom("/ping")(host, port)

  def scheme: String = if (https) "https" else "http"

  def custom(uri: String)(host: String, port: Int): RestResult[String] = {
    retry() {
      RestResult.await(pipeline(Get(s"$scheme://$host:$port$uri")), waitTime).map(_.entity.asString)
    }
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:35,代码来源:AppMockFacade.scala


示例4: ElasticWriteConfig

//设置package包名称以及导入依赖的类
package com.yannick_cw.elastic_indexer4s.elasticsearch.elasic_config

import com.sksamuel.elastic4s.TcpClient
import org.elasticsearch.common.settings.Settings
import org.joda.time.DateTime

import scala.concurrent.duration.{FiniteDuration, _}

case class ElasticWriteConfig(
  hosts: List[String],
  port: Int,
  cluster: String,
  indexPrefix: String,
  docType: String,
  mappingSetting: MappingSetting = TypedMappingSetting(),
  writeBatchSize: Int = 50,
  writeConcurrentRequest: Int = 10,
  writeMaxAttempts: Int = 5,
  logWriteSpeedEvery: FiniteDuration = 1 minute,
  waitForElasticTimeout: FiniteDuration = 5 seconds
) {
  val indexName = indexPrefix + "_" + new DateTime().toString("yyyy-MM-dd't'HH:mm:ss")
  private def settings = Settings.builder().put("cluster.name", cluster).build()
  lazy val client: TcpClient = TcpClient.transport(settings, "elasticsearch://" + hosts
    .map(host => s"$host:$port").mkString(","))
}

object ElasticWriteConfig {
  def apply(
    esTargetHosts: List[String],
    esTargetPort: Int,
    esTargetCluster: String,
    esTargetIndexPrefix: String,
    esTargetType: String
  ): ElasticWriteConfig =
    new ElasticWriteConfig(esTargetHosts, esTargetPort, esTargetCluster, esTargetIndexPrefix, esTargetType)
} 
开发者ID:yannick-cw,项目名称:elastic-indexer4s,代码行数:38,代码来源:ElasticWriteConfig.scala


示例5: CronExpressionService

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

import com.cronutils.model.CronType
import com.cronutils.model.definition.CronDefinitionBuilder
import com.cronutils.model.time.ExecutionTime
import com.cronutils.parser.CronParser
import io.cronit.utils.Clock
import io.cronit.utils.ClockUtils._
import org.joda.time.DateTime

import scala.concurrent.duration.{Duration, _}

trait CronExpressionComponent {

  val cronExpressionService: CronExpressionService
  val cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX)
  val cronParser = new CronParser(cronDefinition)

  class CronExpressionService {
    def getNextExecutionDate(expression: String) = {
      val cron = cronParser.parse(expression)
      ExecutionTime.forCron(cron).nextExecution(Clock.asZonedDateTime).toJoda
    }

    def getFiniteDurationFromNow(dateTime: DateTime) = {
      val now = Clock.now()
      val diff = dateTime.getMillis - now.getMillis
      Duration(diff, MILLISECONDS)
    }
  }

} 
开发者ID:212data,项目名称:cronit-service,代码行数:33,代码来源:CronExpressionComponent.scala


示例6: Worker

//设置package包名称以及导入依赖的类
import CounterService._
import Worker._
import akka.actor.SupervisorStrategy.Stop
import akka.actor._
import akka.event.LoggingReceive
import akka.pattern.{ask, pipe}
import akka.util.Timeout

import scala.concurrent.duration.{Duration, _}


class Worker extends Actor with ActorLogging {

  implicit val askTimeout = Timeout(5 seconds)

  // Stop the CounterService child if it throws ServiceUnavailable
  override val supervisorStrategy = OneForOneStrategy() {
    case _: CounterService.ServiceUnavailable => Stop
  }

  // The sender of the initial Start message will continuously be notified
  // about progress
  var progressListener: Option[ActorRef] = None
  val counterService = context.actorOf(Props[CounterService], name = "counter")
  val totalCount = 51

  import context.dispatcher

  // Use this Actors' Dispatcher as ExecutionContext

  def receive = LoggingReceive {
    case Start if progressListener.isEmpty =>
      progressListener = Some(sender())
      context.system.scheduler.schedule(Duration.Zero, 1 second, self, Do)

    case Do =>
      counterService ! Increment(1)
      counterService ! Increment(1)
      counterService ! Increment(1)

      // Send current progress to the initial sender
      counterService ? GetCurrentCount map {
        case CurrentCount(_, count) => Progress(100.0 * count / totalCount)
      } pipeTo progressListener.get
  }
}

object Worker {

  case object Start

  case object Do

  final case class Progress(percent: Double)

} 
开发者ID:liwei1987,项目名称:study-akka,代码行数:57,代码来源:Worker.scala


示例7: setupDb

//设置package包名称以及导入依赖的类
package au.com.agiledigital.dao.slick.test

import au.com.agiledigital.dao.slick.JdbcProfileProvider
import org.scalatest._
import slick.backend.DatabasePublisher

import scala.concurrent.duration.{ FiniteDuration, _ }
import scala.concurrent.{ Await, ExecutionContext }
import scala.language.postfixOps
import scala.util.{ Failure, Success }

trait DbSuite extends BeforeAndAfterAll with Matchers with OptionValues with TryValues {

  self: Suite with JdbcProfileProvider =>

  import driver.api._

  def setupDb: driver.backend.DatabaseDef

  private lazy val database: driver.backend.DatabaseDef = setupDb

  override protected def afterAll(): Unit = {
    database.close()
  }

  def query[T](dbAction: DBIO[T])(implicit ex: ExecutionContext, timeout: FiniteDuration = 5 seconds): T =
    runAction(dbAction)

  def stream[T](dbAction: StreamingDBIO[T, T])(implicit ex: ExecutionContext, timeout: FiniteDuration = 5 seconds): DatabasePublisher[T] = {
    database.stream(dbAction.transactionally)
  }

  def commit[T](dbAction: DBIO[T])(implicit ex: ExecutionContext, timeout: FiniteDuration = 5 seconds): T =
    runAction(dbAction.transactionally)

  def rollback[T](dbAction: DBIO[T])(implicit ex: ExecutionContext, timeout: FiniteDuration = 5 seconds): T = {

    case class RollbackException(expected: T) extends RuntimeException("rollback exception")

    val markedForRollback = dbAction.flatMap { result =>
      DBIO
        .failed(RollbackException(result))
        .map(_ => result)
    }.transactionally.asTry

    val finalAction =
      markedForRollback.map {
        case Success(result) => result
        case Failure(RollbackException(result)) => result
        case Failure(other) => throw other
      }

    runAction(finalAction)
  }

  private def runAction[T](dbAction: DBIO[T])(implicit ex: ExecutionContext, timeout: FiniteDuration): T = {
    val result = database.run(dbAction)
    Await.result(result, timeout)
  }

} 
开发者ID:agiledigital,项目名称:slick-dao,代码行数:62,代码来源:DbSuite.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala WSPut类代码示例发布时间:2022-05-23
下一篇:
Scala NoStackTrace类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap