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


Scala Stop类代码示例

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


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


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