package com.example

import  akka.actor._
import akka.util.Timeout object Tutorial_03_Ask_Pattern extends App {
val system = ActorSystem("DonutStoreActorySystem") val donutInfoActor = system.actorOf(Props[DonutInfoActor], name="DonutInfoActor") import DonutStoreProtocal._
import akka.pattern._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._ implicit val timeout = Timeout( second) val vanillaDonutFound = donutInfoActor ? Info("vanilla")
for {
found <- vanillaDonutFound
} yield (println(s"Vanilla donut found = $found")) val glazedDountFound = donutInfoActor ? Info("glazed")
for {
found <- glazedDountFound
} yield (println(s"Glazed donut found = $found")) Thread.sleep() system.terminate(); object DonutStoreProtocal{
case class Info(name: String)
} class DonutInfoActor extends Actor with ActorLogging {
import Tutorial_03_Ask_Pattern.DonutStoreProtocal._ override def receive: Receive = {
case Info(name) if name == "vanilla" =>
log.info(s"Found valid $name donut")
sender ! true
case Info(name) =>
log.info(s"$name donut is not supported")
sender ! false
}
}
}

result:

Vanilla donut found = true
[INFO] [// ::51.502] [DonutStoreActorySystem-akka.actor.default-dispatcher-] [akka://DonutStoreActorySystem/user/DonutInfoActor] Found valid vanilla donut
Glazed donut found = false
[INFO] [// ::51.512] [DonutStoreActorySystem-akka.actor.default-dispatcher-] [akka://DonutStoreActorySystem/user/DonutInfoActor] glazed donut is not supported

learning scala akka ask_pattern的更多相关文章

  1. learning scala akka actorySystem create and close

    package com.example import akka.actor.ActorSystem import scala.util.{Failure, Success} import scala. ...

  2. learning scala akka tell pattern(二)

    package com.example import akka.actor._ object Tutorial_02_Tell_Pattern extends App { println(" ...

  3. scala akka Future 顺序执行 sequential execution

    对于 A => B => C 这种 future 之间的操作,akka 默认会自动的按照顺序执行,但对于数据库操作来说,我们希望几个操作顺序执行,就需要使用语法来声明 有两种声明 futu ...

  4. 【原创】大叔经验分享(73)scala akka actor

    import java.util.concurrent.{ExecutorService, Executors, TimeUnit} import akka.actor.{Actor, ActorSy ...

  5. [Scala] akka actor编程(一)

    Akka基础 Akka笔记之Actor简介  Akka中的Actor遵循Actor模型.你可以把Actor当作是人.这些人不会亲自去和别人交谈.他们只通过邮件来交流.  1. 消息传递 2. 并发 3 ...

  6. scala akka 修炼之路5(scala特质应用场景分析)

    scala中特质定义:包括一些字段,行为(方法/函数/动作)和一些未实现的功能接口的集合,能够方便的实现扩展或混入到已有类或抽象类中. scala中特质(trait)是一个非常实用的特性,在程序设计中 ...

  7. learning scala 数组和容器

    数组:可变的,可索引的,元素具有相同类型的数据集合 一维数组 scala> val intValueArr = new Array[Int](3)intValueArr: Array[Int] ...

  8. learning scala control statement

    1 .if satement 与其它语言不同的是,scala if statement 返回的是一个值 scala> val a = if ( 6 > 0 ) 1 else -1a: In ...

  9. learning scala read from file

    scala读文件:   example: scala> import scala.io.Sourceimport scala.io.Source scala> var inputFile ...

随机推荐

  1. Selenium+Java(七)Selenium对话框的处理

    HTML代码如图所示: 一.alert String url = "file:///C:/Users/ex_yuhao/Desktop/index.html"; //引用IE浏览器 ...

  2. loj#10013 曲线(三分)

    题目 #10013. 「一本通 1.2 例 3」曲线 解析 首先这个题保证了所有的二次函数都是下凸的, \(F(x)=max\{s_i(x)\}i=1...n\)在每一个x上对应的最大的y,我们最后得 ...

  3. 设置断点调式 fiddler

    1. 用IE 打开博客园的登录界面  http://passport.cnblogs.com/login.aspx 2. 打开Fiddler,  在命令行中输入bpu http://passport. ...

  4. Flask 进阶

    OOP 面向对象反射 # __call__方法 # class Foo(object): # def __call__(self, *args, **kwargs): # return "i ...

  5. 非洲affrike单词

    affrike 英文单词,含义是非洲,非洲大陆. 中文名:非洲 外文名:affrike 目录 释义 affrike noun名词 非洲,也用做africa 1.Word Origin and Hist ...

  6. python检测远程udp端口是否打开的代码

    研发过程,把开发过程较好的代码收藏起来,如下的代码内容是关于python检测远程udp端口是否打开的代码,希望对各朋友有较大帮助. import socketimport threadingimpor ...

  7. Spring 实例化Bean的3种方式

    要使用Spring中的Bean,需要先创建这个Bean的实例. 实例化Bean有3种方式: 构造器方式 静态工厂方式 实例工厂方式 构造器方式 构造器方式是最常用的.在Bean中写构造函数,然后在配置 ...

  8. 如何使用Prometheus采集SAP ABAP Netweaver的应用日志数据

    Prometheus是一套开源的系统监控报警框架.它启发于Google的borgmon 监控系统,由工作在 SoundCloud 的 google 前员工在 2012 年创建,作为社区开源项目进行开发 ...

  9. MapReduce1.x与MapReduce2.x差异

    一.MapReduce1.x简介 1.图解 2.JobTracker 主节点,单点,负责调度所有的作用和监控整个集群的资源负载. 3.TaskTracker 从节点,自身节点资源管理和JobTrack ...

  10. windows添加ftp站点

    安装下,对应的服务: 在网站上,右键,添加,ftp站点. 配置路径: 然后下一步,选择所有用户,  读写权限.就可以了.