actor

What does a single apostrophe mean in Scala?

孤街浪徒 提交于 2019-11-28 07:07:41
In this slide show on ScalaActors.pdf what does the single quote indicate when the message is sent to the pong actor? class Ping(count: int, pong: Pong) extends Actor { def act() { pong ! 'Ping // what does the single quote indicate??? receive { case 'Pong => } } } Dave Ray This defines a literal Symbol . See also this question . It indicates a Symbol. Eg. cfr http://www.scala-lang.org/docu/files/api/scala/Symbol.html : the Scala term 'mysym will invoke the constructor of the Symbol class in the following way: Symbol("mysym"). 来源: https://stackoverflow.com/questions/918590/what-does-a-single

Actor - 初识

Deadly 提交于 2019-11-28 06:39:04
  Actor是消息并发模型。   在Scala中Actor能够实现并行编程(2.10.x以前的版本),是基于事件模型的并发机制   Scala是运用消息的发送、接收来实现多线程 大家知道 Java的多线程需要注意线程安全,有锁的概念,这就难免会出现死锁等问题,因为Java中多数使用的是可变状态的对象资源。 而Scala中所有皆对象,都是不可变资源,再基于Actor的消息来实现并行 Actor方法执行顺序 调用 start() 方法,启动 Actor 执行 act() 方法 向 Actor 发送消息 消息发送方式 ! —— 发送异步消息,没有返回值 !? —— 发送同步消息,等待返回值 !! —— 发送异步消息,返回值是 Future[Any] 来源: https://www.cnblogs.com/sunnystone85/p/11397618.html

[ 转载 ] Android设计模式详解

非 Y 不嫁゛ 提交于 2019-11-28 05:29:31
从Android再来认识23种设计模式 ReadyShow 关注 0.2 2018.01.06 23:18* 字数 3855 阅读 2584 评论 0 喜欢 20 概况来看本文章的内容 创建型:5个 单例模式 Builder 原型模式 工厂方法 抽象工厂 行为型: 11个 策略模式 状态模式 观察者模式 中介者模式 访问者模式 迭代器模式 模板方法 备忘录模式 命令模式 解释器模式 职责链模式 结构型:7个 组合模式 代理模式 装饰模式 外观模式 享元模式 桥接模式 适配器模式 关于面向对象 面向对象的六大原则 谈到设计模式,不得不说说面向对象的六大原则 1. 单一原则 单一原则通俗的讲就是一个类只表达一个概念、一个方法只做一件事情。将一组相关性很高的函数、数据封装到一个类中。换句话说,一个类应该有职责单一。 2. 开闭原则 开闭原则就是一个类对于扩展是开发的,但是对于修改是封闭的。这也是六大原则中最难的,通常开闭都是短暂的美好,但在业务升级与拓展的状态下,原理的开闭是无法满足。即使是这样,也要尽可能的扩展而不是修改。 3. 里氏替换原则 所有引用基类的地方必须能透明地使用其子类对象 。看着定义很是抽象,但是通俗的理解就是由子类实例化的父类引用,在使用这个引用时,感觉就像是使用了父类一样。一个简单的例子: public class T{ private class A{...}

akka并发编程练习

被刻印的时光 ゝ 提交于 2019-11-28 04:56:14
用 Scala 的akka同时向多个节点发送信息(广播) 思路 :每个客户端向服务端发送登陆信息后,服务端记录发送者,存入列表中,客户端向服务端发送的其他信息向所有已登录的客户端发送 这个程序实现了消息的简单广播 首先实现服务端 package com.bit.room import akka.actor.{Actor, ActorRef, ActorSystem, Props} import com.typesafe.config.ConfigFactory import scala.collection.mutable class TalkServer extends Actor { //伴生类 val talkerSet = new mutable.HashSet[ActorRef]() override def receive: Receive = { case "launch" => println("Server on") //接受launch 打印启动 case "exit" => { //接受到exit,将发送者从聊天室Set移除 talkerSet.remove(sender()) if (talkerSet.nonEmpty) { println(sender().toString() + "off") talkerSet.foreach(Refs =>

When to use actors in libgdx? What are cons and pros?

蓝咒 提交于 2019-11-28 04:24:04
I'm writing simple solar system simulator. This is my first libgdx project. I'm using a Stage and Actors for the main menu and is pretty handy especially touch events handling. But ... looking at the examples i see nobody uses actors in actual game logic. I wander if i should use actor as a parent of planet class or just write my own class tor that. The planets won't be touchable and they will be moved only between the frames so the third parameter of action MoveBy will have to be time between frames. That are the cons. What are the pros for using Actors? The main pros for Actors are Actions,

TPL Dataflow, how to forward items to only one specific target block among many linked target blocks?

有些话、适合烂在心里 提交于 2019-11-28 02:31:51
问题 I am looking for a TPL data flow block solution which can hold more than a single item, which can link to multiple target blocks, but which has the ability to forward an item to only a specific target block that passes a filter/predicate. At no time should an item be delivered to multiple target blocks at the same time, always only to the one which matches the filter or the item can be discarded. I am not fond of BroadCastBlock because, if I understand correctly, it does not guarantee

Can Actors in Scala fail to process messages? (example in O'Reilly's Programming Scala)

大兔子大兔子 提交于 2019-11-28 01:41:42
问题 I'm completely new to Scala, and I've been working my way through Programming Scala (O'Reilly) online; while doing so, I was surprised by the result of the shapes-actor-script.scala example in Chapter 1, "A Taste Of Concurrency". Specifically, the output of running scala -cp . shapes-actor-script.scala should be: Circle.draw: Circle(Point(0.0,0.0),1.0) Rectangle.draw: Rectangle(Point(0.0,0.0),2.0,5.0) Triangle.draw: Triangle(Point(0.0,0.0),Point(1.0,0.0),Point(0.0,1.0)) Error: Unknown message

Parallel file processing in Scala

醉酒当歌 提交于 2019-11-27 22:31:07
Suppose I need to process files in a given folder in parallel. In Java I would create a FolderReader thread to read file names from the folder and a pool of FileProcessor threads. FolderReader reads file names and submits the file processing function ( Runnable ) to the pool executor. In Scala I see two options: create a pool of FileProcessor actors and schedule a file processing function with Actors.Scheduler . create an actor for each file name while reading the file names. Does it make sense? What is the best option? I suggest with all my energies to keep as far as you can from the threads.

好程序员大数据学习路线分享Actor学习笔记

家住魔仙堡 提交于 2019-11-27 21:18:32
  好程序员大数据学习路线分享Actor学习笔记, 在 scala中她能实现很强大的功能,他是基于并发机制的一个事件模型 我们现在学的 scala2.10.x版本就是之前的Actor 同步 :在主程序上排队执行的任务,只有前一个任务执行完毕后,才能执行下一个任务 异步 :指不进入主程序,而进入"任务对列"的任务,只有等主程序任务执行完毕,"任务对列"开始请求主程序,请求任务执行,该任务会进入主程序 java 共享变量 -- 加锁 会出现锁死问题 scala Actor不共享数据 没有锁的概念 Actor通信之间需要message(通信) Aactor执行顺序 1.首先调用start()方法启动Actor 2.调用start()方法后act()方法会被执行 3.Actor之间进行发送消息 Actor发送消息的三种方式 ! -> 发送异步消息,没有返回值 !? -> 发送同步消息,有返回值,会有线程等待 !! -> 发送异步消息,有返回值,返回值类型Future[Any](用来获取异步操作结果) Actor并行执行 //注意,这两个actor会并行执行,当其中一个for循环结束后,actor结束 object ActorDemo01 { def main(args: Array[String]): Unit = { MyActor1.start() MyActor2.start() }

Different Scala Actor Implementations Overview

瘦欲@ 提交于 2019-11-27 19:45:59
问题 I'm trying to find the 'right' actor implementation. I realized there is a bunch of them and it's a bit confusing to pick one. Personally I'm especially interested in remote actors, but I guess a complete overview would be helpful to many others. This is a pretty general question, so feel free to answer just for the implementation you know about. I know about the following Scala Actor implementations (SAI). Please add the missing ones. Scala 2.7 (difference to) Scala 2.8 Akka (http://www