Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

netty4 - Replacement for ChannelEvent and CustomEvent in Netty 4

I am working on upgrading an Netty3 application to Netty4. The application currently uses custom events by extending the ChannelEvent class and I am not sure how to translates this to Netty 4 because ChannelEvent seem to have been gone in Netty4, and unlike in Netty3, in Netty 4, there is no handler method that receives a channel event.

The current code in Netty 3 looks like this:

A custom event is defined:

public class CustomEvent implements ChannelEvent {}

and in some handler down the line, there is some code that uses the event. For example:

public class AppHandler extends SimpleChannelDownstreamHandler {

@Override
public void handleDownstream(ChannelHandlerContext context, ChannelEvent event) {
  event.getChannel().write(new CustomEvent(...))
  context.sendDownstream(event)

}

}

How can this be translated to Netty 4? Not just the custom event part but also the context.sendDownstream(event) method call as this is no longer in Netty 4 also.

question from:https://stackoverflow.com/questions/65935307/replacement-for-channelevent-and-customevent-in-netty-4

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

so either you could use the write method and just write it there and then in your ChannelOutboundHandler you can check for it or maybe you can also use fireUserEvent. Not sure what is a better fit for your use case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...