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

Scala Escalate类代码示例

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

本文整理汇总了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 = ???
} 
开发者ID:dkmn,项目名称:week-3-lecture-examples,代码行数:23,代码来源:ProcrusteanManager.scala


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

} 
开发者ID:otavioucdb,项目名称:akka_sample,代码行数:52,代码来源:ColetorNotificacoesActor.scala


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


示例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
} 
开发者ID:PagerDuty,项目名称:scheduler,代码行数:26,代码来源:Supervision.scala


示例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]
} 
开发者ID:syedatifakhtar,项目名称:TinderBot,代码行数:39,代码来源:BotSupervisor.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: 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)
  }
} 
开发者ID:michelnossin,项目名称:ndb,代码行数:21,代码来源:SupervisorActor.scala


示例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"
		}
	}
} 
开发者ID:uryyyyyyy,项目名称:akkaSample,代码行数:29,代码来源:ParentActor.scala


示例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))
} 
开发者ID:grzesiekw,项目名称:audit,代码行数:30,代码来源:AuditNode.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: 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"
} 
开发者ID:herdes,项目名称:herdes-agent,代码行数:31,代码来源:TopSupervisor.scala


示例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)
  }
} 
开发者ID:lzenczuk,项目名称:akka-app-one,代码行数:37,代码来源:EventActor.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala NaiveBayes类代码示例发布时间:2022-05-23
下一篇:
Scala JUnitRunner类代码示例发布时间: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