本文整理汇总了Scala中akka.actor.ExtensionIdProvider类的典型用法代码示例。如果您正苦于以下问题:Scala ExtensionIdProvider类的具体用法?Scala ExtensionIdProvider怎么用?Scala ExtensionIdProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExtensionIdProvider类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SettingsImpl
//设置package包名称以及导入依赖的类
import akka.actor.{ExtendedActorSystem, ExtensionIdProvider, ExtensionId, Extension}
import com.typesafe.config._
class SettingsImpl(config: Config) extends Extension {
object Http {
lazy val interface = config.getString("http.interface")
lazy val port = config.getInt("http.port")
}
}
object Settings extends ExtensionId[SettingsImpl] with ExtensionIdProvider {
override def lookup = Settings
override def createExtension(system: ExtendedActorSystem) =
new SettingsImpl(system.settings.config)
}
示例2: InfluxDbConfig
//设置package包名称以及导入依赖的类
package io.soheila.cms.services.metrics.influx
import akka.actor.{ ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider }
import com.typesafe.config.Config
class InfluxDbConfig(config: Config) extends Extension {
val host: String = config.getString("influxDb.host")
val port: Int = config.getInt("influxDb.port")
val username: String = config.getString("influxDb.username")
val password: String = config.getString("influxDb.password")
val database: String = config.getString("influxDb.database")
}
object InfluxDbConfig extends ExtensionId[InfluxDbConfig] with ExtensionIdProvider {
override def lookup() = InfluxDbConfig
override def createExtension(system: ExtendedActorSystem): InfluxDbConfig =
new InfluxDbConfig(system.settings.config)
}
示例3: trade
//设置package包名称以及导入依赖的类
package akka.performance.trading.domain
import java.util.concurrent.atomic.AtomicInteger
import akka.actor.{ ExtensionIdProvider, ExtensionId, Extension, ExtendedActorSystem, ActorSystem }
abstract trait TradeObserver {
def trade(bid: Bid, ask: Ask)
}
trait TotalTradeObserver extends TradeObserver {
def system: ActorSystem
private lazy val counter: TotalTradeCounter = TotalTradeCounterExtension(system)
override def trade(bid: Bid, ask: Ask) {
counter.increment()
}
}
trait NopTradeObserver extends TradeObserver {
override def trade(bid: Bid, ask: Ask) {
}
}
class TotalTradeCounter extends Extension {
private val counter = new AtomicInteger
def increment() = counter.incrementAndGet()
def reset() {
counter.set(0)
}
def count: Int = counter.get
}
object TotalTradeCounterExtension
extends ExtensionId[TotalTradeCounter]
with ExtensionIdProvider {
override def lookup = TotalTradeCounterExtension
override def createExtension(system: ExtendedActorSystem) = new TotalTradeCounter
}
示例4: TransactorExtension
//设置package包名称以及导入依赖的类
package akka.transactor
import akka.actor.{ ActorSystem, ExtensionId, ExtensionIdProvider, ExtendedActorSystem }
import akka.actor.Extension
import com.typesafe.config.Config
import akka.util.Timeout
import scala.concurrent.duration.Duration
import java.util.concurrent.TimeUnit.MILLISECONDS
@deprecated("akka.transactor will be removed", "2.3")
object TransactorExtension extends ExtensionId[TransactorSettings] with ExtensionIdProvider {
override def get(system: ActorSystem): TransactorSettings = super.get(system)
override def lookup: TransactorExtension.type = TransactorExtension
override def createExtension(system: ExtendedActorSystem): TransactorSettings = new TransactorSettings(system.settings.config)
}
@deprecated("akka.transactor will be removed", "2.3")
class TransactorSettings(val config: Config) extends Extension {
import config._
val CoordinatedTimeout: Timeout = Timeout(Duration(getMilliseconds("akka.transactor.coordinated-timeout"), MILLISECONDS))
}
示例5: SettingsImpl
//设置package包名称以及导入依赖的类
package com.edu.chat
import akka.actor.{ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider}
import com.typesafe.config.Config
class SettingsImpl(config: Config) extends Extension {
val dbUsername: String = config.getString("mongo.username")
val dbPassword: Array[Char] = config.getString("mongo.password").toCharArray
val dbHost: String = config.getString("mongo.host")
val dbName: String = config.getString("mongo.db")
val dbPort: Int = config.getInt("mongo.port")
val webPort: Int = config.getInt("web.port")
val staticContentPath: String = config.getString("web.staticContent")
val clientIndexPath: String = config.getString("web.client")
}
object Settings extends ExtensionId[SettingsImpl] with ExtensionIdProvider {
override def createExtension(system: ExtendedActorSystem): SettingsImpl = {
new SettingsImpl(system.settings.config)
}
override def lookup(): ExtensionId[_ <: Extension] = Settings
}
示例6: UserConfigExtension
//设置package包名称以及导入依赖的类
package im.actor.server.userconfig
import akka.actor.{ ActorSystem, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider }
import im.actor.api.rpc.configs.UpdateParameterChanged
import im.actor.hook.{ Hook2, Hook3, HooksStorage2, HooksStorage3 }
import im.actor.server.db.DbExtension
import im.actor.server.model.configs.Parameter
import im.actor.server.persist.configs.ParameterRepo
import im.actor.server.sequence.{ SeqState, SeqUpdatesExtension }
import im.actor.types._
import scala.concurrent.Future
object UserConfigExtension extends ExtensionId[UserConfigExtension] with ExtensionIdProvider {
override def createExtension(system: ExtendedActorSystem) = new UserConfigExtension(system)
override def lookup(): ExtensionId[_ <: Extension] = UserConfigExtension
}
final class UserConfigExtension(system: ActorSystem) extends Extension {
import system.dispatcher
private lazy val db = DbExtension(system).db
private lazy val seqUpdExt = SeqUpdatesExtension(system)
val hooks = new HooksStorage3[EditParameterHook, Any, UserId, String, Option[String]]()
def fetchParameters(userId: Int): Future[Seq[(String, Option[String])]] = {
for {
params ? db.run(ParameterRepo.find(userId))
} yield params.map(p ? p.key ? p.value)
}
def editParameter(userId: Int, authId: Long, rawKey: String, value: Option[String]): Future[SeqState] = {
val key = rawKey.trim
val update = UpdateParameterChanged(key, value)
for {
_ ? db.run(ParameterRepo.createOrUpdate(Parameter(userId, key, value)))
seqState ? seqUpdExt.deliverClientUpdate(userId, authId, update)
} yield {
seqUpdExt.reloadSettings(userId)
seqState
}
}
}
trait EditParameterHook extends Hook3[Any, UserId, String, Option[String]]
示例7: Settings
//设置package包名称以及导入依赖的类
package com.mikemunhall.simpletwitterstats
import akka.actor.{ActorContext, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider}
import com.typesafe.config.Config
object Settings extends ExtensionId[Settings] with ExtensionIdProvider {
override def lookup = Settings
override def createExtension(system: ExtendedActorSystem) = new Settings(system.settings.config, system)
def apply(context: ActorContext): Settings = apply(context.system)
}
class Settings(config: Config, extendedSystem: ExtendedActorSystem) extends Extension {
object API {
object Http {
val Port = config.getInt("simple-twitter-stats.api.http.port")
val Interface = config.getString("simple-twitter-stats.api.http.interface")
}
}
object Server {
object Twitter {
object Client {
object OAuth {
object Consumer {
val key = config.getString("simple-twitter-stats.server.twitter.client.oauth.consumer.key")
val secret = config.getString("simple-twitter-stats.server.twitter.client.oauth.consumer.secret")
}
object Access {
val token = config.getString("simple-twitter-stats.server.twitter.client.oauth.access.token")
val secret = config.getString("simple-twitter-stats.server.twitter.client.oauth.access.secret")
}
}
}
}
}
}
示例8: DbConnectionPoolExtension
//设置package包名称以及导入依赖的类
package org.guangwenz.akka.db.connpool
import java.sql.Connection
import java.util.UUID
import akka.actor.{ActorRef, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider, Props}
import akka.pattern.ask
import akka.util.Timeout
import org.guangwenz.akka.db.connpool.ConnectionPool.{DbConnectionRetrieved, GetDbConnection, ShutdownConnectionPool}
import scala.concurrent.Await
import scala.concurrent.duration._
object DbConnectionPoolExtension extends ExtensionId[DbConnectionPoolExtension] with ExtensionIdProvider {
override def createExtension(system: ExtendedActorSystem): DbConnectionPoolExtension = new DbConnectionPoolExtension(system)
override def lookup(): ExtensionId[_ <: Extension] = DbConnectionPoolExtension
}
class DbConnectionPoolExtension(system: ExtendedActorSystem) extends Extension {
private val connectionPool = system.actorOf(Props(new ConnectionPool()).withDispatcher("db-access-dispatcher"), "guangwenz-util-db")
private implicit val timeout = Timeout(1.minutes)
private val requests = Map()
system.registerOnTermination {
connectionPool ! ShutdownConnectionPool
}
def getConnection: Option[Connection] = {
val future = connectionPool.ask(GetDbConnection(UUID.randomUUID().toString)).mapTo[DbConnectionRetrieved]
try {
Some(Await.result(future, 30.seconds).conn)
} catch {
case ex: Exception => None
}
}
def connect(handler: (Either[Exception, Connection]) => Unit): Unit = {
implicit val executor = system.dispatcher
val future = connectionPool.ask(GetDbConnection(UUID.randomUUID().toString)).mapTo[DbConnectionRetrieved]
try {
handler(Right(Await.result(future, 30.seconds).conn))
} catch {
case exception: Exception =>
handler(Left(exception))
}
}
def getConnectionPoolActor: Option[ActorRef] = {
Some(connectionPool)
}
}
示例9: 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)
}
}
}