akka

Using future callback inside akka actor

喜夏-厌秋 提交于 2021-02-06 15:27:04
问题 I've found in Akka docs: When using future callbacks, such as onComplete, onSuccess, and onFailure, inside actors you need to carefully avoid closing over the containing actor’s reference, i.e. do not call methods or access mutable state on the enclosing actor from within the callback. So does it mean that i should always use future pipeTo self and then call some functions? Or i can still use callbacks with method, then how should i avoid concurrency bugs? 回答1: It means this: class

How to send a message to an actor's parent in Akka Classic?

混江龙づ霸主 提交于 2021-02-06 09:40:33
问题 What is the method for an actor to send a message to its parent? I'm using Akka 2.2 回答1: You are looking for getContext().parent() which gives you the ActorRef of the parent, so you can do getContext().parent().tell(...) 回答2: With Akka 2.4, you have to do context.parent inside an actor to have its parent actor reference. After that, you can send it a message as before ( context.parent ! "hello" ). 回答3: It should be noted, e.g. for anybody who comes to this question through a search, that Akka

FSM vs become/unbecome in Akka

五迷三道 提交于 2021-02-05 19:59:39
问题 Akka provides two somewhat overlapping ways to manage actor states, Finite State Machines and unbecome/become. What are their respective benefits/drawbacks? When should one of them be chosen over the other? 回答1: FSM is a DSL that allows you to build more sophisticated, readable state machines than would be possible using the core actor API. You could potentially show the FSM code to a business person and they could validate the business rules. The FSM DSL allows you to compose things together

One of the example projects listed by Lightbend is not working for larger files

不问归期 提交于 2021-01-28 21:54:29
问题 I did post this same question at LightBend's discussion group here, but cannot get an answer that solves my issue. Since I am really anxious to know what is the problem here, let me again post this question here, hoping a big audience group might mean a better chance of getting an answer. So basically, at this page, https://developer.lightbend.com/start/?group=play, we can find a list of example Play! projects. Among these examples, there is one project is about Java File Upload (https:/

Passing Contextual Information

强颜欢笑 提交于 2021-01-28 14:41:36
问题 We are in the process of adding akka.net actors to part of a legacy system. The basic idea is that a message comes in from an external system, it is handed off to a logic that is managed by akka.net actors which then talk to legacy components that do things like save data to the database. The legacy code relies on the fact that a userId is set in the CallContext, which it can then retrieve before doing database writes (to store things like "CreatedBy" and "LastModifiedBy"). It seems clear

Why do I have to pass new keyword?

旧时模样 提交于 2021-01-28 08:35:13
问题 I have the following code: val fsm = TestFSMRef(new SenderCollectorFsm) And do not understand, why do I have to pass to TestFSMRef an instance. Lets look at the definition of TestFSMRef: object TestFSMRef { def apply[S, D, T <: Actor: ClassTag]( factory: => T)(implicit ev: T <:< FSM[S, D], system: ActorSystem): TestFSMRef[S, D, T] = { val impl = system.asInstanceOf[ActorSystemImpl] new TestFSMRef(impl, Props(factory), impl.guardian.asInstanceOf[InternalActorRef], TestActorRef.randomName) } T

How to make recursive calls within Behaviors.receive?

纵饮孤独 提交于 2021-01-28 04:12:50
问题 This code is from akka documentation. It impelements an actor using the recommended functional style: import akka.actor.typed.Behavior import akka.actor.typed.scaladsl.ActorContext import akka.actor.typed.scaladsl.Behaviors object Counter { sealed trait Command case object Increment extends Command final case class GetValue(replyTo: ActorRef[Value]) extends Command final case class Value(n: Int) def apply(): Behavior[Command] = counter(0) private def counter(n: Int): Behavior[Command] =

Reverse HList and convert to class?

喜你入骨 提交于 2021-01-27 11:33:12
问题 I'm using Shapeless to accumulate materialized values in Akka as an HList and convert that to a case class. (You don't have to know Akka much for this question, but the default approach accumulates materialized values as recursively nested 2-tuples, which isn't much fun, so Shapeless HLists seemed a more sensible approach -- and works pretty well. But I don't know how to properly re-use that approach. Here, I'll simplify the kinds of values Akka produces.) For example, let's say we've got two

Execution Context and Dispatcher - Best practices, useful configurations and Documentation

半腔热情 提交于 2021-01-20 14:29:10
问题 Scala Execution Context and Dispatchers - Listing and comparison: Why ? There are a lot of questions around what/how/what is the best Execution Context to use to execute futures on in Scala and how to configure the dispatcher. Still I never was able to find a longer list with pros and cons and configuration examples. The best I could find was in the Akka Documentation: http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html and Play Documentation https://www.playframework.com

How to increase default timeout for ScalaTestWithActorTestKit

时光总嘲笑我的痴心妄想 提交于 2021-01-07 02:42:20
问题 I have a test which constructs another event sourcing actor from inside message handler and this construction is taking more than 3 seconds. Below is current configuration, how can I increase default timeout? extends ScalaTestWithActorTestKit( ConfigFactory.parseString(""" akka.persistence.testkit.events.serialize = off akka.actor.allow-java-serialization = on akka.test.single-expect-default = 999s """).withFallback(PersistenceTestKitPlugin.config).withFallback(ManualTime.config) Here is the