0

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.

Finlay Weber
  • 2,989
  • 3
  • 17
  • 37

1 Answers1

0

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.

Norman Maurer
  • 23,104
  • 2
  • 33
  • 31
  • sorry, not sure I follow. "so either you could use the write method and just write it there" ... by "write it there" what do you mean? "you can check for it " also by "check for it" how do you mean? where to check? Sorry if I am asking to much maybe some code snippet to go along with your answer will help. Thanks :) – Finlay Weber Jan 28 '21 at 10:56
  • Basically each "event" now has its own explicit method that you can call and all that you can override in the handler. You may want to read https://netty.io/wiki/new-and-noteworthy-in-4.0.html – Norman Maurer Jan 28 '21 at 11:07