Structured message reading problem in Netty.

manishr22 manishr22 at gmail.com
Fri May 1 01:51:06 EDT 2009


Hi Frederic,

I understand :). It seems there is still some problem in mailing group, To
me it still showing my message is not yet deilvered. so i deleted the
previous one and added new. :)


I am not doing anything unusual in my handler, i got the point that my
handler is giving DISCONNECTED and UNBOUND, this is the reason my server is
not receiving any further messages.

But what could be the possible reason for this.

For your convenience, my handler class is like 

@ChannelPipelineCoverage("all")
public class LoggingAgentTCPNettyHandler extends SimpleChannelHandler {
@Override
	public void channelBound(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		idn++;
	}

	@Override
	public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
			throws Exception {

		// Log all channel state changes.
		if (e instanceof MessageEvent) {
			logger.info("Writing:: " + e);
		}

		super.handleDownstream(ctx, e);
	}

	@Override
	public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
			throws Exception {
		if (e instanceof ChannelStateEvent) {
			logger.info("HANDLE UPSTREAM " + e.toString());
		}

		// Let SimpleChannelHandler call actual event handler methods below.
		super.handleUpstream(ctx, e);
	}

@Override
	public void messageReceived(ChannelHandlerContext ctx,
			MessageEvent messageEvent) {
 if (messageEvent.getMessage() instanceof BufferData) {
		 buffData = (BufferData) messageEvent.getMessage();
		 }
		 len = buffData.getBodyLegth();
		 header = buffData.getHeaderLength();
		 ChannelBuffer buff = buffData.getBuffer();

....
...
..
}
@Override
	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
		// Close the connection when an exception is raised.
		logger.error("Unexpected exception from downstream." + e.getCause());
		// e.getChannel().close();
	}





}


Frederic Bregier wrote:
> 
> Hi Manish,
> 
> I don't know if it is an accident or not, but posting twice the same
> answer
> will not give you an answer faster... ;-)
> 
> From your code, I see the following:
> - Your decoder is unique for each channel, so ok.
>   @ChannelPipelineCoverage("one") is appropriate.
> 
> - You business handler (this.handler) is shared across all connections.
>   If this is intend then it is ok. The meaning is that every private
> variable
>   of this handler will be shared across all channels. But if you do not
> have
>   any shared variables, then it is perfectly ok.
>   Therefore @ChannelPipelineCoverage("all") should be appropriate for this
> handler
>   only. Note again that the @ChannelPipelineCoverage(xxx) is just a tips
> for
>   the reader of the code right now, nothing is done by Netty with this for
> the moment.
> 
> - The info you get (DISCONNECTED and UNBOUND) seem to say that your
> handler
>   (this.handler) close the connection after the first message.
>   Maybe you cannot have a second message because your handler
> (this.handler)
>   is just behaving like this ?
> 
> - Your LoggingAgentMessageDecoder seems ok to me with ReplayingDecoder.
>   If you wanted to use FrameDecoder, you will have to check the available
> bytes
>   which is done for you by the ReplayingDecoder.
> 
> HTH,
> Frederic
> 
> 

-- 
View this message in context: http://n2.nabble.com/Structured-message-reading-problem-in-Netty.-tp2682454p2751886.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list