actor

Scala actor to non-actor interaction (or synchronizing messages from an actor to a servlet)

浪子不回头ぞ 提交于 2019-12-11 02:14:09
问题 I have the following scala code: package dummy import javax.servlet.http.{HttpServlet, HttpServletRequest => HSReq, HttpServletResponse => HSResp} import scala.actors.Actor class DummyServlet extends HttpServlet { RNG.start override def doGet(req: HSReq, resp: HSResp) = { def message = <HTML><HEAD><TITLE>RandomNumber </TITLE></HEAD><BODY> Random number = {getRandom}</BODY></HTML> resp.getWriter().print(message) def getRandom: String = {var d = new DummyActor;d.start;d.getRandom} } class

How should an akka actor be created that might throw an exception?

試著忘記壹切 提交于 2019-12-11 01:28:18
问题 I am migrating a project from scala actors to akka actors. I used to have something like this where the constructor of MyActor may throw an exception if a certain system resource is unavailable: var myActor: MyActor = null try { myActor = new MyActor(3) } catch { case e: SomeUserDefinedException => println("failed!") } With akka, I migrated the code to this: val someParam = 3 var myActor: ActorRef = null try { myActor = context.actorOf(Props(classOf[MyActor], someParam), "myActor") } catch {

Can Actors reply, which uses a thread local variable, cause a bug?

橙三吉。 提交于 2019-12-11 01:18:31
问题 I noticed that Actor reply invokes the reply method of a thread local variable of ReplyReactor type (see private method rawSelf ). This reply method sends a message to the senders.head , where the senders is a list of senders (see the source). Now I wonder if it may cause a bug. What if two actors share one thread with a thread local ReplyReactor instance ? Is there a scenario, when one of the actors replies to a wrong sender ? 回答1: Actors do share threads, but they cannot be interrupted.

scala actor message definition

浪尽此生 提交于 2019-12-10 19:47:12
问题 Do i need to define class for message i want to retrieve on a scala actor? i trying to get this up where am i wrong def act() { loop { react { case Meet => foundMeet = true ; goHome case Feromone(qty) if (foundMeet == true) => sender ! Feromone(qty+1); goHome }}} 回答1: You can think it as a normal pattern matching just like the following. match (expr) { case a => case b => } So, yes, you should define it first, use object for Message without parameters and case class for those has parameters.

Why I should use context.become() to store internal state in Actor?

怎甘沉沦 提交于 2019-12-10 19:45:52
问题 I've read scala-best-practices and have a question about "5.2. SHOULD mutate state in actors only with context.become". I don't understand why it is so bad to store internal state using var . If actor executes all messages sequentially I just can't see any source of problems. What do I miss? 回答1: Consider the first example in the article that you referenced: class MyActor extends Actor { val isInSet = mutable.Set.empty[String] def receive = { case Add(key) => isInSet += key case Contains(key)

Performance of message-passing in the Actor model [closed]

随声附和 提交于 2019-12-10 15:11:24
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I've seen benchmarks of Actor model implementations done in terms of their actors. For example, Akka actors are very lightweight (600 bytes per actor) and millions of them can be created. However, I've never seen a benchmark done in terms of message-passing throughput. For example, given some number of actors,

In Akka, how do I know when an actor is ready to use after having been registered with actorOf()?

放肆的年华 提交于 2019-12-10 15:03:14
问题 If I create an actor using context().actorOf() in Akka, I get back a valid ActorRef. However, if I do the same but create an ActorRef using actorFor and the path I know that the actor will appear at, I do not reliably get a valid ActorRef back. How can I tell that an actor has been registered successfully? In the description above, I could simply use the ActorRef returned from actorOf(). However, in my actual case I create an actor that itself registers a child actor and I need to resolve

Hard restart directive in Akka?

冷暖自知 提交于 2019-12-10 13:15:36
问题 Is there an elegant way of doing a hard restart of an actor - i.e. clearing out the mailbox along with internal state? I know it can be done by calling context.stop and reinitializing upon the DeathWatch / Terminated message, but that's a bit clunky. 回答1: No, clearing out the mailbox is exactly what is done by terminating the actor. If you were to try that without the termination semantics, how could you ever be sure that you cleared everything? New messages could come in at any point in time

Unable to create an actor using UnTypedActorFactory of akka java api

允我心安 提交于 2019-12-10 10:58:10
问题 I am trying to create an actor with untyped actor factory, compilation happens fine. But while running the application, I get the following error. Am I missing anything in configuration? Java Code: MyActor myactor = new MyActor(); //MyActor extends UnTypedActor ActorSystem system = ActorSystem.create("mynamespace"); ActorRef actor = system.actorOf(new Props(new UntypedActorFactory() { public UntypedActor create() { return myactor; } })); Error during runtime: Caused by: akka.actor

How to Cancel an Akka actor?

为君一笑 提交于 2019-12-10 09:40:29
问题 I have an akka actor(worker) that receives a request and replies to it. The request processing can take 3-60 minutes. Caller(also an actor) is currently using !!! and waiting on future.get, however the design of Caller actor can be changed if required. Also, I'm currently using EventDriven dispatcher. How do i Cancel(user initiated) the request processing so that the worker actor is freed up and returns to the ready state to receive new requests? I was hoping for a method similar to java.util