简体   繁体   English

如何在Scala中序列化远程角色的集合?

[英]How do I Serialize Collections for Remote Actors in Scala?

In Java all collections are serializable, but somehow I always get an exception when I want to send scala collections with remote actors. 在Java中,所有集合都是可序列化的,但是当我想与远程参与者发送scala集合时,总是会出现异常。 It always ends up in exceptions. 它总是以异常结束。 It is important that the collection is mutable and has random access 集合可变且具有随机访问权限很重要

[error] scala.actors.remote.DelegateActor@5090d8ea: caught java.io.NotSerializableException: scala.collection.mutable.ArraySeq
[error] java.io.NotSerializableException: scala.collection.mutable.ArraySeq
[error]     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
[error]     at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
[error]     at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
[error]     at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
[error]     at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)

The collection is nested into another class that is then send over the network 集合被嵌套到另一个类中,然后通过网络发送

@serializable
class NetworkSendable[A]{
    val data = new collection.mutalbe.ArraySeq[A](10)
}

They are not defined for serialization, so you probably have to wrap them in a different structure and unwrap them on arrival. 它们不是为序列化定义的,因此您可能必须将它们包装为不同的结构,并在到达时将其解包。

Other alternative is to customize your serialization mechanism, but that might be error prone. 另一种选择是自定义序列化机制,但这可能容易出错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM