私はnettyを使いすぎていません。ChannelPipelineのドキュメントについて質問があります。ここでは、それは正確に約あるものです:ビジネスロジックでnettyを使用
static final EventExecutorGroup group = new DefaultEventExecutorGroup(16);
...
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("decoder", new MyProtocolDecoder());
pipeline.addLast("encoder", new MyProtocolEncoder());
// Tell the pipeline to run MyBusinessLogicHandler's event handler methods
// in a different thread than an I/O thread so that the I/O thread is not blocked by
// a time-consuming task.
// If your business logic is fully asynchronous or finished very quickly, you don't
// need to specify a group.
pipeline.addLast(group, "handler", new MyBusinessLogicHandler());
私はかなりMyBusinessLogicHandler
クラスを理解していません。それはDuplexChannelHandler
または別の何かを実装する必要がありますか?
public class Packet{}
は、私はいくつかのPacket
生成MyBusinessLogicHandler
に与え、Packet
にいくつかのバイトシーケンスをデコードします:たとえば、私の特定のケースでは、私は以下のクラスを持っています。それを再びバイトストリームにエンコードしてクライアントに送り返します。私は現在次のように表示しています:
public class MyBusinessLogicHandler extends SimpleChannelInboundHandler<MyModel>{
public void channelRead0(ChannelHandlerContext ctx, Packet msg){
Packet rslt = null;
//Do some complicated business logic
ctx.write(rslt);
}
}
これは一般的な方法であるかどうかはわかりません。どうぞお分かりですか?
ありがとうございました!ありがとう。 –