本文整理汇总了Scala中akka.cluster.singleton.ClusterSingletonManagerSettings类的典型用法代码示例。如果您正苦于以下问题:Scala ClusterSingletonManagerSettings类的具体用法?Scala ClusterSingletonManagerSettings怎么用?Scala ClusterSingletonManagerSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClusterSingletonManagerSettings类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MormontListenerSingleton
//设置package包名称以及导入依赖的类
package lib.cluster
import akka.actor.{ActorRef, ActorSystem, Props}
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings}
import lib.models.DefaultCommands.Stop
abstract class MormontListenerSingleton(system: ActorSystem) {
private val prefix: String = "listener-singleton-"
protected def singletonProps: Props
protected def channelName: String
final def startSingleton(): Unit = {
system.actorOf(
ClusterSingletonManager.props(
singletonProps = singletonProps,
terminationMessage = Stop,
settings = ClusterSingletonManagerSettings(system)),
name = prefix + channelName)
}
}
object MormontListenerSingleton {
type MormontListenerSingletonActorRef = ActorRef
}
示例2: ActorModule
//设置package包名称以及导入依赖的类
package module
import actors.{AkkaConfig, MainActor}
import akka.actor.{ActorRef, PoisonPill, Props, ActorSystem}
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings, ClusterSingletonProxy, ClusterSingletonProxySettings}
import scaldi.Module
import service.{SessionService, PaymentMethodService, AddressService}
class ActorModule extends Module {
bind[AddressService] toProvider new AddressService()
bind[PaymentMethodService] toProvider new PaymentMethodService()
bind[MainActor] to new MainActor(inject[PaymentMethodService], inject[AddressService])
bind[ActorSystem] to {
val actorSystem = ActorSystem("rest-akka-cluster", new AkkaConfig(None).config)
actorSystem.actorOf(
ClusterSingletonManager.props(
singletonProps = Props(inject[MainActor]),
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(actorSystem).withSingletonName("MainActor")
), name = "singleton")
actorSystem
} destroyWith(_.terminate)
binding identifiedBy "MainActorProxy" to {
val system = inject[ActorSystem]
system.actorOf(
props = ClusterSingletonProxy.props(singletonManagerPath = "/user/singleton",
settings = ClusterSingletonProxySettings(system).withSingletonName("MainActor")
), name = "main-proxy")
}
bind[SessionService] toProvider new SessionService(inject[ActorRef]("MainActorProxy"))
}
示例3: StatsSampleOneMaster
//设置package包名称以及导入依赖的类
package sample.cluster.stats
import com.typesafe.config.ConfigFactory
import akka.actor.ActorSystem
import akka.actor.PoisonPill
import akka.actor.Props
import akka.cluster.singleton.ClusterSingletonManager
import akka.cluster.singleton.ClusterSingletonManagerSettings
import akka.cluster.singleton.ClusterSingletonProxy
import akka.cluster.singleton.ClusterSingletonProxySettings
object StatsSampleOneMaster {
def main(args: Array[String]): Unit = {
if (args.isEmpty) {
startup(Seq("2551", "2552", "0"))
StatsSampleOneMasterClient.main(Array.empty)
} else {
startup(args)
}
}
def startup(ports: Seq[String]): Unit = {
ports foreach { port =>
// Override the configuration of the port when specified as program argument
val config =
ConfigFactory.parseString(s"akka.remote.netty.tcp.port=" + port).withFallback(
ConfigFactory.parseString("akka.cluster.roles = [compute]")).
withFallback(ConfigFactory.load("stats2"))
val system = ActorSystem("ClusterSystem", config)
system.actorOf(ClusterSingletonManager.props(
singletonProps = Props[StatsService],
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(system).withRole("compute")),
name = "statsService")
system.actorOf(ClusterSingletonProxy.props(singletonManagerPath = "/user/statsService",
settings = ClusterSingletonProxySettings(system).withRole("compute")),
name = "statsServiceProxy")
}
}
}
object StatsSampleOneMasterClient {
def main(args: Array[String]): Unit = {
// note that client is not a compute node, role not defined
val system = ActorSystem("ClusterSystem")
system.actorOf(Props(classOf[StatsSampleClient], "/user/statsServiceProxy"), "client")
}
}
示例4: SingletonActor
//设置package包名称以及导入依赖的类
package hk.edu.polyu.datamining.pamap2.actor
import akka.actor._
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings, ClusterSingletonProxy, ClusterSingletonProxySettings}
object SingletonActor {
val SINGLETON = "singleton"
sealed trait SingletonActorType {
val name: String
protected val actorProps: Props
@deprecated
def actorSelection(context: ActorContext): ActorSelection =
context.actorSelection(context.self.path.root / "user" / name / SINGLETON)
def init(system: ActorSystem) =
system.actorOf(
ClusterSingletonManager.props(
actorProps,
PoisonPill.getInstance,
ClusterSingletonManagerSettings.create(system)
), name)
def proxy(implicit system: ActorSystem) =
system.actorOf(ClusterSingletonProxy.props(
singletonManagerPath = s"/user/$name",
settings = ClusterSingletonProxySettings.create(system)
))
}
case object Dispatcher extends SingletonActorType {
override val name: String = "task-dispatcher"
override val actorProps: Props = Props[DispatchActor]
}
}
示例5: HcdSingleton
//设置package包名称以及导入依赖的类
package tmt.demo.hcd
import akka.actor.{PoisonPill, Props}
import akka.cluster.singleton.{ClusterSingletonProxySettings, ClusterSingletonProxy, ClusterSingletonManagerSettings, ClusterSingletonManager}
import tmt.app.configs.{Names, AppSettings}
import tmt.app.utils.ActorRuntime
import tmt.demo.connectors.{ZmqToAkkaFlow, AkkaToZmqFlow}
import tmt.demo.zeromq_drivers.ZmqClient
class HcdSingleton(
zmqClient: ZmqClient,
akkaToZmqFlow: AkkaToZmqFlow,
zmqToAkkaFlow: ZmqToAkkaFlow,
appSettings: AppSettings,
actorRuntime: ActorRuntime
) {
import actorRuntime._
lazy val start = system.actorOf(
ClusterSingletonManager.props(
singletonProps = Props(new HcdActor(
zmqClient,
akkaToZmqFlow,
zmqToAkkaFlow,
appSettings
)),
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(system).withRole(Names.HcdServer)
),
name = Names.HcdServer
)
lazy val proxy = system.actorOf(
ClusterSingletonProxy.props(
singletonManagerPath = s"/user/${Names.HcdServer}",
settings = ClusterSingletonProxySettings(system).withRole(Names.HcdServer)
),
name = "hcdServerProxy"
)
}
示例6: BackendMain
//设置package包名称以及导入依赖的类
package cluster
import akka.actor.ActorSystem
import akka.cluster.singleton.{ ClusterSingletonManager, ClusterSingletonManagerSettings }
import com.typesafe.config.ConfigFactory
import common.CommonMessages.KillYourself
import processing.{ FileProcessor, SampleActor, WordCounter }
object BackendMain {
def main(args: Array[String]): Unit = {
val config = ConfigFactory.parseString("akka.cluster.roles = [backend]")
.withFallback(ConfigFactory.load())
val actorSystemName = config.getString("cluster.name")
val system = ActorSystem(actorSystemName, config)
val actor = system.actorOf(SampleActor.props(), "sample-actor")
actor ! "Hello Backend"
system.actorOf(WordCounter.props(), "word-counter")
system.actorOf(
ClusterSingletonManager.props(
singletonProps = FileProcessor.props(),
terminationMessage = KillYourself,
settings = ClusterSingletonManagerSettings(system).withRole("backend")
), "file-processor"
)
}
}
示例7: PizzaMain
//设置package包名称以及导入依赖的类
package actors
import akka.actor.{ActorSystem, PoisonPill, Props}
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings, ClusterSingletonProxy, ClusterSingletonProxySettings}
import com.typesafe.config.ConfigFactory
object PizzaMain {
def main(args: Array[String]) {
if (args.isEmpty)
println("run <host> <port>")
else
startup(args(0), args(1))
}
def startup(host: String, port: String): Unit = {
// override configuration
val config = ConfigFactory.parseString(s"akka.remote.netty.tcp.port = ${port}")
.withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.hostname = ${host}"))
// .withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.bind-hostname = ${host}"))
.withFallback(ConfigFactory.parseString(s"akka.remote.netty.tcp.bind-port = ${port}"))
.withFallback(ConfigFactory.parseString("akka.cluster.roles = [chef]"))
.withFallback(ConfigFactory.load("application"))
val system = ActorSystem("PizzaBakerSystem", config)
// create singleton manager
system.actorOf(ClusterSingletonManager.props(
singletonProps = Props[PizzaService],
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(system).withRole("chef")
),
"pizzaService")
// create singleton proxy
system.actorOf(ClusterSingletonProxy.props(
singletonManagerPath = "/user/pizzaService",
settings = ClusterSingletonProxySettings(system).withRole("chef")
),
"pizzaServiceProxy")
}
}
示例8: Main
//设置package包名称以及导入依赖的类
package ecb.cluster.tpcdi
import akka.actor.{ActorSystem, PoisonPill, Props}
import akka.cluster.Cluster
import akka.cluster.metrics.ClusterMetricsExtension
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings}
import com.typesafe.config.ConfigFactory
object Main extends App {
val config = ConfigFactory.load()
val system = ActorSystem("tpcdi", config)
val roles = system.settings.config.getStringList("akka.cluster.roles")
if(roles.contains("metric")) {
Cluster(system).registerOnMemberUp {
system.actorOf(
ClusterSingletonManager.props(
singletonProps = Props(classOf[MetricsListener]),
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(system).withRole("metric")),
name = "metrics-listener")
}
}
}
示例9: Terminated
//设置package包名称以及导入依赖的类
package org.dmonix.area51.akka.cluster
import akka.actor.{Actor, ActorSystem, Props}
import akka.cluster.Cluster
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings, ClusterSingletonProxy, ClusterSingletonProxySettings}
import org.dmonix.area51.akka.Configuration
case object Terminated
case class Request(msg:String)
case class Response(msg:String)
class Electee(groupName:String) extends Actor {
println(s"Created Electee for [$groupName] [$self]")
override def receive = {
case Request(msg) => {
println(s"Electee [$self] received [$msg]")
sender ! Response(msg)
}
case a:Any => {
println(s"Electee [$self] received [$a]")
}
}
}
abstract class Singleton extends App with ClusterSettings {
val singletonName = "Group-1"
def joinCluster(actorSystem: ActorSystem): Unit = {
val cluster = Cluster(actorSystem)
//join in to the cluster
cluster.joinSeedNodes(seedNodes)
}
def startSingleton(actorSystem: ActorSystem, name:String): Unit = {
actorSystem.actorOf(ClusterSingletonManager.props(Props(classOf[Electee], name), Terminated, ClusterSingletonManagerSettings(actorSystem).withSingletonName("singleton")), name)
}
}
object MessageSender extends Singleton {
val actorSystem = ActorSystem(actorSystemName, Configuration.memberCfg)
joinCluster(actorSystem)
val proxy = actorSystem.actorOf(ClusterSingletonProxy.props("/user/Group-1", ClusterSingletonProxySettings(actorSystem).withSingletonName("singleton")),"SingletonProxy")
proxy ! Request("Hello!")
}
示例10: ClusterSingletonApp
//设置package包名称以及导入依赖的类
package com.nico.ClusterSingleton
import akka.actor._
import akka.cluster.routing.{ClusterRouterGroupSettings, ClusterRouterGroup}
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings}
import akka.routing.{ConsistentHashingGroup, RoundRobinGroup}
import com.nico.actors.BankManager
import com.typesafe.config.ConfigFactory
object ClusterSingletonApp {
def main(args: Array[String]) {
val port = args(1).toInt
val configuration = ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$port")
.withFallback(ConfigFactory.parseString("akka.cluster.roles=[banker]"))
.withFallback(ConfigFactory.load())
val system = ActorSystem("TransactionCluster", configuration)
val numberOfAccounts = args(0).toInt
val accounts = (0 to numberOfAccounts).map (_.toString).toSet
system.actorOf(ClusterSingletonManager.props(
singletonProps = BankManager.props(accounts.toList),
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(system)
))
readLine()
}
}
示例11: startSingleton
//设置package包名称以及导入依赖的类
package com.packt.masteringakka.bookstore.common
import akka.actor._
import akka.cluster.singleton.ClusterSingletonManager
import akka.cluster.singleton.ClusterSingletonManagerSettings
def startSingleton(system:ActorSystem, props:Props,
managerName:String, terminationMessage:Any = PoisonPill):ActorRef = {
system.actorOf(
ClusterSingletonManager.props(
singletonProps = props,
terminationMessage = terminationMessage,
settings = ClusterSingletonManagerSettings(system)),
managerName)
}
}
示例12: Main
//设置package包名称以及导入依赖的类
package scb.tpcdi
import akka.actor.{ActorSystem, PoisonPill, Props}
import akka.cluster.Cluster
import akka.cluster.metrics.ClusterMetricsExtension
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings}
import com.typesafe.config.ConfigFactory
object Main extends App {
val system = ActorSystem("tpcdi", ConfigFactory.load())
val roles = system.settings.config.getStringList("akka.cluster.roles")
if(roles.contains("data-ingestion")) {
Cluster(system).registerOnMemberUp {
system.actorOf(
ClusterSingletonManager.props(
singletonProps = Props(classOf[AdmissionControl]),
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(system).withRole("data-ingestion")),
name = "admissioncontrol")
system.actorOf(
ClusterSingletonManager.props(
singletonProps = Props(classOf[DataAccess]),
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(system).withRole("data-ingestion")),
name = "dataaccess")
system.actorOf(
ClusterSingletonManager.props(
singletonProps = Props(classOf[TaxRateProducer]),
terminationMessage = PoisonPill,
settings = ClusterSingletonManagerSettings(system).withRole("data-ingestion")),
name = "taxrateproducer")
}
}
}