本文整理汇总了Scala中akka.cluster.singleton.ClusterSingletonProxySettings类的典型用法代码示例。如果您正苦于以下问题:Scala ClusterSingletonProxySettings类的具体用法?Scala ClusterSingletonProxySettings怎么用?Scala ClusterSingletonProxySettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClusterSingletonProxySettings类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: 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"))
}
开发者ID:tmccartan,项目名称:rest-akka-cluster,代码行数:40,代码来源:ActorModule.scala
示例2: 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")
}
}
开发者ID:seglo,项目名称:akka-cluster-conductr,代码行数:52,代码来源:StatsSampleOneMaster.scala
示例3: 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]
}
}
开发者ID:polyu-datamining-2016,项目名称:data-mining-pamap2,代码行数:40,代码来源:SingletonActor.scala
示例4: 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"
)
}
开发者ID:mushtaq,项目名称:tcs-jeromq,代码行数:42,代码来源:HcdSingleton.scala
示例5: 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")
}
}
开发者ID:prokosna,项目名称:pizza-baker,代码行数:43,代码来源:PizzaMain.scala
示例6: Main
//设置package包名称以及导入依赖的类
package com.github.liwei1987
import java.text.SimpleDateFormat
import java.util.{Date, UUID}
import akka.actor.{ActorSystem, PoisonPill, Props}
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings, ClusterSingletonProxy, ClusterSingletonProxySettings}
import akka.event.{Logging, LoggingAdapter}
import com.typesafe.config.ConfigFactory
import scala.collection.script.End
import scala.concurrent.duration._
object Main extends App {
private val ports = Array(2551, 2552)
for (port <- ports) {
// start akka singleton system at port
val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=" + port).withFallback(ConfigFactory.load())
val system = ActorSystem.create("AkkaClusterSingleSystem", config)
val logger: LoggingAdapter = Logging.getLogger(system, this)
logger.info(s"started AkkaClusterSingleSystem port at [${port}]")
// create singleton actor
system.actorOf(ClusterSingletonManager.props(Props[ClusterSingletonActor], PoisonPill, ClusterSingletonManagerSettings(system)), "clusterSingletonActor")
val clusterSingletonActorProxy = system.actorOf(ClusterSingletonProxy.props("/user/clusterSingletonActor", ClusterSingletonProxySettings.create(system)), "clusterSingletonActorProxy")
logger.info(s"finish create actor [${clusterSingletonActorProxy.path.name}]")
// interval 3 second send a message to actor
import system.dispatcher
system.scheduler.schedule(0.second, 10.second) {
clusterSingletonActorProxy ! s"${new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS").format(new Date())}"
}
}
}
开发者ID:liwei1987,项目名称:study-akka,代码行数:40,代码来源:Main.scala
示例7: 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!")
}
开发者ID:pnerg,项目名称:area51-akka,代码行数:48,代码来源:Singleton.scala
注:本文中的akka.cluster.singleton.ClusterSingletonProxySettings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论