learning scala akka ask_pattern
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的更多相关文章
- learning scala akka actorySystem create and close
package com.example import akka.actor.ActorSystem import scala.util.{Failure, Success} import scala. ...
- learning scala akka tell pattern(二)
package com.example import akka.actor._ object Tutorial_02_Tell_Pattern extends App { println(" ...
- scala akka Future 顺序执行 sequential execution
对于 A => B => C 这种 future 之间的操作,akka 默认会自动的按照顺序执行,但对于数据库操作来说,我们希望几个操作顺序执行,就需要使用语法来声明 有两种声明 futu ...
- 【原创】大叔经验分享(73)scala akka actor
import java.util.concurrent.{ExecutorService, Executors, TimeUnit} import akka.actor.{Actor, ActorSy ...
- [Scala] akka actor编程(一)
Akka基础 Akka笔记之Actor简介 Akka中的Actor遵循Actor模型.你可以把Actor当作是人.这些人不会亲自去和别人交谈.他们只通过邮件来交流. 1. 消息传递 2. 并发 3 ...
- scala akka 修炼之路5(scala特质应用场景分析)
scala中特质定义:包括一些字段,行为(方法/函数/动作)和一些未实现的功能接口的集合,能够方便的实现扩展或混入到已有类或抽象类中. scala中特质(trait)是一个非常实用的特性,在程序设计中 ...
- learning scala 数组和容器
数组:可变的,可索引的,元素具有相同类型的数据集合 一维数组 scala> val intValueArr = new Array[Int](3)intValueArr: Array[Int] ...
- learning scala control statement
1 .if satement 与其它语言不同的是,scala if statement 返回的是一个值 scala> val a = if ( 6 > 0 ) 1 else -1a: In ...
- learning scala read from file
scala读文件: example: scala> import scala.io.Sourceimport scala.io.Source scala> var inputFile ...
随机推荐
- 下载并使用MNIST数据集
TensorFlow提供了一个库,可以直接用来自动下载与安装MNIST. MNIST里包含3个数据集:第一个是训练数据集(mnist.train.images),另外两个分别是测试数据集(mnist. ...
- Java8 集合相关操作
// java8 集合快速转成string List<String> cities; String citiesCommaSeparated = String.join(",&q ...
- ELK学习笔记之logstash将配置写在多个文件
0x00 概述 我们用Logsatsh写配置文件的时候,如果读取的文件太多,匹配的正则过多,会使配置文件动辄成百上千行代码,可能会造成阅读和修改困难.这时候,我们可以将配置文件的输入.过滤.输出分别放 ...
- .NET 使用 ILMerge 合并多个程序集,避免引入额外的依赖
原文:.NET 使用 ILMerge 合并多个程序集,避免引入额外的依赖 我们有多种工具可以将程序集合并成为一个.打包成一个程序集可以避免分发程序的时候带上一堆依赖而出问题. ILMerge 可以用来 ...
- 如何监视 WPF 中的所有窗口,在所有窗口中订阅事件或者附加 UI
原文:如何监视 WPF 中的所有窗口,在所有窗口中订阅事件或者附加 UI 由于 WPF 路由事件(主要是隧道和冒泡)的存在,我们很容易能够通过只监听窗口中的某些事件使得整个窗口中所有控件发生的事件都被 ...
- 使用Dapper查询记录是否存在
/// <summary> /// Dapper数据访问抽象基础类 /// </summary> public class DapperHelper { public stat ...
- 在IOS10系统中无法定位问题
果是非https网页,在http协议下通过html5原生定位接口会返回错误,也就是无法正常定位到用户的具体位置,而已经支持https的网站则不会受影响. 目前提供的解决方案: 1.将网站的http设置 ...
- Docker 四种网络模式
原文 https://www.cnblogs.com/gispathfinder/p/5871043.html 我们在使用docker run创建Docker容器时,可以用--net选项指定容器的网络 ...
- 自学Python编程的第十天(希望有IT大牛看见的指点小弟我,万分感谢)---------来自苦逼的转行人
2019-09-20-23:24:15 今天逛论坛.逛知识星球时.逛b站up主时,都说到低学历,非科班的人最好不要去自学Python 他们都说:如果我们学python是为了找工作,最好不要把pytho ...
- python基础知识(七)---数据类型补充、"雷区"、编码
数据类型补充."雷区".编码 1.数据类型补充 str: #字符串数据类型补充 s1=str(123) #常用于类型转换 print(s1) #capitalize()首字母大写 ...