actor

Use Post or PostAndAsyncReply with F#'s MailboxProcessor?

微笑、不失礼 提交于 2019-12-22 05:53:23
问题 I've seen different snippets demonstrating a Put message that returns unit with F#'s MailboxProcessor . In some, only the Post method is used while others use PostAndAsyncReply , with the reply channel immediately replying once the message is being processed. In doing some testing, I found a significant time lag when awaiting the reply, so it seems that unless you need a real reply, you should use Post . Note: I started asking this in another thread but thought it useful to post as a full

Akka remote actors, superclass without default constructor

允我心安 提交于 2019-12-22 05:23:18
问题 I am trying to send a message using akka remote actors, where the case class is a subclass of a superclass taking argument in its constructor. Here is a minimum example to reproduce the problem: package com.tuvistavie.testremote import akka.actor.{ Actor, ActorSystem, Props, ActorLogging } import com.typesafe.config.ConfigFactory abstract class Foo(val a: Int) case class MessageFoo(override val a: Int) extends Foo(a) object Sender { def main(args: Array[String]) { val system = ActorSystem(

Client-Server example with Scala actors

自作多情 提交于 2019-12-22 05:16:33
问题 What is the best way to implement the following example ? Actor server receives Requests , handles them, creates a new Response for each Request and sends the Response back to the Request sender. Actor client sends Requests and receives Responses . All this communication is asynchronous and hence it uses react . This is just an example and so it should not handle all those cases like server is down, client is stuck, etc. It should be just concise and expressive. 回答1: import scala.actors._

访问者模式

走远了吗. 提交于 2019-12-22 01:01:04
访问者模式定义如下:封装一些作用于某种数据结构中各个元素的操作,它可以在不改变数据结构的前提下定义作用于这些元素的新的操作。 下面看一下几个抽象角色: Visitor抽象访问者:抽象类或接口,定义访问者可以访问哪些元素。 ConcreateVisitor具体访问者:它影响访问者访问到一个类之后该怎么办,做哪些事情。 Element抽象元素:接口或抽象类,声明接收哪一类访问者访问,程序中通过accept方法中的参数来定义 ConcreateElement具体元素:实现accept方法,通常是visitor.visit(this),基本上都是一种固定形式了 ObjectStructure结构对象:元素产生者,一般容纳在多个不同类、不同接口的容器,如List Map等,在项目中,一般很少抽象出这个角色 看一下访问者模式的通用代码: //抽象元素 public abstract class Element{ //定义业务逻辑 public abstract void doSomething(); //允许谁来访问 public abstract void accept(IVisitor visitor); } //具体元素 public class ConcreateElement1 extends Element{ //完善业务逻辑 public void doSomething(){

Akka Actor “ask” and “Await” with TimeoutException

不问归期 提交于 2019-12-21 12:31:07
问题 I'm modeling a simple P2P with Scala and Akka: class Node() extends Peer with Actor { var peers: List[ActorRef] = List() def receive = { case _register(peer: ActorRef, p: Option[Int]) => { println("registering [" + peer + "] for [" + this + "]") peers = peer :: peers } } } sealed case class _register(val peer: ActorRef, var p: Option[Int] = None) and then a simple network: class Network() extends Actor { def this(name: String) = { this() val system = ActorSystem(name) val s1 = system.actorOf

Advantages of actors over futures

末鹿安然 提交于 2019-12-21 09:27:19
问题 I currently program in Futures, and I'm rather curious about actors. I'd like to hear from an experienced voice: What are the advantages of actors over futures? When should I use one instead of other? As far as I've read, actors hold state and futures doesn't, is this the only difference? So if I have true immutability I shouldn't care about actors? Please enlighten me :-) 回答1: One important difference is that actors typically have internal state, and therefore theoretically, they are not

Akka/Scala: mapping Future vs pipeTo

蓝咒 提交于 2019-12-21 07:26:08
问题 In Akka actors, are there any differences - in terms of number of threads being used, or thread locking - between sending a Future result to another actor by: A. mapping the Future to function that tell the result to the actor. B. defining an onSuccess callback on the future, which tell the result to the actor. C. piping the Future result to the actor with pipeTo . Some of these options are discussed in a previous question: Akka: Send a future message to an Actor Which one of the three is the

How to hide Akka remote actors from lookup?

自闭症网瘾萝莉.ら 提交于 2019-12-21 05:27:18
问题 I am running the Akka 2.0.2 microkernel and want to implement an authentication scheme for untrusted remote actors. The first thing that comes to mind is to set up an authentication actor which returns a reference to the work actor when authentication succeeds. However, how should I protect the work actor from simply being directly looked up remotely via actorFor(), circumventing authentication altogether? That is, I want to prevent remote actors from accessing actors in my microkernel actor

Writing applications with Scala actors in practice

让人想犯罪 __ 提交于 2019-12-21 04:59:13
问题 I've now written a few applications using scala actors and I'm interested in how people have approached or dealt with some of the problems I've encountered. A plethora of Message classes or !? I have an actor which reacts to a user operation and must cause something to happen. Let's say it react s to a message UserRequestsX(id) . A continuing problem I have is that, because I want to modularize my programs, a single actor on its own is unable to complete the action without involving other

Akka Design Principals

可紊 提交于 2019-12-21 02:43:06
问题 Whilst working on a fairly large Akka application, I have come across a very simple structure when working with normal methods and non Akka classes but which are actually quite difficult to nail when working with Akka which is why I have come here to ask what you recommend to be the best way to solve this issue. So the issue is this, I have one parent actor, let's call him "Connector", Connector has behavior describing what it should do when it receives a ConnectCommand instance. First it