0

Netty(バージョン3.6.1.final)を現在のシステムに統合して、現在のNIOコードを置き換えることができるようにしようとしています。

現在、他のリスナーが処理するためにイベントがキューに入れられ、さらに処理するために別のイベントをバスに戻すメッセージングバスがあります。

Nettyビジネスロジックハン​​ドラーのmessageReceived()メソッドで、バスに入力要求を追加します。私が渡すことの1つは、Nettyイベントメッセージからのデータです。

受信したデータ/メッセージとともに、このInputEventでChannelHandlerContextを渡す必要があると思います。そのため、最終的にOutputEventが処理されるときに、最初に渡されたChannelHandlerContextを使用して、処理されたデータを正しいNettyチャネル上の要求元のクライアントに送り返すことができます。

では、OutputEventを処理しているOutputタスクをNettyにどのように結び付けることができるでしょうか。

処理されたデータを入力として使用しているChannelHandlerContextを使用して呼び出しを発行しますか?出力タスクを拘束したくありません。

Nettyハンドラーからのコードスニペット。

public void messageReceived(
        ChannelHandlerContext ctx, MessageEvent e) {

    byte[] message = (byte[])e.getMessage();

    try {
            data.add(message);
        }
    catch( IOException ioe )
        {
            logger.error(ioe);
        }

    InputEvent ie = new InputEvent( ctx, this, data.getBuffer() );

    try {
              bus.enqueue(ie);
    }
    catch( Exception ex )
   {
      logger.error(ex);
   }

出力プロセッサからのコードスニペット。

public void run() {


    // note that the OutputEvent (event) is available here.  This is not a Netty event.
    ChannelHandlerContext ctx = event.getHandlerContext();
    ClientChannel handler = event.getHandler();

    // I need to send the data in event.getBuffer() back.

// Now what do I do here???


…
…
…

}

ありがとうございました。

4

2 に答える 2

1

次のように呼び出します。

InputEvent event = ...
ChannelHandlerContext ctx = ....
ctx.write(event.getBuffer());

または:

InputEvent event = ...
Channel channel = ....
channel.write(event.getBuffer());
于 2013-01-16T06:48:59.997 に答える
0
    // Make a new connection.
    ChannelFuture connectFuture =
        bootstrap.connect(new InetSocketAddress(host, port));

    // Wait until the connection is made successfully.
    Channel channel = connectFuture.awaitUninterruptibly().getChannel();

    // Get the handler instance to retrieve the answer.
    FactorialClientHandler handler =
        (FactorialClientHandler) channel.getPipeline().getLast();//get("your handler name")
于 2013-02-01T02:45:33.473 に答える