merlimat commented on a change in pull request #1286: WIP - Implement directly 
ChannelOutboundHandlerAdapter in BookieProtoEncoding#ResponseEncoder
URL: https://github.com/apache/bookkeeper/pull/1286#discussion_r176585565
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieProtoEncoding.java
 ##########
 @@ -452,20 +454,24 @@ protected void decode(ChannelHandlerContext ctx, Object 
msg, List<Object> out) t
         }
 
         @Override
-        protected void encode(ChannelHandlerContext ctx, Object msg, 
List<Object> out)
-                throws Exception {
+        public void write(ChannelHandlerContext ctx, Object msg, 
ChannelPromise promise) throws Exception {
             if (LOG.isTraceEnabled()) {
                 LOG.trace("Encode response {} to channel {}.", msg, 
ctx.channel());
             }
             if (msg instanceof BookkeeperProtocol.Response) {
-                out.add(repV3.encode(msg, ctx.alloc()));
+                ctx.write(repV3.encode(msg, ctx.alloc()), promise);
             } else if (msg instanceof BookieProtocol.Response) {
-                out.add(repPreV3.encode(msg, ctx.alloc()));
+                ctx.write(repPreV3.encode(msg, ctx.alloc()), promise);
             } else {
                 LOG.error("Invalid response to encode to {}: {}", 
ctx.channel(), msg.getClass().getName());
-                out.add(msg);
+                ctx.write(msg, promise);
             }
         }
+
+        @Override
+        public void exceptionCaught(ChannelHandlerContext ctx, Throwable 
cause) throws Exception {
+            LOG.error("Generic error while encoding response", cause);
+        }
 
 Review comment:
   I think this exception handler will be invoked in addition to the one we 
have already on the main handler.
   Also, the exception here might not necessarely related to the encoder, but 
the `exceptionCaught()` is invoked for any exception that happens in the IO 
thread when serving this connection.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to