我正在尝试将对象发送给远程actor,我得到了这个异常:
ERROR akka.remote.EndpointWriter - Transient association error (association remains live)
java.io.NotSerializableException: scala.collection.immutable.MapLike$$anon$2
Run Code Online (Sandbox Code Playgroud)
被序列化的对象是一个案例类:
case class LocationReport(idn: String, report: String, timestamp: Option[String], location: Attr, status: Attr, alarms: Attr, network: Attr, sensors: Attr) extends Message(idn) {
val ts = timestamp getOrElse location("fix_timestamp")
def json =
(report ->
("TIME" -> ts) ~
("location" -> location) ~
("alarms" -> alarms) ~
("network" -> network) ~
("sensors" -> ((status ++ sensors) + ("CUSTOMCLOCK" -> Report.decodeTimestamp(ts)))))
}
Run Code Online (Sandbox Code Playgroud)
并且Attr是一种类型重新定义:
type Attr = Map[String, String]
Run Code Online (Sandbox Code Playgroud)
这 …
我打电话的时候
System.err.println("Before")
System.err.flush()
val foo: Map[Int, T] = t mapValues (fn(_))
System.err.println(foo.head) //prevent optimiser from delaying the construction of 'foo'
System.err.println("After")
System.err.flush()
Run Code Online (Sandbox Code Playgroud)
与fn里面有一个调试打印语句,我得到这样的输出:
Before
...head item...
After
...debug print statement from fn...
...debug print statement from fn...
Run Code Online (Sandbox Code Playgroud)
我不明白为什么在打印"After"之后调用调试打印语句,我不明白为什么我得到它两次---除非mapValues创建一个懒惰的地图?