当前位置: 首页>>代码示例>>Scala>>正文


Scala ClusterSingletonManager类代码示例

本文整理汇总了Scala中akka.cluster.singleton.ClusterSingletonManager的典型用法代码示例。如果您正苦于以下问题:Scala ClusterSingletonManager类的具体用法?Scala ClusterSingletonManager怎么用?Scala ClusterSingletonManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ClusterSingletonManager类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
} 
开发者ID:sharma-rohit,项目名称:mormont,代码行数:28,代码来源:MormontListenerSingleton.scala

示例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"))
} 
开发者ID:tmccartan,项目名称:rest-akka-cluster,代码行数:40,代码来源:ActorModule.scala

示例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")
  }
} 
开发者ID:seglo,项目名称:akka-cluster-conductr,代码行数:52,代码来源:StatsSampleOneMaster.scala

示例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]
  }

} 
开发者ID:polyu-datamining-2016,项目名称:data-mining-pamap2,代码行数:40,代码来源:SingletonActor.scala

示例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"
  )
} 
开发者ID:mushtaq,项目名称:tcs-jeromq,代码行数:42,代码来源:HcdSingleton.scala

示例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"
    )

  }
} 
开发者ID:jmarin,项目名称:akka-cluster-example,代码行数:30,代码来源:BackendMain.scala

示例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")
  }
} 
开发者ID:prokosna,项目名称:pizza-baker,代码行数:43,代码来源:PizzaMain.scala

示例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")
    }
  }
} 
开发者ID:bahadley,项目名称:akka-cluster-metrics-listener-demo,代码行数:26,代码来源:Main.scala

示例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!")
} 
开发者ID:pnerg,项目名称:area51-akka,代码行数:48,代码来源:Singleton.scala

示例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()
  }
} 
开发者ID:anicolaspp,项目名称:distributd-transaction-processor,代码行数:33,代码来源:ClusterSingleton.scala

示例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)        
  }
} 
开发者ID:PacktPublishing,项目名称:Mastering-Akka,代码行数:19,代码来源:Bootstrap.scala

示例12: singletonProps

//设置package包名称以及导入依赖的类
package uk.gov.homeoffice.mercury.boot

import akka.actor.{PoisonPill, Props}
import akka.cluster.singleton.{ClusterSingletonManager, ClusterSingletonManagerSettings}
import uk.gov.homeoffice.akka.cluster.ClusterActorSystem
import uk.gov.homeoffice.configuration.HasConfig
import uk.gov.homeoffice.feature.FeatureSwitch
import uk.gov.homeoffice.mercury.boot.configuration.{HocsCredentials, HocsWebService, S3, SQS}
import uk.gov.homeoffice.mercury.sqs.{MercuryActor => MercurySQSActor}

import scala.language.postfixOps


trait MercuryBoot extends HasConfig with FeatureSwitch {
  this: App =>

  val system = ClusterActorSystem()
  sys addShutdownHook system.terminate()

  system.actorOf(singletonProps(MercurySQSActor.props(SQS(), S3(), HocsCredentials(), HocsWebService())), name = "mercury-actor")

  def singletonProps(p: Props) = try {
    ClusterSingletonManager.props(
      singletonProps = p,
      terminationMessage = PoisonPill,
      settings = ClusterSingletonManagerSettings(system))
  } catch {
    case t: Throwable =>
      error("Fatal error on startup", t)
      sys.exit(1)
  }
} 
开发者ID:UKHomeOffice,项目名称:mercury,代码行数:33,代码来源:MercuryBoot.scala

示例13: 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")
    }
  }
} 
开发者ID:bahadley,项目名称:adaptive-circuit-breaker,代码行数:39,代码来源:Main.scala


注:本文中的akka.cluster.singleton.ClusterSingletonManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。