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. 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.
精彩评论