本文整理汇总了Scala中akka.actor.ExtensionId类的典型用法代码示例。如果您正苦于以下问题:Scala ExtensionId类的具体用法?Scala ExtensionId怎么用?Scala ExtensionId使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExtensionId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: TestKitExtension
//设置package包名称以及导入依赖的类
package akka.testkit
import com.typesafe.config.Config
import akka.util.Timeout
import akka.actor.{ ExtensionId, ActorSystem, Extension, ExtendedActorSystem }
import scala.concurrent.duration.FiniteDuration
object TestKitExtension extends ExtensionId[TestKitSettings] {
override def get(system: ActorSystem): TestKitSettings = super.get(system)
def createExtension(system: ExtendedActorSystem): TestKitSettings = new TestKitSettings(system.settings.config)
}
class TestKitSettings(val config: Config) extends Extension {
import akka.util.Helpers._
val TestTimeFactor = config.getDouble("akka.test.timefactor").
requiring(tf ? !tf.isInfinite && tf > 0, "akka.test.timefactor must be positive finite double")
val SingleExpectDefaultTimeout: FiniteDuration = config.getMillisDuration("akka.test.single-expect-default")
val TestEventFilterLeeway: FiniteDuration = config.getMillisDuration("akka.test.filter-leeway")
val DefaultTimeout: Timeout = Timeout(config.getMillisDuration("akka.test.default-timeout"))
}
示例5: RemoteMetricsOn
//设置package包名称以及导入依赖的类
package akka.remote
import java.util.concurrent.ConcurrentHashMap
import scala.annotation.tailrec
import akka.actor.ActorSelectionMessage
import akka.actor.ActorSystem
import akka.actor.ExtendedActorSystem
import akka.actor.Extension
import akka.actor.ExtensionId
import akka.actor.ExtensionIdProvider
import akka.event.Logging
import akka.routing.RouterEnvelope
private[akka] class RemoteMetricsOn(system: ExtendedActorSystem) extends RemoteMetrics {
private val logFrameSizeExceeding: Int = system.settings.config.getBytes(
"akka.remote.log-frame-size-exceeding").toInt
private val log = Logging(system, this.getClass)
private val maxPayloadBytes: ConcurrentHashMap[Class[_], Integer] = new ConcurrentHashMap
override def logPayloadBytes(msg: Any, payloadBytes: Int): Unit =
if (payloadBytes >= logFrameSizeExceeding) {
val clazz = msg match {
case x: ActorSelectionMessage ? x.msg.getClass
case x: RouterEnvelope ? x.message.getClass
case _ ? msg.getClass
}
// 10% threshold until next log
def newMax = (payloadBytes * 1.1).toInt
@tailrec def check(): Unit = {
val max = maxPayloadBytes.get(clazz)
if (max eq null) {
if (maxPayloadBytes.putIfAbsent(clazz, newMax) eq null)
log.info("Payload size for [{}] is [{}] bytes", clazz.getName, payloadBytes)
else check()
} else if (payloadBytes > max) {
if (maxPayloadBytes.replace(clazz, max, newMax))
log.info("New maximum payload size for [{}] is [{}] bytes", clazz.getName, payloadBytes)
else check()
}
}
check()
}
}
示例6: AddressTerminatedTopic
//设置package包名称以及导入依赖的类
package akka.event
import java.util.concurrent.atomic.AtomicReference
import scala.annotation.tailrec
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.AddressTerminated
import akka.actor.ExtendedActorSystem
import akka.actor.Extension
import akka.actor.ExtensionId
import akka.actor.ExtensionIdProvider
private[akka] final class AddressTerminatedTopic extends Extension {
private val subscribers = new AtomicReference[Set[ActorRef]](Set.empty[ActorRef])
@tailrec def subscribe(subscriber: ActorRef): Unit = {
val current = subscribers.get
if (!subscribers.compareAndSet(current, current + subscriber))
subscribe(subscriber) // retry
}
@tailrec def unsubscribe(subscriber: ActorRef): Unit = {
val current = subscribers.get
if (!subscribers.compareAndSet(current, current - subscriber))
unsubscribe(subscriber) // retry
}
def publish(msg: AddressTerminated): Unit = {
subscribers.get foreach { _.tell(msg, ActorRef.noSender) }
}
}
示例7: 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))
}
示例8: 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
}
示例9: 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]]
示例10: triggerGracefulShutdown
//设置package包名称以及导入依赖的类
package de.choffmeister.microserviceutils
import java.util.concurrent.TimeUnit
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, ExtendedActorSystem, Extension, ExtensionId, Props}
import com.typesafe.config.Config
import de.choffmeister.microserviceutils.GracefulShutdownExtension.{ShuttingDown, Subscribe, Unsubscribe}
import scala.concurrent.duration._
def triggerGracefulShutdown(): Unit = {
isShuttingDownBoolean = true
notifier ! ShuttingDown(shutdownDelay)
}
}
private[this] class GracefulShutdownNotifierActor extends Actor with ActorLogging {
var subscribers = Vector.empty[ActorRef]
var shutdownAt = Option.empty[Long]
override def receive = {
case Subscribe(subscriber) if shutdownAt.isEmpty =>
subscribers = subscribers :+ subscriber
case Subscribe(subscriber) if shutdownAt.nonEmpty =>
subscriber ! ShuttingDown(FiniteDuration(Math.max(shutdownAt.get - System.currentTimeMillis, 0L), TimeUnit.MILLISECONDS))
case Unsubscribe(subscriber) =>
subscribers = subscribers.filterNot(_ == subscriber)
case ShuttingDown(shutdownDelay) if shutdownAt.isEmpty =>
log.info("Initiating graceful shutdown")
shutdownAt = Some(System.currentTimeMillis + shutdownDelay.toMillis)
subscribers.foreach(subscriber => subscriber ! ShuttingDown(shutdownDelay))
subscribers = Vector.empty
}
}
object GracefulShutdownExtension extends ExtensionId[GracefulShutdownExtensionImpl] {
final case class ShuttingDown(delay: FiniteDuration)
private[microserviceutils] final case class Subscribe(subscriber: ActorRef)
private[microserviceutils] final case class Unsubscribe(subscriber: ActorRef)
override def createExtension(system: ExtendedActorSystem): GracefulShutdownExtensionImpl =
new GracefulShutdownExtensionImpl(system, system.settings.config)
}
示例11: SettingsImpl
//设置package包名称以及导入依赖的类
package model.Util
import akka.actor.ActorSystem
import akka.actor.Extension
import akka.actor.ExtensionId
import akka.actor.ExtensionIdProvider
import akka.actor.ExtendedActorSystem
import scala.concurrent.duration.Duration
import com.typesafe.config.{ConfigObject, ConfigValue, ConfigFactory, Config}
import java.util.concurrent.TimeUnit
import scala.collection.JavaConverters._
import java.util.Map.Entry
import model.Util.util._
class SettingsImpl(config: Config) extends Extension {
object border {
val left = config.getInt("myApp.border.left")
val right = config.getInt("myApp.border.right")
val top = config.getInt("myApp.border.top")
val bottom = config.getInt("myApp.border.bottom")
}
object view {
val baseX = config.getInt("myApp.view.baseX")
val baseY = config.getInt("myApp.view.baseY")
}
val initFoodCount = config.getInt("myApp.initFoodCount")
val gridSquareSize = config.getInt("myApp.gridSquareSize")
val playerRecombineTime = config.getInt("myApp.playerRecombineTime")
val playerMinMassToSplit = config.getInt("myApp.playerMinMassToSplit")
val playerMaxCells = config.getInt("myApp.playerMaxCells")
val splitCellSpeedDecay = config.getDouble("myApp.splitCellSpeedDecay")
val ejectedMassSpeedDecay = config.getDouble("myApp.ejectedMassSpeedDecay")
val automaticMovementTicksForSplit = config.getInt("myApp.automaticMovementTicksForSplit")
val ejectedMass = config.getInt("myApp.ejectedMass")
val ejectedMassSpeed = config.getInt("myApp.ejectedMassSpeed")
val minMassEject = config.getInt("myApp.minMassEject")
val automaticMovementTicksForEject = config.getInt("myApp.automaticMovementTicksForEject")
val virusStartMass = config.getInt("myApp.virusStartMass")
val virusFeedAmount = config.getInt("myApp.virusFeedAmount")
val virusMinAmount = config.getInt("myApp.virusMinAmount")
val virusMaxAmount = config.getInt("myApp.virusMaxAmount")
val ejectedVirusSpeed = config.getInt("myApp.ejectedVirusSpeed")
val ejectedVirusSpeedDecay = config.getDouble("myApp.ejectedVirusSpeedDecay")
val automaticMovementTicksForVirusEject = config.getInt("myApp.automaticMovementTicksForVirusEject")
var defaultRooms: List[RoomDescription] = {
val projs = config.getConfigList("myApp.defaultRooms").asScala map { p =>
RoomDescription(p.getString("title"), p.getDouble("lat"), p.getDouble("lng"), null, p.getString("serverAddress")) }
projs.toList }
}
object Settings extends ExtensionId[SettingsImpl] with ExtensionIdProvider {
override def lookup = Settings
override def createExtension(system: ExtendedActorSystem) =
new SettingsImpl(system.settings.config)
}
示例12: 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")
}
}
}
}
}
}
示例13: 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)
}
}
示例14: LogUnreachable
//设置package包名称以及导入依赖的类
package com.evolutiongaming.cluster
import akka.actor.{Actor, ActorLogging, ExtendedActorSystem, Extension, ExtensionId, Props}
import akka.cluster.ClusterEvent._
import akka.cluster.{Cluster, Member}
import scala.collection.immutable.Queue
class LogUnreachable(system: ExtendedActorSystem) extends Extension {
private lazy val ref = system.actorOf(Props(new Listener))
def start(): Unit = ref
private class Listener extends Actor with ActorLogging {
private val cluster = Cluster(context.system)
private var queue = Queue.empty[ClusterDomainEvent]
override def preStart() = {
super.preStart()
cluster.subscribe(self, initialStateMode = InitialStateAsEvents, classOf[ClusterDomainEvent])
}
def receive = {
case x: ClusterDomainEvent => x match {
case x: UnreachableMember => onUnreachableMember(x.member); enqueue(x)
case x: MemberEvent => enqueue(x)
case x: ReachabilityEvent => enqueue(x)
case x: LeaderChanged => enqueue(x)
case [email protected] => enqueue(x)
case _ =>
}
}
def enqueue(event: ClusterDomainEvent) = {
queue = queue enqueue event takeRight 20
}
def onUnreachableMember(member: Member) = {
log.warning(s"node ${member.address} is Unreachable, cluster: ${cluster.state}, events: ${queue mkString ","}")
}
}
}
object LogUnreachable extends ExtensionId[LogUnreachable] {
def createExtension(system: ExtendedActorSystem) = new LogUnreachable(system)
}
示例15: AddressHelper
//设置package包名称以及导入依赖的类
package com.evolutiongaming.cluster
import akka.actor.{Address, ExtendedActorSystem, Extension, ExtensionId}
class AddressHelper(val defaultAddress: Address) extends Extension {
def toLocal(address: Address): Address = {
if (address == defaultAddress) address.copy(host = None, port = None, protocol = "akka") else address
}
def toGlobal(address: Address): Address = {
if (address.hasGlobalScope) address else defaultAddress
}
}
object AddressHelperExtension extends ExtensionId[AddressHelper] {
def createExtension(system: ExtendedActorSystem): AddressHelper = {
new AddressHelper(system.provider.getDefaultAddress)
}
}