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. 二叉树根结点到任意结点的路径(C语言)

    有一棵二叉树,如下图所示: 其中 # 表示空结点. 先序遍历:A B D E G C F 问题:怎么得到从根结点到任意结点的路径呢? 示例:输入 G,怎么得到从结点 A 到结点 G 的路径呢? 很明显 ...

  2. Ubuntu 固定自己的IP

    使用以下命令 sudo vi /etc/network/interfaces 以下方文件内容进行覆盖 ​# interfaces(5) file used by ifup(8) and ifdown( ...

  3. 论文笔记: Deep Learning based Recommender System: A Survey and New Perspectives

    (聊两句,突然记起来以前一个学长说的看论文要能够把论文的亮点挖掘出来,合理的进行概括23333) 传统的推荐系统方法获取的user-item关系并不能获取其中非线性以及非平凡的信息,获取非线性以及非平 ...

  4. @SuppressWarnings注解用法

    @SuppressWarnings注解主要用在取消一些编译器产生的警告对代码左侧行列的遮挡,有时候这会挡住我们断点调试时打的断点. 如图所示: 这时候我们在方法上加上@SuppressWarnings ...

  5. nrm的安装和使用

    1.安装nodejs,下载地址,http://nodejs.cn/download/,安装过程直接点击下一步即可 安装完成后cmd输入npm -v 查看当前安装的npm的版本,如下图提示所示则表示安装 ...

  6. Net实现钩子函数(Hook)以及通过SendMessage实现自动点击按钮和给文本框赋值

    1.实现钩子函数 钩子(Hook)的实现需要三个主要的函数和一个委托 [DllImport("user32.dll", CharSet = CharSet.Auto, Callin ...

  7. C# vb .net实现缩放特效滤镜

    在.net中,如何简单快捷地实现Photoshop滤镜组中的缩放特效呢?答案是调用SharpImage!专业图像特效滤镜和合成类库.下面开始演示关键代码,您也可以在文末下载全部源码: 设置授权 第一步 ...

  8. Dockerfile构建jar镜像

    dockerDockerfilejar包docker-compose 一.安装docker和compose 二.准备jar包 三.编写配置文件 1. Dockerfile 2. docker-comp ...

  9. C++ STL vector类型

    vector容器是一个模板类,可以存放任何类型的对象(但必须是同一类对象).vector对象可以在运行时高效地添加元素,并且vector中元素是连续存储的.注:vector容器内存放的所有对象都是经过 ...

  10. 【面试突击】- 2019年125条常见的java面试笔试题汇总(二)

    26.什么时候用assert. assertion(断言)在软件开发中是一种常用的调试方式,很多开发语言中都支持这种机制.在实现中,assertion就是在程序中的一条语句,它对一个boolean表达 ...