When are you suposed to call super on extended methods?

javadevmtl java.dev.mtl at gmail.com
Thu May 20 20:28:17 EDT 2010


In the documents, some methods it explicitly says to and in others it doesn't


1- So I'm overriding channelOpen and call supper is that ok?
2- I'm also overriding handleUpstream and handleDownstream which suggest
that I do call supper but where should I call it? I'm, using senUpstream and
sendDownstream as well as fire message received. When should supper be
called?

See my code below...

	@Override
	public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception
	{
		super.channelOpen(ctx, e);
		
		MyApp.allChannels.add(e.getChannel());
	}


	@Override
	// Convert the incoming string to POJO
	public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent ce)
throws Exception {
			
		if (!(ce instanceof MessageEvent)) {
			ctx.sendUpstream(ce);
			return;
		}

		MessageEvent me = (MessageEvent) ce;
		if (!(me.getMessage() instanceof String)) {
			ctx.sendUpstream(ce);
			return;
		}

		Channels.fireMessageReceived(ctx, decode((String) me.getMessage()));
	}

	// Convert outgoing message from POJO to Stlink style message
	@Override
	public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent ce)
throws Exception {

		
		if (!(ce instanceof MessageEvent)) {
			ctx.sendDownstream(ce);
			return;
		}

		MessageEvent messageEvent = (MessageEvent) ce;
		// Not the message we need to handle, send it back

		if (!(messageEvent.getMessage() instanceof TransactionResponseMessage)) {
			ctx.sendDownstream(ce);
			return;
		}

		String encodedMessage = encode((MyResponseObject)
messageEvent.getMessage());

		Channels.write(ctx, messageEvent.getFuture(), encodedMessage);

	}


-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/When-are-you-suposed-to-call-super-on-extended-methods-tp5082146p5082146.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list