ivankelly commented on a change in pull request #526: ISSUE 525 Refactor 
PerChannelBookieClient
URL: https://github.com/apache/bookkeeper/pull/526#discussion_r142375948
 
 

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
 ##########
 @@ -980,163 +816,72 @@ private ChannelFuture closeChannel(Channel c) {
         return c.close();
     }
 
-    void errorStartTLS(int rc) {
-        failTLS(rc);
-    }
-
-    void errorOutReadKey(final CompletionKey key) {
-        errorOutReadKey(key, 
BKException.Code.BookieHandleNotAvailableException);
-    }
-
-    void errorOutReadKey(final CompletionKey key, final int rc) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Removing completion key: {}", key);
-        }
-        final ReadCompletion readCompletion = 
(ReadCompletion)completionObjects.remove(key);
-        if (null == readCompletion) {
+    private void writeAndFlush(final Channel channel,
+                               final CompletionKey key,
+                               final Object request) {
+        if (channel == null) {
+            errorOut(key);
             return;
         }
-        executor.submitOrdered(readCompletion.ledgerId, new SafeRunnable() {
-            @Override
-            public void safeRun() {
-                String bAddress = "null";
-                Channel c = channel;
-                if (c != null && c.remoteAddress() != null) {
-                    bAddress = c.remoteAddress().toString();
-                }
 
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Could not write request for reading entry: {} 
ledger-id: {} bookie: {} rc: {}",
-                            new Object[] { readCompletion.entryId, 
readCompletion.ledgerId, bAddress, rc });
-                }
-
-                readCompletion.cb.readEntryComplete(rc, 
readCompletion.ledgerId, readCompletion.entryId,
-                                                    null, readCompletion.ctx);
-            }
-
-            @Override
-            public String toString() {
-                return String.format("ErrorOutReadKey(%s)", key);
-            }
-        });
+        try{
+            channel.writeAndFlush(request)
+                .addListener(new ChannelFutureListener() {
+                        @Override
+                        public void operationComplete(ChannelFuture future)
+                                throws Exception {
+                            if (future.isSuccess()) {
+                                if (LOG.isDebugEnabled()) {
+                                    LOG.debug("Successfully wrote request {} 
to {}",
+                                              requestToString(request),
+                                              channel.remoteAddress());
+                                }
+                            } else {
+                                if (!(future.cause()
+                                      instanceof ClosedChannelException)) {
+                                    LOG.warn("Writing request {} to {} failed 
: ",
+                                             requestToString(request),
+                                             channel, future.cause());
+                                }
+                                errorOut(key);
+                            }
+                        }
+                    });
+        } catch(Throwable e) {
+            LOG.warn("Operation {} failed", requestToString(request), e);
+            errorOut(key);
+        }
     }
 
-    void errorOutWriteLacKey(final CompletionKey key) {
-        errorOutWriteLacKey(key, 
BKException.Code.BookieHandleNotAvailableException);
+    private String requestToString(Object request) {
 
 Review comment:
   regarding, #145 that's at a higher level, not PerChannelBookieClient, but 
PendingReadOp
 
----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to