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

Scala MILLISECONDS类代码示例

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

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



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

示例1: getDuration

//设置package包名称以及导入依赖的类
package de.innfactory.bootstrap.utils

import com.typesafe.config.{Config, ConfigFactory}

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

trait Configuration {
  protected val config : Config = ConfigFactory.load()
  private val httpConfig = config.getConfig("http")
  private val databaseConfig = config.getConfig("database")
  private val authenticationConfig = config.getConfig("auth")

  val httpHost = httpConfig.getString("interface")
  val httpPort = httpConfig.getInt("port")
  val httpSelfTimeout = httpConfig.getDuration("self-timeout")

  val jdbcUrl = databaseConfig.getString("db.url")
  val dbUser = databaseConfig.getString("db.user")
  val dbPassword = databaseConfig.getString("db.password")

  val authCognito = authenticationConfig.getString("cognito")
  val allowAll = authenticationConfig.getBoolean("allow-all")

  private def getDuration(key: String) = FiniteDuration(config.getDuration(key, MILLISECONDS), MILLISECONDS)
} 
开发者ID:innFactory,项目名称:bootstrap-akka-http,代码行数:26,代码来源:Configuration.scala


示例2: KeepThisUp

//设置package包名称以及导入依赖的类
package com.darienmt.keepers

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.darienmt.keepers.CollectorManager.StartCollecting
import com.typesafe.config.{ Config, ConfigFactory }

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

object KeepThisUp {
  def apply(implicit system: ActorSystem, materializer: ActorMaterializer): Generator => Unit =
    apply(ConfigFactory.load())

  def apply(config: Config)(implicit system: ActorSystem, materializer: ActorMaterializer): Generator => Unit = {
    val retryConfig = RetryConfig(
      maxRetryPeriod = FiniteDuration(config.getDuration("retry.maxRetryPeriod").toMillis, MILLISECONDS),
      retryInterval = FiniteDuration(config.getDuration("retry.retryInterval").toMillis, MILLISECONDS),
      retryAutoResetPeriod = FiniteDuration(config.getDuration("retry.retryAutoResetPeriod").toMillis, MILLISECONDS),
      randomIntervalFactor = config.getDouble("retry.randomIntervalFactor")
    )
    apply(retryConfig)(_)
  }

  def apply(retryConfig: RetryConfig)(generator: Generator)(implicit system: ActorSystem, materializer: ActorMaterializer): Unit = {
    val collectorManager = system.actorOf(
      CollectorManager.props(
        Collector.props,
        generator,
        retryConfig
      )
    )
    collectorManager ! StartCollecting
  }
} 
开发者ID:darienmt,项目名称:airplane-adventures,代码行数:35,代码来源:KeepThisUp.scala


示例3: StopwatchSpec

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

import org.scalatest.{FlatSpec, Matchers}

import scala.concurrent.duration.{Duration, FiniteDuration, MILLISECONDS}

class StopwatchSpec extends FlatSpec with Matchers {
  "Stopwatch" should "spot time intervals" in {
    val stopwatch = Stopwatch.start()(new FixedClock(1, 10))
    stopwatch().toMillis shouldBe 10
    stopwatch().toMillis shouldBe 20
    stopwatch().toMillis shouldBe 30
  }

  it should "measure code blocks execution time" in {
    implicit val clock = new FixedClock(1, 10)
    val (result: Int, duration: Duration) = Stopwatch.measure { 42 }

    result shouldBe 42
    duration.toMillis shouldBe 10
  }
}


class FixedClock(from: Int, tick: Int) extends Clock {
  private val tickStream = Stream.from(from, tick).iterator
  override def currentTime: Duration = FiniteDuration(tickStream.next, MILLISECONDS)
} 
开发者ID:artem-kirillov,项目名称:stopwatch,代码行数:29,代码来源:StopwatchSpec.scala


示例4: TimerExt

//设置package包名称以及导入依赖的类
package com.wavesplatform.it

import com.wavesplatform.settings.Constants
import io.netty.util.Timer

import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.duration.{FiniteDuration, MILLISECONDS}

package object util {
  implicit class TimerExt(val timer: Timer) extends AnyVal {
    def schedule[A](f: => Future[A], delay: FiniteDuration): Future[A] = {
      val p = Promise[A]
      try {
        timer.newTimeout(_ => p.completeWith(f), delay.toMillis, MILLISECONDS)
      } catch {
        case t: Throwable => p.failure(t)
      }
      p.future
    }

    def retryUntil[A](f: => Future[A], cond: A => Boolean, retryInterval: FiniteDuration)
                     (implicit ec: ExecutionContext): Future[A] =
      f.flatMap(v => if (cond(v)) Future.successful(v) else schedule(retryUntil(f, cond, retryInterval), retryInterval))
  }
  implicit class LongExt(val l: Long) extends AnyVal {
    def waves: Long = l * Constants.UnitsInWave
  }
} 
开发者ID:wavesplatform,项目名称:Waves,代码行数:29,代码来源:package.scala


示例5: EventService

//设置package包名称以及导入依赖的类
package g8.akkahttp.eventsvc

import java.lang.management.ManagementFactory

import akka.actor.ActorSystem
import akka.event.Logging
import akka.http.scaladsl.server.{Directives, Route}
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._
import g8.akkahttp.eventsvc.data.access.{DataStoreComponent, MongoDataStoreImpl}

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

class EventService(system: ActorSystem) extends EventServiceTrait with MongoDataStoreImpl {

  override protected def log      = Logging(system, "service")
  override protected def executor = system.dispatcher
}

trait EventServiceTrait extends BaseComponent with DataStoreComponent with ResponseFactory {
  import Directives._
  import g8.akkahttp.eventsvc.data._
  import io.circe.generic.auto._

  def getStatus: Route = {
    log.info("/event executing")
    complete(Status(Duration(ManagementFactory.getRuntimeMXBean.getUptime, MILLISECONDS).toString()))
  }

  def readEvent(eventId: String): Route = {
    log.info("/event/read executing")
    complete(s"Requesting an event by Id: $eventId")
  }

  def createEvents(ecr: EventCreationRequest): Route = {
    log.info("/event/create executing")
    sendResponse(dataStore.createEvents(ecr.howMany))
  }

  def getEventsByType(triggerType: Int): Route = {
    log.info("/event/getEventsByType executing")
    sendResponse(
      for {
        events <- dataStore.getEventsByType(triggerType)
      } yield {
        events.map(_.toJson).mkString("[", ",", "]")
      }
    )
  }
} 
开发者ID:stephmajor,项目名称:eventsvc,代码行数:50,代码来源:EventService.scala


示例6: Settings

//设置package包名称以及导入依赖的类
package com.lightbend.dns.locator

import akka.actor.{ Actor, ExtendedActorSystem, Extension, ExtensionKey }

import scala.concurrent.duration.{ Duration, FiniteDuration, MILLISECONDS }
import com.typesafe.config.Config

import scala.util.matching.Regex
import scala.collection.JavaConversions._

object Settings extends ExtensionKey[Settings]


class Settings(system: ExtendedActorSystem) extends Extension {
  val nameTranslators: Seq[(Regex, String)] =
    serviceLocatorDns
      .getObjectList("name-translators")
      .toList
      .flatMap(_.toMap.map {
        case (k, v) => k.r -> v.unwrapped().toString
      })

  val srvTranslators: Seq[(Regex, String)] =
    serviceLocatorDns
      .getObjectList("srv-translators")
      .toList
      .flatMap(_.toMap.map {
        case (k, v) => k.r -> v.unwrapped().toString
      })

  val resolveTimeout1: FiniteDuration =
    duration(serviceLocatorDns, "resolve-timeout1")

  val resolveTimeout2: FiniteDuration =
    duration(serviceLocatorDns, "resolve-timeout2")

  private lazy val config = system.settings.config
  private lazy val serviceLocatorDns = config.getConfig("service-locator-dns")

  private def duration(config: Config, key: String): FiniteDuration =
    Duration(config.getDuration(key, MILLISECONDS), MILLISECONDS)
}

trait ActorSettings {
  this: Actor =>

  protected val settings: Settings =
    Settings(context.system)
} 
开发者ID:typesafehub,项目名称:service-locator-dns,代码行数:50,代码来源:Settings.scala


示例7: KamonLogstash

//设置package包名称以及导入依赖的类
package com.codekeepersinc.kamonlogstash

import akka.actor.{ ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider }
import akka.event.Logging
import MetricShipper.ShipperConfig
import com.typesafe.config.Config
import kamon.Kamon
import kamon.util.ConfigTools.Syntax

import scala.collection.JavaConverters._
import scala.concurrent.duration.{ FiniteDuration, MILLISECONDS }

object KamonLogstash extends ExtensionId[KamonLogstashExtension] with ExtensionIdProvider {
  override def createExtension(system: ExtendedActorSystem): KamonLogstashExtension = new KamonLogstashExtension(system)

  override def lookup(): ExtensionId[_ <: Extension] = KamonLogstash
}

class KamonLogstashExtension(system: ExtendedActorSystem) extends Kamon.Extension {
  val log = Logging(system, classOf[KamonLogstashExtension])
  log.info("Starting the Kamon Logstash extension")

  private val metricsExtension = Kamon.metrics

  private val config = system.settings.config
  private val logstashConfig = config.getConfig("kamon.logstash")

  private val appName = logstashConfig.getString("appname")
  private val hostName = logstashConfig.getString("hostname")

  private val shipperConfig = ShipperConfig(
    address = logstashConfig.getString("address"),
    port = logstashConfig.getInt("port"),
    minBackoff = FiniteDuration(logstashConfig.getDuration("retry.minBackoff").toMillis, MILLISECONDS),
    maxBackoff = FiniteDuration(logstashConfig.getDuration("retry.maxBackoff").toMillis, MILLISECONDS),
    randomFactor = logstashConfig.getDouble("retry.randomFactor"),
    retryAutoReset = FiniteDuration(logstashConfig.getDuration("retry.retryAutoReset").toMillis, MILLISECONDS)
  )

  private val shipper = system.actorOf(MetricShipper.props(shipperConfig), "metric-shipper")
  private val logger = system.actorOf(MetricLogger.props(appName, hostName, shipper), "subscription-logger")

  private val subscriptions: Config = logstashConfig.getConfig("subscriptions")

  subscriptions.firstLevelKeys.foreach { subscriptionCategory =>
    subscriptions.getStringList(subscriptionCategory).asScala.foreach { pattern =>
      metricsExtension.subscribe(subscriptionCategory, pattern, logger, permanently = true)
    }
  }
} 
开发者ID:darienmt,项目名称:kamon-logstash,代码行数:51,代码来源:KamonLogstash.scala


示例8: getDuration

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

import com.typesafe.config.{Config, ConfigFactory}

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

trait Configuration {
  protected val config : Config = ConfigFactory.load()
  private val httpConfig = config.getConfig("http")
  private val databaseConfig = config.getConfig("database")
  private val authenticationConfig = config.getConfig("auth")

  val httpHost = httpConfig.getString("interface")
  val httpPort = httpConfig.getInt("port")
  val httpSelfTimeout = httpConfig.getDuration("self-timeout")

  val jdbcUrl = databaseConfig.getString("db.url")
  val dbUser = databaseConfig.getString("db.user")
  val dbPassword = databaseConfig.getString("db.password")

  val authCognito = authenticationConfig.getString("cognito")
  val allowAll = authenticationConfig.getBoolean("allow-all")

  private def getDuration(key: String) = FiniteDuration(config.getDuration(key, MILLISECONDS), MILLISECONDS)
} 
开发者ID:innFactory,项目名称:bootstrap-akka-http.g8,代码行数:26,代码来源:Configuration.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala macros类代码示例发布时间:2022-05-23
下一篇:
Scala InetSocketTransportAddress类代码示例发布时间: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