Netty: How to make sure Channel.close() was fired by the I/O thread -


i using netty 3.6.2, here pipeline factory pseudocode:

private final static threadpoolexecutor executor = new orderedmemoryawarethreadpoolexecutor(8, 4194304, 4194304, 5l, timeunit.minutes); public channelpipeline getpipeline() throws exception {     channelpipeline p = pipeline();     p.addlast("framedecoder", protobufframedecoder);     p.addlast("protobufdecoder", protobufdecoder);     p.addlast("executor", new executionhandler(executor));     p.addlast("handler", handler);     p.addlast("frameencoder", protobufframeencoder);     p.addlast("protobufencoder", protobufencoder);     return p; } 

in way, handler's messagereceived() called in different thread pool instead of worker thread pool, want close channel in case exception happened in messagereceived(), according here: http://netty.io/wiki/thread-model.html,

any upstream events triggered side effect of downstream event must fired i/o thread.

simply call ctx.getchannel().close() not safe in exceptioncaught(), trying use way solve issue,

nettyserversocketfactory.getworkerexecutor().execute(new runnable() {    @override    public void run() {        channel.close();    } }); 

here nettyserversocketfactory code:

public class nettyserversocketfactory extends nioserversocketchannelfactory {  private static executor bossexecutor = executors.newcachedthreadpool(); private static executor workerexecutor = executors.newcachedthreadpool();  public static executor getbossexecutor() {     return bossexecutor; }  public static executor getworkerexecutor() {     return workerexecutor; }  public nettyserversocketfactory() {     super(bossexecutor, workerexecutor); } } 

but seems not work, advice appreciated.

channel#close() triggers downstream event ventually reach channelsink, event "handed over" worker associated channel further processing. worker fire channel closed event, , worker make sure event sent upstream on io thread.

this how works, maybe document referring discussing previous situation, event indeed delivered on calling thread.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -