开发者

How do I Serialize Collections for Remote Actors in Scala?

开发者 https://www.devze.com 2023-02-10 07:33 出处:网络
In Java all collections are serializable, but somehow I always get an exception when I want to send scala collections with remote actors. It always ends up in exceptions. It is important that the coll

In Java all collections are serializable, but somehow I always get an exception when I want to send scala collections with remote actors. 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 tha开发者_StackOverflow社区t 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消