May I upstream self-created messages?

Daniel Ferber dffforum at gmail.com
Tue Aug 24 10:37:47 EDT 2010


I have implemented a ByteCounterHandler (extends
SimpleChannelUpstreamHandler) that is the first handler in my pipeline. As
the name of the handler states, it sums the length of received messages. 

When the channel disconnects, I want to notify the business handler on the
top of the pipeline about the sum of received bytes, for billing purposes.

After reading the docs, I understand that believe I should override the
channelDisconnected() method to fire a self-created MessageReceived event up
the pipeline (to the business handler)? Or is another approach recommended?
I am new to Netty so I am not feeling secure about how to design this.

Like:
public class ByteCounter extends SimpleChannelUpstreamHandler {
  public void channelDisconnected(ChannelHandlerContext ctx,
ChannelStateEvent e) {
    Integer sum = (Integer) ctx.getAttachment();
    Channels.fireMessageReceived(ctx, sum);
    super.channelDisconnected(ctx, e);
  }
}

-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/May-I-upstream-self-created-messages-tp5457151p5457151.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list