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


Scala Success类代码示例

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


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

示例1: ExecutionLauncher

//设置package包名称以及导入依赖的类
package net.mikolak.pomisos.process

import akka.actor.{Actor, ActorLogging, Props}
import net.mikolak.pomisos.prefs.Execution
import scala.sys.process._
import language.postfixOps
import akka.actor.Status.Success

class ExecutionLauncher(execution: Execution) extends Actor with ActorLogging with Launcher with CommandExecution {

  import ExecutionLauncher._

  private val cmd = execution.cmd

  private def running_?() = cmd.exists(c => s"pgrep -f $c".!(devnullProcessLogger) == 0)

  protected def main: Receive = {
    case OnBreak =>
      if (!running_?()) {
        cmd.foreach(c => {
          log.debug(s"Launching command: $c")
          context.actorOf(Props[DeferredExecutor]) ! (s"nohup $c", CodesToIgnore)
        })
      }
    case OnPomodoro =>
      var killsLeft = KillsToTry
      log.debug(s"Attempting to kill process for: $cmd")
      while (running_?() && killsLeft > 0) {
        cmd.foreach { c =>
          execute(s"pkill -f $c")
          killsLeft -= 1
        }
      }
      if (running_?() && killsLeft == 0) {
        reportError(s"Failed to kill process $cmd after $KillsToTry attempts.")
      } else {
        log.debug(s"Successfully killed process for: $cmd")
      }
  }

}

object ExecutionLauncher {

  type ErrorInfo = (Int, String)

  type CommandStatus = Either[ErrorInfo, Success]

  val KillsToTry = 10

  private val RootSigReturnCode = 128
  private val SigTermCode       = RootSigReturnCode + 15
  private val KillCode          = RootSigReturnCode + 9
  val CodesToIgnore             = Set(SigTermCode, KillCode)

  def devnullProcessLogger = ProcessLogger(_ => (), _ => ())
} 
开发者ID:mikolak-net,项目名称:pomisos,代码行数:58,代码来源:ExecutionLauncher.scala


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