merlimat commented on a change in pull request #6362: [ClientAPI]Fix 
hasMessageAvailable()
URL: https://github.com/apache/pulsar/pull/6362#discussion_r381502751
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
 ##########
 @@ -1412,6 +1424,43 @@ protected void 
handleGetLastMessageId(CommandGetLastMessageId getLastMessageId)
         }
     }
 
+    private int getLargestBatchIndex(Topic topic, PositionImpl position, long 
requestId) {
+        PersistentTopic persistentTopic = (PersistentTopic) topic;
+        ManagedLedgerImpl ml = (ManagedLedgerImpl) 
persistentTopic.getManagedLedger();
+
+        CompletableFuture<Entry> entryFuture = new CompletableFuture<>();
+        ml.asyncReadEntry(position, new AsyncCallbacks.ReadEntryCallback() {
+            @Override
+            public void readEntryComplete(Entry entry, Object ctx) {
+                entryFuture.complete(entry);
+            }
+
+            @Override
+            public void readEntryFailed(ManagedLedgerException exception, 
Object ctx) {
+                entryFuture.completeExceptionally(exception);
+            }
+        }, null);
+
+        CompletableFuture<Integer> batchSizeFuture = 
entryFuture.thenApply(entry -> {
+            MessageMetadata metadata = 
Commands.parseMessageMetadata(entry.getDataBuffer());
+            int batchSize = metadata.getNumMessagesInBatch();
+            entry.release();
+            return batchSize;
+        });
+
+        try {
+            int batchSize =  batchSizeFuture.get();
 
 Review comment:
   This is being called within an IO thread. We cannot block on the future

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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