I'm setting up a client connection using OioClientSocketChannelFactory and a pipeline like this:
ClientBootstrap bootstrap = new ClientBootstrap(
new OioClientSocketChannelFactory(Executors.newCachedThreadPool())
);
pipeline.addLast("encoder", new MessageEncoder());
pipeline.addLast("decoder", new MessageDecoder());
pipeline.addLast("manager", new FooClientManager());
BlockingReadHandler<Message> reader = new BlockingReadHandler<Message>();
pipeline.addLast("reader", reader);
bootstrap.setPipeline(pipeline);
The FooClientManager class (a SimpleChannelHandler) sends a handshake message on connect (SimpleChannelHandler.channelConnected), and has the responsibility of consuming the handshake reply (SimpleChannelHandler.messageReceived) from the server without passing it up the pipeline. I don't want the user of the API receiving certain low level messages, which is FooClientManager's responsibility to consume.
It is expected that after connecting, the user of the API would now construct a message and call channel.write() to send the message, and reader.read() to block awaiting a reply.
The problem I'm having is FooClientManager did not see the handshake reply before the user of the API called channel.write(), because a read() was never performed.
If I call reader.read() before calling channel.write(), it blocks indefinitely, because FooClientManager doesn't send the message I'm trying to read up the pipeline.
What is the best way to deal with blocking client IO and a channel handler in the pipeline that may consume messages?