Java, Netty: Help Understanding ChannelPipelines and addLast -



Java, Netty: Help Understanding ChannelPipelines and addLast -

i working through some examples of using netty io server. working on understanding pipeline construct, , how elements added pipeline effect each other, , how order of import in pipeline. far have created kid handler follows in main method

serverbootstrap.childhandler(new channelinitializer<socketchannel>() { @override protected void initchannel(socketchannel socketchannel) throws exception { channelpipeline pipeline = socketchannel.pipeline().addlast( ... ); } }

i want have pipeline 1 handler generates long system.currenttimemillis() , handler encodes string in format provided date classes tostring method. end started this:

channelpipeline pipeline = socketchannel.pipeline().addlast( new channelinboundhandleradapter() { @override public void channelactive(final channelhandlercontext channelhandlercontext) { byte[] bytes = "press homecoming time\n".getbytes(); channelhandlercontext.writeandflush( channelhandlercontext .alloc() .buffer(bytes.length) .writebytes(bytes)); } @override public void channelread(final channelhandlercontext channelhandlercontext, object object) { seek { channelfuture channelfuture = channelhandlercontext.writeandflush( channelhandlercontext .alloc() .buffer() .writelong(system.currenttimemillis())); channelfuture.addlistener(channelfuturelistener.close); } { referencecountutil.release(object); } } @override public void exceptioncaught(channelhandlercontext channelhandlercontext, throwable throwable) { throwable.printstacktrace(); channelhandlercontext.close(); } } );

how modify encoder encodes payload date string such 2014-10-07t18:34:10.897-00:00? right way think pipeline, though trivial example?

in terms of understanding, looking @ example, unclear how order of pipeline executed. example, if assume execute in linear order, thing info payload gzipped , ungzipped. missing?

pipeline.addlast(zlibcodecfactory.newzlibencoder(zlibwrapper.gzip)); pipeline.addlast(zlibcodecfactory.newzlibdecoder(zlibwrapper.gzip)); // add together number codec first, pipeline.addlast(new bigintegerdecoder()); pipeline.addlast(new numberencoder()); // , business logic. // please note create handler every new channel // because has stateful properties. pipeline.addlast(new factorialserverhandler());

update: found this diagram still trying work out how coerce long in illustration above date on way client. how that?

java netty

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -