Writing a ChannelBuffer to a Netty Channel throws java.io.NotSerializableException -


i want write raw bytes netty channel. thought first creating channelbuffer, filling bytes (coming from, say, kryo serializer), , writing channelbuffer netty channel.

here relevant code, i'm filling bytes channelbuffer in ctor , trying send upon connection:

/**  * handler implementation object echo client.  initiates  * ping-pong traffic between object echo client , server sending  * first message server.  */ public class objectechoclienthandler extends simplechannelupstreamhandler {  private final channelbuffer firstmessage;  /**  * creates client-side handler.  */ public objectechoclienthandler(int firstmessagesize) {     if (firstmessagesize <= 0) {         throw new illegalargumentexception(                 "firstmessagesize: " + firstmessagesize);     }     firstmessage = channelbuffers.buffer(8192);     (int = 0; < firstmessagesize; i++) {         firstmessage.writebyte(i % 256);     } }  @override public void channelconnected(         channelhandlercontext ctx, channelstateevent e) {      // send first message if handler client-side handler.     // e.getchannel().write(firstmessage);     channels.write(ctx, e.getfuture(), firstmessage); }  } 

this doesn't seem work, throws exception:

java.io.notserializableexception: org.jboss.netty.buffer.bigendianheapchannelbuffer @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1164) @ java.io.objectoutputstream.writeobject(objectoutputstream.java:330) @ org.jboss.netty.handler.codec.serialization.objectencoder.encode(objectencoder.java:80) @ org.jboss.netty.handler.codec.oneone.onetooneencoder.handledownstream(onetooneencoder.java:61) @ org.jboss.netty.channel.channels.write(channels.java:626) @ org.jboss.netty.channel.channels.write(channels.java:587) @ ca.gsimard.spacecraft.client.objectechoclienthandler.channelconnected(objectechoclienthandler.java:83) @ ca.gsimard.spacecraft.client.objectechoclienthandler.handleupstream(objectechoclienthandler.java:75) @ org.jboss.netty.channel.channels.firechannelconnected(channels.java:227) @ org.jboss.netty.channel.socket.nio.nioworker$registertask.run(nioworker.java:784) @ org.jboss.netty.channel.socket.nio.nioworker.processregistertaskqueue(nioworker.java:250) @ org.jboss.netty.channel.socket.nio.nioworker.run(nioworker.java:192) @ java.util.concurrent.threadpoolexecutor$worker.runtask(threadpoolexecutor.java:886) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:908) @ java.lang.thread.run(thread.java:662) 

i'm sure dead trivial , wrong way of doing it, because can't seem find had same error this. i'm using netty 3.3.0 right now.

i can work creating sized byte[] , copying contents of channelbuffer it, have liked more direct solution avoids useless byte copying.

    byte[] array = new byte[firstmessage.writerindex()];     firstmessage.readbytes(array);     e.getchannel().write(array); 

thanks pointers !

looking @ stack trace, observed these 2 lines:

at org.jboss.netty.handler.codec.serialization.objectencoder.encode(objectencoder.java:80) @ org.jboss.netty.handler.codec.oneone.onetooneencoder.handledownstream(onetooneencoder.java:61 

what means me pipeline contains objectencoder attempting serialize channelbuffer. since objects have been encoded kryo, don't need objectencoder.

or put differently (without kryo), channelbuffer should output of objectencoder , object should input.

your best bet write new channelhandler uses kryo encode objects. may find added efficiencies when kryo it's job handler in netty pipeline.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -