本文整理汇总了Scala中akka.actor.SupervisorStrategy.Escalate类的典型用法代码示例。如果您正苦于以下问题:Scala Escalate类的具体用法?Scala Escalate怎么用?Scala Escalate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Escalate类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: 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 = ???
}
示例2: ColetorNotificacoesActor
//设置package包名称以及导入依赖的类
package com.exemplo5
import akka.actor.SupervisorStrategy.{Escalate, Restart, Resume, Stop}
import akka.actor.{Actor, OneForOneStrategy, Props, Terminated}
import akka.routing.RoundRobinPool
import com.common.Notificacao
import com.common.TipoNotificacao._
import com.exemplo5.ColetorNotificacoesActor.{ContarNotificacoes, EnviarNotificacao}
import com.exemplo5.NotificacaoPagamentoActor.NotificarPagamento
import scala.collection.mutable.ListBuffer
import scala.concurrent.duration._
class ColetorNotificacoesActor extends Actor {
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
case _: ArithmeticException => Resume
case _: NullPointerException => Restart
case _: IllegalArgumentException => Restart
case _: Exception => Escalate
}
var notificacoes = new ListBuffer[Notificacao]()
val notificacaoPagamentoActor = context.actorOf(RoundRobinPool(10).props(Props[NotificacaoPagamentoActor]), "NotificacaoPagamentoActor")
context.watch(notificacaoPagamentoActor)
def receive = {
case EnviarNotificacao(notificacao) => {
notificacoes += notificacao
notificacao.tipo match {
case PAGAMENTO => notificacaoPagamentoActor ! NotificarPagamento(notificacao)
case SAQUE => notificacaoPagamentoActor ! NotificarPagamento(notificacao)
case TRANSFERENCIA => notificacaoPagamentoActor ! NotificarPagamento(notificacao)
}
}
case ContarNotificacoes => sender ! notificacoes.size
case Terminated(ator) => println(s"############### Ator ${ator.path} finalizado ##############")
}
}
object ColetorNotificacoesActor {
case object ContarNotificacoes
case class EnviarNotificacao(notificacao: Notificacao)
}
示例3: OrderActor
//设置package包名称以及导入依赖的类
import java.io.FileWriter
import akka.actor.SupervisorStrategy.Escalate
import akka.actor.{Actor, OneForOneStrategy, SupervisorStrategy}
import scala.concurrent.duration.Duration
class OrderActor() extends Actor {
override def receive: Receive = {
case Order(title: String) =>
val currentSender = sender
orderSingleton.orderBook(title)
currentSender ! Ordered
}
override def supervisorStrategy: SupervisorStrategy =
OneForOneStrategy(10, Duration(60, "seconds")) {
case _: Exception => Escalate // because of other threads
}
}
case class Order(title: String)
case class Ordered()
object orderSingleton {
def orderBook(title: String): Unit = {
new FileWriter("orders.txt", true) { // append to end of file
write(s"$title\n")
close()
}
}
}
示例4: Supervision
//设置package包名称以及导入依赖的类
package com.pagerduty.scheduler.akka
import akka.actor.SupervisorStrategy.Escalate
import akka.actor.{AllForOneStrategy, SupervisorStrategy, SupervisorStrategyConfigurator}
import com.pagerduty.scheduler.Scheduler
object Supervision {
val AlwaysEscalateStrategy = AllForOneStrategy() {
case _: Throwable => Escalate
}
def makeAlwaysEscalateTopicSupervisorStrategy(logger: Scheduler.Logging): AllForOneStrategy = {
AllForOneStrategy() {
case throwable: Throwable => {
logger.reportActorSystemRestart(throwable)
Escalate
}
}
}
}
final class UserGuardianEscalateStrategy extends SupervisorStrategyConfigurator {
override def create(): SupervisorStrategy = Supervision.AlwaysEscalateStrategy
}
示例5: 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]
}
示例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)
}
}
示例7: SupervisorActor
//设置package包名称以及导入依赖的类
package com.nossin.ndb
import akka.actor.SupervisorStrategy.{Escalate, Restart}
import akka.actor.{Actor, OneForOneStrategy, Props}
import com.nossin.ndb.messages.Messages.StopActor
import scala.concurrent.duration._
class SupervisorActor extends Actor {
//One for One , only restart failed actor not any others/siblings. useful if actors are independed.
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute)
{
case _: ArithmeticException => Restart
case t =>
super.supervisorStrategy.decider.applyOrElse(t, (_: Any) => Escalate)
}
def receive = {
case (props: Props, name: String) => sender ! context.actorOf(props, name)
case StopActor(actorRef) => context.stop(actorRef)
}
}
示例8: 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"
}
}
}
示例9: AuditNode
//设置package包名称以及导入依赖的类
package audit
import akka.actor.SupervisorStrategy.Escalate
import akka.actor.{Actor, OneForOneStrategy, Props, SupervisorStrategy}
import audit.collector.CollectorActor
import audit.collector.CollectorActor.CollectorRequest
import audit.viewer.ViewerActor
import audit.viewer.ViewerActor.ViewerRequest
import com.datastax.driver.core.Cluster
class AuditNode(cluster: Cluster.Builder, settings: AuditSettings) extends Actor {
val session = cluster.build().connect()
val collector = context.actorOf(CollectorActor.props(session), "collector")
val viewer = context.actorOf(ViewerActor.props(session), "viewer")
override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy() {
case e: Exception => Escalate
}
override def receive: Receive = {
case req: CollectorRequest => collector forward req
case req: ViewerRequest => viewer forward req
}
}
object AuditNode {
def props(cluster: Cluster.Builder, settings: AuditSettings) = Props(new AuditNode(cluster, settings))
}
示例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
})
}
}
示例11: TopSupervisor
//设置package包名称以及导入依赖的类
package io.anydev.container
import akka.actor.SupervisorStrategy.{Escalate, Stop}
import akka.actor.{Actor, ActorInitializationException, ActorKilledException, ActorLogging, AllDeadLetters, OneForOneStrategy, SupervisorStrategy}
import io.anydev.container.infrastructure.endpoint.HttpServerActor
import io.scalaberries.akka.{ActorEmptyReceive, ActorFactory}
class TopSupervisor extends Actor with ActorLogging with ActorEmptyReceive {
private val system = context.system
HttpServerActor.actor
override val supervisorStrategy: SupervisorStrategy = OneForOneStrategy() {
case _: ActorKilledException => Escalate
case _: ActorInitializationException => Escalate
case _ => Stop
}
override def preStart(): Unit = {
system.eventStream.subscribe(self, classOf[AllDeadLetters])
}
override def receive: Receive = {
case any =>
}
}
object TopSupervisor extends ActorFactory {
override implicit val actorClass = classOf[TopSupervisor]
override implicit val actorName = "top-supervisor-actor"
}
示例12: EventActor
//设置package包名称以及导入依赖的类
package com.github.lzenczuk.akka.course.failover
import akka.actor.SupervisorStrategy.{Escalate, Restart, Resume}
import akka.actor.{Actor, ActorLogging, AllForOneStrategy, OneForOneStrategy, SupervisorStrategy}
import com.github.lzenczuk.akka.course.failover.MarketActor.MarketException
import scala.util.Random
import scala.concurrent.duration._
object EventActor {
sealed trait EventCommand
case class CreateMarket() extends EventCommand
}
class EventActor extends Actor with ActorLogging {
import EventActor._
import scala.math.abs
override def receive = {
case CreateMarket() =>
log.info("creating market")
val marketId: Long = abs(Random.nextLong())
context.actorOf(MarketActor.props(marketId), s"Market_$marketId")
}
override val supervisorStrategy = AllForOneStrategy(maxNrOfRetries = 5, withinTimeRange = 1 second, false){
case MarketException(msg) =>
log.info(s"Market exception $msg. Restart.")
Restart
case t =>
log.info("Not supported exception")
super.supervisorStrategy.decider.applyOrElse(t, (_:Any) => Escalate)
}
}