Serialization of Netty objects

361 views
Skip to first unread message

Tsume

unread,
Oct 3, 2013, 9:09:14 AM10/3/13
to ne...@googlegroups.com
Hi,

I'm using Socko, an Akka based webserver which uses Netty for networking. My issue is stated here as well, but I will explain it here for everyone.
I'm using Eventsourced to log Socko WebSocketFrameEvent's so I can recover them in case an actor fails. When I try to pass a message to log a Socko WebSocketFrameEvent I get an error stating :

[ERROR] [09/24/2013 20:35:04.124] [WebSocketExampleActorSystem-akka.actor.default-dispatcher-3] [akka://WebSocketExampleActorSystem/user/$a] org.jboss.netty.channel.socket.nio.NioAcceptedSocketChannel 

I'll post the whole error  at the end. It was pointed out that the Netty NioAcceptedSocketChannel  is not serialazable. I then came across this package for netty to make object serializable. In Akka there are certain ways to make objects serializable, but I'm unsure of how to integrate the Netty package into my Akka system. I first tried to do it with the config file but my application was giving an error saying it could not use the Netty serialization package. I then tried to do it programmatically but I was unable to follow the Netty API. I would prefer to do the Netty serialization through the config file, I included my build.sbt file & application.conf. If no one has a clue on how to do it through the configuration files, could someone show me an example of how I would do it programmatically.



[info] [ERROR] [09/24/2013 20:35:04.124] [WebSocketExampleActorSystem-akka.actor.default-dispatcher-3] [akka://WebSocketExampleActorSystem/user/$a] org.jboss.netty.channel.socket.nio.NioAcceptedSocketChannel
[info] java.io.NotSerializableException: org.jboss.netty.channel.socket.nio.NioAcceptedSocketChannel
[info]  at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
[info]  at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
[info]  at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
[info]  at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
[info]  at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
[info]  at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
[info]  at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply$mcV$sp(Serializer.scala:129)
[info]  at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply(Serializer.scala:129)
[info]  at akka.serialization.JavaSerializer$$anonfun$toBinary$1.apply(Serializer.scala:129)
[info]  at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
[info]  at akka.serialization.JavaSerializer.toBinary(Serializer.scala:129)
[info]  at org.eligosource.eventsourced.journal.common.serialization.MessageSerialization.messageProtocolBuilder(MessageSerialization.scala:86)
[info]  at org.eligosource.eventsourced.journal.common.serialization.MessageSerialization.serializeMessage(MessageSerialization.scala:71)
[info]  at org.eligosource.eventsourced.journal.leveldb.LeveldbJournalPS.msgToBytes(LeveldbJournalPS.scala:51)
[info]  at org.eligosource.eventsourced.journal.leveldb.LeveldbJournalPS$$anonfun$executeWriteInMsg$1.apply(LeveldbJournalPS.scala:57)
[info]  at org.eligosource.eventsourced.journal.leveldb.LeveldbJournalPS$$anonfun$executeWriteInMsg$1.apply(LeveldbJournalPS.scala:54)
[info]  at org.eligosource.eventsourced.journal.leveldb.LeveldbJournalPS.withBatch(LeveldbJournalPS.scala:152)
[info]  at org.eligosource.eventsourced.journal.leveldb.LeveldbJournalPS.executeWriteInMsg(LeveldbJournalPS.scala:54)
[info]  at org.eligosource.eventsourced.journal.common.support.SynchronousWriteReplaySupport$$anonfun$receive$1.applyOrElse(SynchronousWriteReplaySupport.scala:39)
[info]  at akka.actor.ActorCell.receiveMessage(ActorCell.scala:498)
[info]  at akka.actor.ActorCell.invoke(ActorCell.scala:456)
[info]  at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237)
[info]  at akka.dispatch.Mailbox.run(Mailbox.scala:219)
[info]  at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
[info]  at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262)
[info]  at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
[info]  at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
[info]  at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
[info] 
[info] 20:35:23.804 [New I/O worker #1] DEBUG o.m.socko.webserver.RequestHandler - WS EndPoint(GET,127.0.0.1:8888,/websocket?) CHANNEL=-746091765 
application.conf
build.sbt

Rajiv Kurian

unread,
Oct 5, 2013, 12:20:38 PM10/5/13
to ne...@googlegroups.com
The package you pointed to converts serializable objects to byte buffers and vice versa. If NIOSocketChannel is not serializable then this package can't help you. Also Akka serialization deals with byte arrays and not byte buffers. What would it even mean to serialize and deserialize a socket channel? It would lose it's meaning between the two operations IMO.
I am guessing you are more interested in serializing the contents of the web socket frame. In that case you should write a custom Akka serializer that takes in a web socket frame object and only returns the actual data as a byte array. You'll have to consult the socko documentation to figure out how the class works so that you can extract the data out. Also consult the Akka documentation on custom serializers to write custom serializer.

Vibul Imtarnasan

unread,
Oct 7, 2013, 7:31:36 PM10/7/13
to ne...@googlegroups.com
Hi,

You can get the data from the web socket frame event readBinary or readText method.

Regards
Vibul
Reply all
Reply to author
Forward
0 new messages