Netty server with MySql database backend, how to do it right?

Frederic Bregier fredbregier at free.fr
Tue Apr 21 16:30:14 EDT 2009


Hi again,

Like in the other post, I forgot one point :

ServerPipelineFactory.java
<code>
   public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = pipeline();
        pipeline.addLast("cmdDecoder", new MyCommandDecoder());
        pipeline.addLast("stringEncoder", new StringEncoder("UTF-8"));
        MyHandlerObj handler = new ServerHandlerObj();
        pipeline.addLast("handler", handler);
        return pipeline;
    }
</code> 
You could make static the StringEncoder since it is a stateless encoder (as
in "all" pipeline). In contrary, MyCommandDecoder (and ServerHandlerObj if
you follow me) is statefull so you need to your pipeline unique for each
channel (as in "one" pipeline).
So it could be as the following:

@ChannelPipelineCoverage("one")
ServerPipelineFactory.java
<code>
   static private final StringEncoder stringEncoder = new
StringEncoder("UTF-8");
   public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = pipeline();
        pipeline.addLast("cmdDecoder", new MyCommandDecoder());
        pipeline.addLast("stringEncoder", stringEncoder);
        pipeline.addLast("handler", new ServerHandlerObj());
        return pipeline;
    }
</code> 

HTH,
Frederic

-----
Hardware/Software Architect
-- 
View this message in context: http://n2.nabble.com/Netty-server-with-MySql-database-backend%2C-how-to-do-it-right--tp2668426p2672370.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list