本文整理汇总了Scala中akka.actor.SupervisorStrategy.Resume类的典型用法代码示例。如果您正苦于以下问题:Scala Resume类的具体用法?Scala Resume怎么用?Scala Resume使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Resume类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: StatsSupervisorActor
//设置package包名称以及导入依赖的类
package com.example
import akka.actor.SupervisorStrategy.{Decider, Resume}
import akka.actor._
import akka.event.LoggingReceive
class StatsSupervisorActor(maybeAccuracy: Option[Int]) extends Actor with ActorLogging {
private val decider: Decider = {
case StatsActor.StatstActorException =>
log.warning("Received exception on stats, trying to resume it")
Resume
}
override def supervisorStrategy: SupervisorStrategy = {
OneForOneStrategy() {
decider.orElse(super.supervisorStrategy.decider)
}
}
private val statsActor = createStatsActor()
override def receive: Receive = LoggingReceive {
case message => statsActor.forward(message)
}
private[example] def createStatsActor(): ActorRef = {
val acc = maybeAccuracy.getOrElse(context.system.settings.config.getInt("main.stats-accuracy"))
context.actorOf(StatsActor.props(acc), "stats-actor")
}
}
object StatsSupervisorActor {
def props(maybeAccuracy: Option[Int]): Props = {
Props(new StatsSupervisorActor(maybeAccuracy))
}
}
开发者ID:dgolovan,项目名称:AkkaIntro,代码行数:40,代码来源:StatsSupervisorActor.scala
示例2: Notifier
//设置package包名称以及导入依赖的类
package auctionsystem
import akka.actor.Actor
import akka.actor.ActorRef
import akka.actor.SupervisorStrategy
import akka.actor.OneForOneStrategy
import akka.event.LoggingReceive
import akka.actor.Props
import auctionsystem.Notifier.Notification
import auctionsystem.Notifier.RepeatRequest
import auctionsystem.exceptions.RemoteServerErrorException
import akka.actor.SupervisorStrategy.Resume
import akka.actor.SupervisorStrategy.Stop
class Notifier extends Actor {
val auctionPublisher = context.actorSelection("akka.tcp://[email protected]:2552/user/auctionPublisher")
var requestsMap = Map [ActorRef, Notification]()
var idx = 0;
override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy(maxNrOfRetries = 3) {
case _: RemoteServerErrorException =>
println(s"An error occurred when trying to connect with remote server, node that caused failure: ${sender.path}. Resuming...")
self ! RepeatRequest(requestsMap(sender), sender)
Resume
case e =>
println(s"Something else went wrong: $e")
Stop
}
def receive = LoggingReceive {
case Notification(auction, highestBidder, highestBid) =>
val notifierRequest = context.actorOf(Props(new NotifierRequest(auctionPublisher)), "notifierRequest" + idx);
idx = idx + 1
val notification = Notification(auction, highestBidder, highestBid)
requestsMap += (notifierRequest -> notification)
notifierRequest ! notification
}
}
object Notifier {
final case class RepeatRequest(notification: Notification, notifierRequest: ActorRef)
final case class Notification(auctionName: String, highestBidder: ActorRef, highestBid: Int);
}
开发者ID:Stawicki,项目名称:reactive-scala,代码行数:44,代码来源:Notifier.scala
示例3: ClientActor
//设置package包名称以及导入依赖的类
import akka.actor.SupervisorStrategy.Resume
import akka.actor.{Actor, OneForOneStrategy, SupervisorStrategy}
import scala.concurrent.duration._
class ClientActor extends Actor {
override def receive: Receive = {
case Ordered =>
println("\033[33m:: Book was ordered\033[0m")
case Searched(titles, prices) =>
for (i <- titles.indices)
println("\033[33m:: " + s"'${titles(i)}' costs ${prices(i)} PLN" + "\033[0m")
case SearchError(message) =>
println("\033[33m:: Search failed in database: " + message + "\033[0m")
case StreamLine(line) =>
println("\033[37m" + line + "\033[0m")
}
override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy(10, Duration(60, "seconds")) {
case _: Exception => Resume
}
}
开发者ID:Wwarrior1,项目名称:DistributedSystemsLab5Akka,代码行数:23,代码来源:ClientActor.scala
示例4: BotSupervisor
//设置package包名称以及导入依赖的类
package actors
import akka.actor.SupervisorStrategy.{Resume, Restart, Stop, Escalate}
import akka.actor.{OneForOneStrategy, Actor, ActorLogging, Props}
import com.typesafe.config.Config
import play.api.libs.ws.WSClient
import scala.concurrent.duration._
class BotSupervisor(wsClient: WSClient,config: Config) extends Actor with ActorLogging{
override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
case _: ArithmeticException => Resume
case _: NullPointerException => Restart
case _: IllegalArgumentException => Stop
case _: Exception => Escalate
}
val tinderBot =
context
.actorOf(Props(new TinderBot(wsClient,config))
,"TinderBot")
override def preStart() = {
log.info("Starting Tinder Bot Supervisor")
tinderBot ! TinderBot.Start
}
override def receive: Receive = {
case _ =>
}
}
object BotSupervisor {
def props = Props[BotSupervisor]
}
开发者ID:syedatifakhtar,项目名称:TinderBot,代码行数:39,代码来源:BotSupervisor.scala
示例5: AkkaSupervision
//设置package包名称以及导入依赖的类
package trove.core.event
import akka.actor.SupervisorStrategy.{Resume, Stop}
import akka.actor.{ActorInitializationException, ActorKilledException, OneForOneStrategy, SupervisorStrategy, SupervisorStrategyConfigurator}
import grizzled.slf4j.Logging
class AkkaSupervision extends SupervisorStrategyConfigurator with Logging {
override def create(): SupervisorStrategy = {
logger.debug("Creating custom akka supervisor strategy")
OneForOneStrategy() {
case _: ActorInitializationException => Stop
case _: ActorKilledException => Stop
case e: Exception =>
logger.error("Exception in event listener", e)
Resume
}
}
}
开发者ID:emanchgo,项目名称:trove,代码行数:19,代码来源:AkkaSupervision.scala
示例6: SupervisorAllActor
//设置package包名称以及导入依赖的类
package com.nossin.ndb
import akka.actor.{Actor, AllForOneStrategy, Props}
import akka.actor.SupervisorStrategy.{Escalate, Restart, Resume, Stop}
import com.nossin.ndb.messages.Calculator.{Div, Sub}
//import com.nossin.ndb.messages.Calculator.{Add, Div, Sub}
import scala.concurrent.duration._
class SupervisorAllActor extends Actor{
override val supervisorStrategy =
AllForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 seconds)
{
case _: ArithmeticException => Restart
case _: NullPointerException => Resume
case _: IllegalArgumentException => Stop
case _: Exception => Escalate
}
val printer = context.actorOf(Props[ResultPrinterActor])
val calculator = context.actorOf(Props(classOf[CalculatorActor], printer)) //The all supervisor strategy will also restart printer!
def receive = {
case "Start" => calculator ! com.nossin.ndb.messages.Calculator.Add(10, 12)
calculator ! Sub(12, 10)
calculator ! Div(5, 2)
calculator ! Div(5, 0)
}
}
开发者ID:michelnossin,项目名称:ndb,代码行数:29,代码来源:SupervisorAllActor.scala
示例7: ParentActor
//设置package包名称以及导入依赖的类
package com.github.uryyyyyyy.akka.helloworld.faultTolerance
import java.io.IOException
import akka.actor.SupervisorStrategy.{Escalate, Resume}
import akka.actor.{Actor, OneForOneStrategy, Props}
import scala.concurrent.duration.DurationInt
class ParentActor extends Actor {
override val supervisorStrategy =OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = new DurationInt(1).second ) {
case _: IOException => Resume
case _: Exception => Escalate
}
def receive = {
case x => {
val actor1 = context.actorOf(Props[ChildActor1])
val actor2 = context.actorOf(Props[ChildActor2])
// val actor3 = context.actorSelection("akka.tcp://notExist")
val f1 = actor1 ! "hello"
val f2 = actor2 ! "hello"
val f3 = actor2 ! "hello"
// val f3 = actor3 ! "hello"
}
}
}
开发者ID:uryyyyyyy,项目名称:akkaSample,代码行数:29,代码来源:ParentActor.scala
示例8: LogProcSupervisor
//设置package包名称以及导入依赖的类
package chapter4
import akka.actor.SupervisorStrategy.Resume
import akka.actor.{OneForOneStrategy, SupervisorStrategy, Actor, Props}
class LogProcSupervisor(dbSupervisorProps:Props) extends Actor{
//if file corrupted,keep deal the next msg
override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy(){
case _:CorruptedFileException=>Resume
}
//by dbSupervisorProps, create db supervisor
val dbSupervisor=context.actorOf(dbSupervisorProps)
//this supervisor monitoer the logProcessor
val logProcProps=Props(new LogProcessor(dbSupervisor))
val logProcessor=context.actorOf(logProcProps)
def receive={
case m=> logProcessor forward(m)
}
}
开发者ID:wjingyao2008,项目名称:firsttry,代码行数:24,代码来源:LogProcSupervisor.scala
示例9: SupervisorTest
//设置package包名称以及导入依赖的类
package teleporter.integration.component.jdbc
import akka.actor.SupervisorStrategy.Resume
import akka.actor._
import scala.concurrent.duration._
object SupervisorTest extends App {
implicit val system = ActorSystem()
import system.dispatcher
class A extends Actor with ActorLogging {
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 2) {
case _ => println("An actor has been killed"); Resume
}
val b = context.actorOf(Props[B], "b")
context.system.scheduler.schedule(10 seconds, 1 seconds, b, true)
def receive = {
case true ? println("is resume"); throw new IllegalArgumentException()
case _ =>
}
}
class B extends Actor with ActorLogging {
def receive = {
case true => throw new IllegalArgumentException("exception")
}
}
system.actorOf(Props[A])
}
开发者ID:huanwuji,项目名称:teleporter,代码行数:36,代码来源:SupervisorTest.scala
示例10: Ch4Ping1Actor
//设置package包名称以及导入依赖的类
package com.akkastarting.chapter4
import scala.concurrent.duration._
import akka.actor.SupervisorStrategy.{Escalate, Stop, Restart, Resume}
import akka.actor.{Actor, ActorLogging, Props, OneForOneStrategy}
import akka.pattern.{BackoffOptions, Backoff, BackoffSupervisor}
class Ch4Ping1Actor extends Actor with ActorLogging {
log.info("Ping1Actor Created, ...")
val child2Supervisor = BackoffSupervisor.props(createStrategy(Props[Ch4Ping2Actor], "Ping2Actor"))
val child3Supervisor = BackoffSupervisor.props(createStrategy(Props[Ch4Ping3Actor], "Ping3Actor"))
val child2 = context.system.actorOf(child2Supervisor, "Ping2ActorWithSupervisor")
val child3 = context.system.actorOf(child3Supervisor, "Ping3ActorWithSupervisor")
def receive = {
case message: Bad =>
(child2 ! message)(sender)
(child3 ! message)(sender)
case message: Good =>
(child2 ! message)(sender)
(child3 ! message)(sender)
}
def createStrategy(props: Props, name: String): BackoffOptions = {
Backoff.onStop(props,
childName = name,
minBackoff = 3.seconds,
maxBackoff = 30.seconds,
randomFactor = 0.2)
.withManualReset
.withSupervisorStrategy(OneForOneStrategy() {
case ex: ArithmeticException =>
Resume
case ex: NullPointerException =>
Restart
case ex: IllegalArgumentException =>
Stop
case _ =>
Escalate
})
}
}
开发者ID:imjuni,项目名称:AkkaStartingUsingScala,代码行数:45,代码来源:Ch4Ping1Actor.scala
示例11:
//设置package包名称以及导入依赖的类
package core.cluster
import akka.actor.SupervisorStrategy.{Resume, Stop}
import akka.actor._
trait SupervisionStrategy extends ActorLogging { self: Actor =>
override val supervisorStrategy =
AllForOneStrategy() {
case e: ActorInitializationException =>
log.error(e, "Escalating to parent")
Stop
case e: ActorKilledException =>
Stop
case e: Exception => {
log.error(e, s"Resume actor")
Resume
}
}
}
开发者ID:sumanyu,项目名称:distributed-kv-store,代码行数:20,代码来源:SupervisionStrategy.scala
注:本文中的akka.actor.SupervisorStrategy.Resume类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论