score:1
when you schedule a message with
system.scheduler.scheduleonce(...)
a sender of that message is deadletters
which is what you are trying to send message to in
sender ! returninfluencemessage(source)
and it is also what error message says.
score:2
@martynas is correct in that your sender
ref will be the deadletter
ref when your code is setup the way it is. the main issue is that you send in a message from outside of the actor system (via the scheduler) and then when you use forward
, you continue to propagate the fact that you don't have a sender down into the next actor. you can remedy this by using a tell (!)
instead of forward. i have modified your code sample to show this (as well as some other changes described after the code sample):
import akka.actor._
import concurrent.duration._
sealed trait message
case class returninfluencemessage(source: actorref) extends message
case class setinfluences(source: actorref) extends message
case object getinfluence extends message
class listener extends actor {
def receive = {
case returninfluencemessage(s0urce) => println(s"listener: received influence ($s0urce)")
}
}
class entity extends actor {
val influences = context.actorof(props[influences], name = "influences")
def receive = {
case si @ setinfluences(s0urce) =>
influences ! si
case getinfluence =>
influences ! getinfluence
case rim @ returninfluencemessage(source) =>
source ! rim
}
}
class influences extends actor {
def receive = setinfluence
def setinfluence:receive = {
case setinfluences(s0urce) =>
println (s"influences: received $s0urce")
println (s"influences: influence set to $s0urce")
context.become(withsource(s0urce) orelse setinfluence)
}
def withsource(source:actorref):receive = {
case getinfluence =>
println (s"influences: influence sent to $source")
sender ! returninfluencemessage(source)
}
}
object main extends app {
val system = akka.actor.actorsystem("mysystem")
val abel = system.actorof(props[listener], name = "listener")
val cain = system.actorof(props[entity], name = "entity")
import system.dispatcher
system.scheduler.scheduleonce(1500 milliseconds, cain, setinfluences(abel))
system.scheduler.scheduleonce(3000 milliseconds, cain, getinfluence)
}
when i ran this i did not get any deadletters. other changes include:
- formatting (2 spaces for indents, correct casing for var/vals)
- changed
getinfluence
into a case object as it did not have any fields - used variable binding in the case statements to capture a ref to the message (via the
@
symbol) when we needed to send that message along - used a two state setup for the
influences
actor where it is first waiting for the state to be set (thesource
ref) and then switches to a state where it is able to respond properly to agetinfluences
message. probably want to explicitly handle agetinfluences
message when in the initial state as for now it's just an unhandled message. - got rid of the use of
children.foreach
as you already had a ref to the only child of that actor, so it seemed unnecessary to use this construct. i would use that construct if you had a variable amount of children to send to and in this example you don't.
Source: stackoverflow.com
Related Query
- Error with DeadLetters and ActorRef
- A binding to play.api.db.DBApi was already configured, evolutions and injector error with play-slick
- Cannot resolve symbol 'play' error with Play Framework 2.4.x and IntellijIdea 14.x
- Error with definition covariant and contravariant types
- Circular Dependency Error for Google Guice with Play2.4 and scala
- Error handling with Try match inside an udf - and log row where it failed
- Scala compilation error with Java parametrized constructor and parametrized interface
- Building a project with mixed Scala and Java source files using Ant - illegal cyclic reference error
- SQL syntax error with Derby and Circumflex ORM
- Compiler error on nested futures response with Play and ReactiveMongo
- Error with scala-2.8 and scalacheck: Prop has wrong version
- Error with sbt-assembly and Play Framework
- Scala and Playframework : what they mean with ExecutionException: Boxed Error
- Compile Error when killing topology from storm bolt programatically: object and package with same name
- Scala: compile error with wildcards (type parameters) and collections: "you may wish to investigate a wildcard type as"
- Error running ensime-source-buffer-loaded-hook - OSX with ENSIME and Emacs
- Using -= with incompatible types (Double and DenseVector) causes strange scala compiler error
- Scala Type Error with Traits and Generics
- Compile error using flatMap with Sets and type bounds
- Why is the Unresolved Dependencies error with SecureSocial and Play 2.3.2?
- Play form and GET request with parameter error
- Embedded Cassandra with Spark and DataStax Driver Error
- Explanation on the error with for comprehension and co-variance
- Scala instantiation error with libGdx and Gradle
- Error when working with AspectJ and Scala
- sbt-jacoco plugin does not work with Java11 and throws instrumenting class error
- flattening of nested json using spark scala creating 2 column with same name and giving error of duplicate in Phoenix
- Error while Executing Scala constructs with Spark 1.5.2 and Scala 2.11.7
- When I run tests with scalaTestPlus and Play framework, I get an error "no started application"
- Error with DeadLetters
More Query from same tag
- Elegant way to reverse a list using foldRight?
- scala - Can I overload curried methods?
- How to diagnose or detect deadlocks in Java static initializers
- How to maintain state after streaming application restart?
- Scala mkString except the last one
- Map column values to a a numeric type in spark
- Is it possible to create a Flow with Akka-stream that can switch between 2 different inner Shapes?
- Spray: Convert String/ByteString into HttpRequest (or similar)
- Getting resource path files from the context of a scala macro
- What is the |>> symbol in Scala
- how to keep return value when logging in scala
- java 8 Docker Improperly specified VM option 'InitialRAMPercentage=XX'
- Scala - handling initialization of objects (_ vs Option[T])
- EitherT: Call function returning Either only if a certain condition is true (otherwise return right)
- REST (Squeryl/Akka/Spray) - Very low throughput
- How to find exact and non-exact matches between two dataframes?
- Unable to get Ratings to work
- Locating Scala Array deep documentation?
- Iterate over dates range (the scala way)
- ZIO : How to compute only once?
- Compile error scala project
- FileUtils write method does not work on Azure Databricks
- Does Scala have an equivalent to C#'s Global Namespace Alias?
- Blocking Awaitable instances with Duration.Inf, best practice?
- Get individual model scores at every iteration / fold in k-fold validation
- How to chain multiple case expressions together in Scala
- Parsing xml causing match error with new line
- How to iterate array without for in scala?
- In Play 2.1, What to use instead of deprecated PushEnumerator
- Type erasure leads to missing parameter type for expanded function