Separating handlers
Vadim Berezniker
kryptolus at gmail.com
Mon Apr 12 18:17:52 EDT 2010
I'm implementing a client for an existing proprietary binary protocol that's
pretty simple. You open a TCP/IP connection, do a handshake and after that
you can send many requests and get a response for each request.
I have my handlers set up like this
ClientHandler => ProtocolHandler
The protocol handler converts between objects and the underlying binary
protocol.
The ClientHandler takes care of the handshake when the channel is opened.
What's the proper way to send a new request downstream? It seems in this
case the client (that initialized the pipeline) has to write a message to
the channel and then wait for a response using the ClientHandler. That seems
a little inconsistent.
It would look like something like this:
channel.write(new SomeRequest());
clientHandler.getResponse(); // will block until response is received
In ClientHandler I would have something like:
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
throws Exception
{
<record information about the request so it can be looked up by
getResponse>
super.writeRequested(ctx, e);
}
public Response getResponse()
{
<wait for response>
}
I feel like I'm off course. Is there a better way?
--
View this message in context: http://n2.nabble.com/Separating-handlers-tp4893026p4893026.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list