actor

AKKA Inbox收件箱

匿名 (未验证) 提交于 2019-12-03 00:03:02
起因 得到ActorRef就可以给actor发送消息,但无法接收多回复,也不知道actor是否停止 Inbox收件箱出现就是解决这两个问题 示例 package akka . demo . actor import akka . actor .* import java . time . Duration /** ** created by tankx ** 2019/9/12 与actor 通信模式ask或tell 无法支持接收多回复和观察其它actor的生命周期,所以inbox应用而生 **/ fun main () { val system = ActorSystem . create ( "box-sys" ) val helloActor = system . actorOf ( HelloActor . props ( "tom" )) helloActor . tell ( "hi" , ActorRef . noSender ()) val box = Inbox . create ( system ) box . send ( helloActor , "how are you!" ) box . watch ( helloActor ) //监控actor 的生命周期,当actor stop, receive会接收到Terminated消息 helloActor

Scala-Akka 实例

匿名 (未验证) 提交于 2019-12-02 23:45:01
Akka 实例 18.1需求分析   实现一个分布式模型,Master 保持所有 Worker 节点的信息,根据 Worker 的心跳信息维持与 Worker 的连接,Worker 启动时向 Master 节点进行 18.2项目源代码 18.2.1 新建 Maven 项目 AkkaSystem class WorkerInfo(val id : String, val workerHost : String, val memory : String, val cores : String) { var lastHeartbeat : Long = System.currentTimeMillis() override def toString = s"WorkerInfo($id, $workerHost, $memory, $cores)" } case class RegisterWorker(val id : String, val workerHost : String, val memory : String, val cores : String) case class HeartBeat(val workid : String) case class CheckOfTimeOutWorker() case class RegisteredWorker(val

How would you explain actors to a non-programmer? [closed]

佐手、 提交于 2019-12-02 22:39:10
Well, the title's pretty much it: if I sat a non-techie/my mum/twelve-year old boy/cocker spaniel in front of you and asked you to explain actors to them, where would you start? I ask because my master's project involves them to a pretty large degree, and every other day someone asks me to tell them what I'm doing. When I'm talking to other people on my course it's not so bad—usually the concept is foreign but understandable—but recently my flatmate, a chemist, asked me to explain it to her, and to say I struggled would be a pretty humongous understatement. I'm looking for some sort of

《通过C#学Proto.Actor模型》之 HelloWorld

匿名 (未验证) 提交于 2019-12-02 22:06:11
在微服务中,数据最终一致性的一个解决方案是通过有状态的Actor模型来达到,那什么是Actor模型呢? Actor是并行的计算模型,包含状态,行为,并且包含一个邮箱,来异步处理消息。 关于Actor的介绍可参考: https://www.jianshu.com/p/449850aa8e82 https://www.jianshu.com/p/db04cab86ab9 这次要说一下Proto.Actor,关于Proto.Actor的资料较少,这里有一篇可以作简单入门 https://studygolang.com/p/protoactor 为了便于开码友们理解,这个系列就以代码为主来学习,通过代码来“意会”Proto.Actor,所以这个系列叫《通过C#学Proto.Actor模型》 Proto.Actor特点是:异步,分布式,高并发,高容错性,跨语言调用 《通过C#学Proto.Actor模型》之 HelloWorld: 代码:https://github.com/axzxs2001/ProtoActorSample/tree/master/ProtoActorSample/P001_HelloWorld 引用NuGet:Proto.Actor 1 using Proto; 2 using System; 3 using System.Threading.Tasks; 4 5

Java高并发程序设计―Akka

匿名 (未验证) 提交于 2019-12-02 21:40:30
注:其一、本文章为作者读完《实战Java高并发程序设计》之后所总结的知识,其中涵盖了每一章节的精髓之处。其二、文章中一部分代码直接引自书中。 使用Akka构建高并发程序设计 1.1.新并发模型:Actor 在并发程序中,线程始终是并发程序的基本执行单元。但是在 Akka 中,你将会使用一个全新的执行单元― Actor ,而不再需要线程的概念。 在Actor模型中,我们不在需要调用对象(例如Actor)的方法去执行一些业务逻辑代码,而是通过给Actor发送一条消息。Actor接收到消息之后,它会根据消息的内容做出一些行为,包括改变自身的状态(自发式进行) 1.2.Akka֮HelloWorld 第一个Actor实现 public class Greeter extends UntypedActor { public static enum Msg { GERRT , DONE ; //消息类型 } @Override public void onReceive ( Object msg ) { if ( msg == Msg . GERRT ) { System . out . println ( "Hello World!" ) ; getSender ( ) . tell ( Msg . DONE , getSelf ( ) ) ; } else { unhandled (

Akka and ReactiveMongo

怎甘沉沦 提交于 2019-12-02 21:06:04
I am trying to find the best approach to sharing the same pool of connection between actors withing the cluster workers. I have the following structure: Master Actor -> Worker Actors(can be up to 100 or more) -> MongoDB Between workers and MongoDB I want to put reactivemongo, however I am not sure how exactly to provide connection pool sharing between all actors. According to reactivemongo documentation: A MongoDriver instance manages an actor system; a connection manages a pool of connections. In general, MongoDriver or create a MongoConnection are never instantiated more than once. You can

How are akka actors implemented on underlying threads?

こ雲淡風輕ζ 提交于 2019-12-02 20:51:31
Given an execution context and a thread pool, how are akka/scala actors scheduled/implemented on that? I was confused with this topic for a long time. I assumed that there is some relation between threads and actors. For each actor there is a thread that hosts it, so I was thinking. Probably there are several actors for each thread that works in cooperative multitasking mode. Documentation is focused on usage and cover internal architecture lightly. You just should extend Actor class and you would get working actor. So I tried to guess how can this be done. And imagined that each Actor has

Is it good to put jdbc operations in actors?

两盒软妹~` 提交于 2019-12-02 20:40:23
I am building a traditional webapp that do database CRUD operations through JDBC. And I am wondering if it is good to put jdbc operations into actors, out of current request processing thread. I did some search but found no tutorials or sample applications that demo this. So What are the cons and pros? Will this asynchonization improve the capacity of the appserver(i.e. the concurrent request processed) like nio? leedm777 Whether putting JDBC access in actors is 'good' or not greatly depends upon the rest of your application. Most web applications today are synchronous, thanks to the Servlet

How do I best share behavior among Akka actors?

本小妞迷上赌 提交于 2019-12-02 20:32:49
I have two Akka actors that respond to some messages in the same way, but others in a different way. They both respond to the same set of messages. Wondering how to design my two actors with their receive methods, via inheritance, composure, etc? I tried chaining together partial functions from other traits with "orElse", which unfortunately exposes the class to its trait's functionality, plus I wasn't sure how the trait's receive could easily access the actor context. A drop-in, modularized solution would be ideal, but I'm wondering if this is a solved problem somewhere? There's really a

Scala pattern matching confusion with Option[Any]

落花浮王杯 提交于 2019-12-02 20:12:28
I have the following Scala code. import scala.actors.Actor object Alice extends Actor { this.start def act{ loop{ react { case "Hello" => sender ! "Hi" case i:Int => sender ! 0 } } } } object Test { def test = { (Alice !? (100, "Hello")) match { case i:Some[Int] => println ("Int received "+i) case s:Some[String] => println ("String received "+s) case _ => } (Alice !? (100, 1)) match { case i:Some[Int] => println ("Int received "+i) case s:Some[String] => println ("String received "+s) case _ => } } } After doing Test.test , I get the output: scala> Test.test Int received Some(Hi) Int received