• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Stop类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Stop类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: ClientActor

//设置package包名称以及导入依赖的类
package org.http4s.akka

import scala.reflect.ClassTag

import akka.actor.SupervisorStrategy.Stop
import akka.actor.{Actor, OneForOneStrategy, Props, Terminated}
import fs2.Task
import fs2.async.mutable.{Queue, Signal}

private class ClientActor[Out](props: Props, outQueue: Queue[Task, Out], closeSignal: Signal[Task, Boolean])
                              (implicit messageType: ClassTag[Out]) extends Actor {
  val serverActor = context actorOf props
  context watch serverActor
  
  def receive: Receive = {
    case Terminated(`serverActor`) =>
      closeSignal.set(true).unsafeRun()
      context stop self
    case messageType(m) if sender() == serverActor =>
      outQueue.enqueue1(m).unsafeRun()
    case m if sender() == serverActor =>
      org.log4s.getLogger.error(s"Server sent unhandled message ${m.getClass.getSimpleName} " +
        s"expecting a ${messageType.runtimeClass.getSimpleName}!")
    case m if sender() == self =>
      serverActor ! m
  }
  
  override def supervisorStrategy: OneForOneStrategy = OneForOneStrategy() {
    case _ => Stop
  }
} 
开发者ID:Lasering,项目名称:http4s-akka,代码行数:32,代码来源:ClientActor.scala


示例2: CustomOneForOneUser

//设置package包名称以及导入依赖的类
package com.example.supervisor

import akka.actor.SupervisorStrategy.{Restart, Stop}
import akka.actor.{Actor, ActorLogging, ActorRef, OneForOneStrategy}


class CustomOneForOneUser extends Actor with ActorLogging {

  // Map that keeps track of how often a given child has been restarted
  var restarts = Map.empty[ActorRef, Int].withDefaultValue(0)

  // Using the default parameters for a SupervisorStrategy mean "arbitarily
  // often over forever"
  override val supervisorStrategy = OneForOneStrategy() {

    case _: ArithmeticException =>

      restarts(sender) match {
        case tooManyRestarts if tooManyRestarts > 15 =>
          restarts -= sender
          Stop
        case n =>
          restarts = restarts.updated(sender, n+1)
          Restart
      }
  }

  override def receive: Receive = ???
} 
开发者ID:dkmn,项目名称:week-3-lecture-examples,代码行数:30,代码来源:CustomOneForOneUser.scala


示例3: ProcrusteanManager

//设置package包名称以及导入依赖的类
package com.example.supervisor

import akka.actor.SupervisorStrategy.{Escalate, Restart, Stop}
import akka.actor.{Actor, ActorLogging, AllForOneStrategy}

import scala.concurrent.duration._


class ProcrusteanManager extends Actor with ActorLogging {

  override val supervisorStrategy =
                                  AllForOneStrategy(maxNrOfRetries = 5,
                                                    withinTimeRange = 5 seconds,
                                                    loggingEnabled = true) {
    case _: IllegalStateException => Restart
    case _: IllegalArgumentException => Stop
    case _: NullPointerException => Stop
    case _: Exception => Escalate
  }

  override def receive: Receive = ???
} 
开发者ID:dkmn,项目名称:week-3-lecture-examples,代码行数:23,代码来源:ProcrusteanManager.scala


示例4: NetworkBrokerSupervisorStrategy

//设置package包名称以及导入依赖的类
package net.ruippeixotog.scalafbp.runtime

import akka.actor.SupervisorStrategy.{ Decider, Stop }
import akka.actor._
import NetworkBrokerSupervisorStrategy._

class NetworkBrokerSupervisorStrategy(onError: (ActorRef, Throwable) => Unit)
    extends OneForOneStrategy()(stoppingDecider) {

  override def handleFailure(
    context: ActorContext,
    child: ActorRef,
    cause: Throwable,
    stats: ChildRestartStats,
    children: Iterable[ChildRestartStats]): Boolean = {
    cause match {
      case _: ActorKilledException | _: DeathPactException =>
      case ex: Exception => onError(child, cause)
    }
    super.handleFailure(context, child, cause, stats, children)
  }

  override val loggingEnabled = false
}

object NetworkBrokerSupervisorStrategy {
  def stoppingDecider: Decider = {
    case _: Exception => Stop
  }
} 
开发者ID:ruippeixotog,项目名称:scalafbp,代码行数:31,代码来源:NetworkBrokerSupervisorStrategy.scala


示例5: Supervisor

//设置package包名称以及导入依赖的类
package io.ticofab.scalarabbitmqexample.actor

import akka.actor.SupervisorStrategy.Stop
import akka.actor.{Actor, OneForOneStrategy, Props}
import io.ticofab.scalarabbitmqexample.actor.QueueListener.{CloseYourEars, Listen}
import io.ticofab.scalarabbitmqexample.actor.Supervisor.{Begin, End}

object Supervisor {

  case object Begin

  case object End

  def props = Props[Supervisor]
}

class Supervisor extends Actor {
  val queueListener = context.actorOf(QueueListener.props)

  // very simple supervision strategy: if anything happens, stop the actor
  override val supervisorStrategy = OneForOneStrategy(loggingEnabled = false) {
    case _: Exception => Stop
  }

  override def receive: Receive = {
    case Begin => queueListener ! Listen
    case End => queueListener ! CloseYourEars
  }
} 
开发者ID:ticofab,项目名称:Scala-RabbitMQ-Example,代码行数:30,代码来源:Supervisor.scala


示例6: RemoteActor

//设置package包名称以及导入依赖的类
package com.actorsys.actors

import akka.actor.SupervisorStrategy.Stop
import akka.actor.{Actor, ActorLogging}
import com.actorsys.service._


class RemoteActor extends Actor with ActorLogging {
  val SUCCESS = "SUCCESS"
  val FAILURE = "FAILURE"

  override def receive: Receive = {
    case Start => log.info("receive event" + Start)
    case Stop => log.info("receive event" + Stop)
    case Shutdown(waitSecs) => {
      log.info("wait to shutdown:waitSecs:" + waitSecs)
      Thread.sleep(waitSecs)
      log.info("Shutdown this system.")
      context.system.deadLetters
    }
    case Heartbeat(id, magic) => log.info("receive Heartbeat:" + (id, magic))
    case Header(id, len, encrypted) => log.info("receive Header:" + (id, len, encrypted))
    case Packet(id, seq, content) => {
      val originalSender = sender
      log.info("receive Packet:" + (id, seq, content))
      originalSender ! (seq, SUCCESS)
    }
    case _ => log.info("ERROR")
  }
} 
开发者ID:yuanyedc,项目名称:actorsys,代码行数:31,代码来源:RemoteActor.scala


示例7: ArithmeticService

//设置package包名称以及导入依赖的类
package com.bob.akka.supervision

import akka.actor.SupervisorStrategy.{Restart, Stop}
import akka.actor._
import com.bob.akka.supervision.FlakyExpressionCalculator.{FlakinessException, Result}

class ArithmeticService extends Actor with ActorLogging {

  override def receive: Receive = {
    case e: Expression =>
      val worker = context.actorOf(FlakyExpressionCalculator.props(expr = e, position = FlakyExpressionCalculator.Left))
      pendingWorkers += worker -> sender()
    case Result(originalExpression, value, _) =>
      notifyConsumerSuccess(worker = sender(), result = value)
  }

  var pendingWorkers = Map[ActorRef, ActorRef]()

  def notifyConsumerFailure(worker: ActorRef, failure: Throwable): Unit = {
    pendingWorkers.get(worker).foreach { x => x ! Status.Failure(failure) }
    pendingWorkers -= worker
  }

  def notifyConsumerSuccess(worker: ActorRef, result: Int): Unit = {
    pendingWorkers.get(worker) foreach {
      _ ! result
    }
    pendingWorkers -= worker
  }

  override val supervisorStrategy = OneForOneStrategy(loggingEnabled = false) {
    case _: FlakinessException =>
      log.warning("Evaluation of a top level expression failed, restarting.")
      Restart
    case e: ArithmeticException =>
      log.error("Evaluation failed because of: {}", e.getMessage)
      notifyConsumerFailure(worker = sender(), failure = e)
      Stop
    case e =>
      log.error("Unexpected failure: {}", e.getMessage)
      notifyConsumerFailure(worker = sender(), failure = e)
      Stop
  }

} 
开发者ID:bobxwang,项目名称:akka-in-all,代码行数:46,代码来源:ArithmeticService.scala


示例8:

//设置package包名称以及导入依赖的类
package actors.workflow

import actors.WorkflowLog.LogMessage
import akka.actor.SupervisorStrategy.{Restart, Stop}
import akka.actor.{Actor, ActorLogging, OneForOneStrategy}
import com.amazonaws.{AmazonClientException, AmazonServiceException}

import scala.concurrent.duration._

trait AWSSupervisorStrategy extends Actor with ActorLogging {
  override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 20, loggingEnabled = true) {
    case ex: AmazonServiceException =>
      ex.getErrorCode match {
        case "ServiceUnavailable" | "Throttling" =>
          log.debug("Supervisor Authorized Restart")
          Restart
        case _ =>
          context.parent ! LogMessage(ex.toString)
          Stop
      }
      
    case _: AmazonClientException =>
      log.debug("Supervisor Authorized Restart")
      Restart

    case ex: Exception =>
      context.parent ! LogMessage(ex.toString)
      Stop
  }
} 
开发者ID:lifeway,项目名称:Chadash,代码行数:31,代码来源:AWSSupervisorStrategy.scala


示例9: FlushLog

//设置package包名称以及导入依赖的类
package dcp.business.actors

import BoDaoCommon.Log.LogTool
import akka.actor.Actor
import akka.actor.SupervisorStrategy.Stop
import dcp.common._

import scala.collection.mutable.ArrayBuffer
import scala.concurrent.duration._
import dcp.config.DynConfiguration

case class FlushLog()

class LogActor extends Actor {
  private lazy val logs = ArrayBuffer[LogMsg]()
  
  private def cachelogs(logMsg: LogMsg) = {
    logs += logMsg
  }

  private def stopLoger() = {
    this.flushlogs()  //?????
    context.stop(self)
  }

  def receive = {
    case log @ flushLog() => flushlog(log)  //??????????????

    case log @ cacheLog() => cachelogs(log)

    case DeleteLog(lever, date) =>
      lever match {
        case LogLevelEnum.Info => LogTool.deleteInfoLog(date)
        case LogLevelEnum.Warn => LogTool.deleteWarningLog(date)
        case LogLevelEnum.Err => LogTool.deleteErrorLog(date)
      }

    case DeleteDayLogs(date) => LogTool.deleteDayLog(date)

    case FlushLog() =>
      this.flushlogs()
      if (logs.nonEmpty) logs.clear()  //????

    case Stop => this.stopLoger()
  }

} 
开发者ID:TopSpoofer,项目名称:dcp2.0,代码行数:48,代码来源:LogActor.scala


示例10: CrookedForeman

//设置package包名称以及导入依赖的类
package com.example.coalmine

import akka.actor.SupervisorStrategy.Stop
import akka.actor.{Actor, ActorLogging, ActorRef, OneForOneStrategy, Props, Terminated}
import com.example.coalmine.Miner.{DoValuableWork, WorkDone}



object CrookedForeman {
  val props = Props[CrookedForeman]

  case object HireMiners
  case object BerateMiners
  case class DeathNotice(miner: ActorRef)
}

class CrookedForeman extends Actor with ActorLogging {
  import CrookedForeman._

  // We'll learn more about supervisor strategies next week... for now we
  // install this one so that dead children stay dead, to make our point.
  override val supervisorStrategy = OneForOneStrategy() {
    case _: Exception => Stop
  }

  override def receive: Receive = {

    case HireMiners => 1 to 5 foreach { i => {
                                        val miner = context.actorOf(Miner.props,
                                          s"Miner-no-$i")
                                        log.info(s"Hiring miner $i")
                                        context.watch(miner) }
                                      }

    case BerateMiners =>
      val numMiners = context.children.size
      log.info(s"I have $numMiners miner children, at your service! Berating!")
      context.children.foreach { miner => miner ! DoValuableWork }

    case WorkDone(v) => context.parent forward WorkDone(v)

    case Terminated(miner) =>
      log.info(s"Oh dear, $miner has died!")
      context.parent ! DeathNotice(miner)
  }
} 
开发者ID:dkmn,项目名称:week-2-lecture-examples,代码行数:47,代码来源:CrookedForeman.scala


示例11: 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


示例12: SearchDatabaseActor

//设置package包名称以及导入依赖的类
import akka.actor.SupervisorStrategy.Stop
import akka.actor.{Actor, OneForOneStrategy, SupervisorStrategy}

import scala.concurrent.duration.Duration
import scala.io.Source._

class SearchDatabaseActor(filename: String) extends Actor {
  override def receive: Receive = {
    case Search(title) =>
      val lines = fromFile(filename).getLines
      sender ! SearchResponse(lines.filter(s => s.startsWith(title)).toArray)
  }

  override def supervisorStrategy: SupervisorStrategy =
    OneForOneStrategy(10, Duration(60, "seconds")) {
      case _: Exception => Stop
    }
}

case class SearchResponse(books: Array[String]) 
开发者ID:Wwarrior1,项目名称:DistributedSystemsLab5Akka,代码行数:21,代码来源:SearchDatabaseActor.scala


示例13: 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


示例14: 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


示例15: 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


示例16: Intact

//设置package包名称以及导入依赖的类
package oriana

import akka.actor.SupervisorStrategy.Stop
import akka.actor.{OneForOneStrategy, SupervisorStrategy, Props, Actor}

sealed trait FuseStatus
case object Intact extends FuseStatus
case object Blown extends FuseStatus

class Fuse(childSpec: Props) extends Actor {
  case object FuseBlown
  var status: FuseStatus = Intact
  val child = context.actorOf(childSpec)

  def receive = {
    case Fuse.ReadStatus => sender() ! status
    case FuseBlown => status = Blown
    case x if status == Intact => child forward x
  }

  override def supervisorStrategy = OneForOneStrategy() {
    case _: Throwable =>
      self ! FuseBlown
      Stop
  }
}

object Fuse {
  case object ReadStatus
  def props(childSpec: Props) = Props(new Fuse(childSpec))
} 
开发者ID:Norwae,项目名称:oriana,代码行数:32,代码来源:Fuse.scala


示例17: Worker

//设置package包名称以及导入依赖的类
import CounterService._
import Worker._
import akka.actor.SupervisorStrategy.Stop
import akka.actor._
import akka.event.LoggingReceive
import akka.pattern.{ask, pipe}
import akka.util.Timeout

import scala.concurrent.duration.{Duration, _}


class Worker extends Actor with ActorLogging {

  implicit val askTimeout = Timeout(5 seconds)

  // Stop the CounterService child if it throws ServiceUnavailable
  override val supervisorStrategy = OneForOneStrategy() {
    case _: CounterService.ServiceUnavailable => Stop
  }

  // The sender of the initial Start message will continuously be notified
  // about progress
  var progressListener: Option[ActorRef] = None
  val counterService = context.actorOf(Props[CounterService], name = "counter")
  val totalCount = 51

  import context.dispatcher

  // Use this Actors' Dispatcher as ExecutionContext

  def receive = LoggingReceive {
    case Start if progressListener.isEmpty =>
      progressListener = Some(sender())
      context.system.scheduler.schedule(Duration.Zero, 1 second, self, Do)

    case Do =>
      counterService ! Increment(1)
      counterService ! Increment(1)
      counterService ! Increment(1)

      // Send current progress to the initial sender
      counterService ? GetCurrentCount map {
        case CurrentCount(_, count) => Progress(100.0 * count / totalCount)
      } pipeTo progressListener.get
  }
}

object Worker {

  case object Start

  case object Do

  final case class Progress(percent: Double)

} 
开发者ID:liwei1987,项目名称:study-akka,代码行数:57,代码来源:Worker.scala


示例18: ShutdownRequest

//设置package包名称以及导入依赖的类
package io.scalanator.robot.monitor

import akka.actor.SupervisorStrategy.Stop
import akka.actor.{ Actor, ActorLogging, ActorSystem, OneForOneStrategy, Props }

final case class ShutdownRequest(reason: String, isError: Boolean = false)

class MonitorActor(mainProps: Props, shutdownFn: (ActorSystem, ShutdownRequest) => Unit) extends Actor with ActorLogging {

  override val supervisorStrategy = OneForOneStrategy() {
    case ex: Exception =>
      log.error(s"Error seen  by monitor actor ${ex.getMessage}", ex)
      self ! ShutdownRequest(s"Monitor actor failed with ${ex.getClass} - ${ex.toString}", isError = true)
      Stop
  }

  def initialiseChildren(): Unit = {

    context.actorOf(mainProps, "robot")

    //    Environment.info foreach log.info
  }

  override def preStart(): Unit = {
    try {
      initialiseChildren()
    } catch {
      case t: Throwable =>
        log.error(s"Error during startup - ${t.getMessage}", t)
        self ! ShutdownRequest(t.toString, isError = true)
    }
  }
  override def receive: Receive = {
    case req: ShutdownRequest =>
      triggerShutdown(req)
  }

  def triggerShutdown(request: ShutdownRequest): Unit = {
    shutdownFn(context.system, request)
  }
} 
开发者ID:rorygraves,项目名称:ensime-bot,代码行数:42,代码来源:MonitorActor.scala


示例19: SupervisorStrategy

//设置package包名称以及导入依赖的类
package teleporter.integration.akka

import akka.actor.SupervisorStrategy.{Decider, Restart, Stop}
import akka.actor._
import org.apache.logging.log4j.scala.Logging


trait FaultHandling {

}

object SupervisorStrategy extends Logging {
  final val defaultDecider: Decider = {
    case e ?
      logger.info(e.getLocalizedMessage, e)
      e match {
        case _: ActorInitializationException ? Stop
        case _: ActorKilledException ? Stop
        case _: DeathPactException ? Stop
        case _: Exception ? Restart
      }
  }

  final val defaultStrategy: SupervisorStrategy = {
    OneForOneStrategy()(defaultDecider)
  }
}

final class DefaultSupervisorStrategy extends SupervisorStrategyConfigurator {
  override def create(): SupervisorStrategy = SupervisorStrategy.defaultStrategy
} 
开发者ID:huanwuji,项目名称:teleporter,代码行数:32,代码来源:FaultHandling.scala


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Regions类代码示例发布时间:2022-05-23
下一篇:
Scala Cursor类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap