Reputation: 1824
I have a ChannelOutboundHandlerAdapter
which overrides method write
. What are the differences between calling parent class write
method:
public class MyChannelOutboundHandler extends ChannelOutboundHandlerAdapter {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
//some code
super.write(ctx, anotherMessage, promise);
}
}
and calling context write
?:
public class MyChannelOutboundHandler extends ChannelOutboundHandlerAdapter {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
//some code
ctx.write(anotherMessage);
}
}
Upvotes: 0
Views: 721
Reputation: 2650
You can check the source code of the ChannelOutboundHandlerAdapter#write
to determine this. It is calling a write on context passing both message and promise:
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ctx.write(msg, promise);
}
So first evident difference is promise
not being passed to context.
The difference in the long term will be:
super
method you are decorating write method. You should do this when you want to add some additional behavior to standard one. Then if later ChannelOutboundHandlerAdapter
source will change your class will still be just adding functionality around it.ChannelHandlerContext
directly you are replacing original implementation. So it will be completely independent of base class method changes.Upvotes: 1