本文整理汇总了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)
}
示例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
}
}
示例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)
}
示例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
}
}
示例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("[", ",", "]")
}
)
}
}
示例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)
}
示例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)
}
}
}
示例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)
}