|
24 | 24 | import io.netty.channel.ChannelHandlerContext; |
25 | 25 | import io.netty.channel.ChannelPromise; |
26 | 26 | import java.util.ArrayList; |
| 27 | +import java.util.Collection; |
27 | 28 | import java.util.List; |
28 | 29 | import java.util.Optional; |
29 | 30 | import java.util.concurrent.CompletableFuture; |
30 | | -import java.util.function.Consumer; |
| 31 | +import java.util.function.Function; |
31 | 32 | import lombok.extern.slf4j.Slf4j; |
32 | 33 | import org.apache.bookkeeper.mledger.Entry; |
33 | 34 | import org.apache.pulsar.broker.intercept.BrokerInterceptor; |
@@ -129,7 +130,9 @@ public void sendSendError(long producerId, long sequenceId, ServerError error, S |
129 | 130 | @Override |
130 | 131 | public CompletableFuture<Void> sendGetTopicsOfNamespaceResponse(List<String> topics, String topicsHash, |
131 | 132 | boolean filtered, boolean changed, long requestId, |
132 | | - Consumer<Throwable> permitAcquireErrorHandler) { |
| 133 | + Function<Throwable, |
| 134 | + CompletableFuture<Void>> |
| 135 | + permitAcquireErrorHandler) { |
133 | 136 | BaseCommand command = Commands.newGetTopicsOfNamespaceResponseCommand(topics, topicsHash, |
134 | 137 | filtered, changed, requestId); |
135 | 138 | safeIntercept(command, cnx); |
@@ -366,27 +369,32 @@ public void sendEndTxnErrorResponse(long requestId, TxnID txnID, ServerError err |
366 | 369 |
|
367 | 370 | /*** |
368 | 371 | * @param topics topic names which are matching, the topic name contains the partition suffix. |
| 372 | + * @return a CompletableFuture<Void> that completes when the operation finishes |
369 | 373 | */ |
370 | 374 | @Override |
371 | | - public void sendWatchTopicListSuccess(long requestId, long watcherId, String topicsHash, List<String> topics) { |
| 375 | + public CompletableFuture<Void> sendWatchTopicListSuccess(long requestId, long watcherId, String topicsHash, |
| 376 | + Collection<String> topics, |
| 377 | + Function<Throwable, CompletableFuture<Void>> |
| 378 | + permitAcquireErrorHandler) { |
372 | 379 | BaseCommand command = Commands.newWatchTopicListSuccess(requestId, watcherId, topicsHash, topics); |
373 | | - interceptAndWriteCommand(command); |
| 380 | + safeIntercept(command, cnx); |
| 381 | + return acquireDirectMemoryPermitsAndWriteAndFlush(cnx.ctx(), maxTopicListInFlightLimiter, () -> !cnx.isActive(), |
| 382 | + command, permitAcquireErrorHandler); |
374 | 383 | } |
375 | 384 |
|
376 | 385 | /*** |
377 | 386 | * {@inheritDoc} |
| 387 | + * @return a CompletableFuture that completes when the watch topic list update operation finishes |
378 | 388 | */ |
379 | 389 | @Override |
380 | | - public void sendWatchTopicListUpdate(long watcherId, |
381 | | - List<String> newTopics, List<String> deletedTopics, String topicsHash) { |
| 390 | + public CompletableFuture<Void> sendWatchTopicListUpdate(long watcherId, List<String> newTopics, |
| 391 | + List<String> deletedTopics, String topicsHash, |
| 392 | + Function<Throwable, CompletableFuture<Void>> |
| 393 | + permitAcquireErrorHandler) { |
382 | 394 | BaseCommand command = Commands.newWatchTopicUpdate(watcherId, newTopics, deletedTopics, topicsHash); |
383 | | - interceptAndWriteCommand(command); |
384 | | - } |
385 | | - |
386 | | - private void interceptAndWriteCommand(BaseCommand command) { |
387 | 395 | safeIntercept(command, cnx); |
388 | | - ByteBuf outBuf = Commands.serializeWithSize(command); |
389 | | - writeAndFlush(outBuf); |
| 396 | + return acquireDirectMemoryPermitsAndWriteAndFlush(cnx.ctx(), maxTopicListInFlightLimiter, () -> !cnx.isActive(), |
| 397 | + command, permitAcquireErrorHandler); |
390 | 398 | } |
391 | 399 |
|
392 | 400 | private void writeAndFlush(ByteBuf outBuf) { |
|
0 commit comments