BewareMyPower commented on code in PR #19102:
URL: https://github.com/apache/pulsar/pull/19102#discussion_r1061321237
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/channel/ServiceUnitStateChannel.java:
##########
@@ -51,7 +51,7 @@ public interface ServiceUnitStateChannel extends Closeable {
*
* ServiceUnitStateChannel elects the separate leader as the owner broker
of the system topic in this channel.
*/
- CompletableFuture<Optional<String>> getChannelOwnerAsync();
+ CompletableFuture<String> getChannelOwnerAsync();
Review Comment:
Using an `Optional` could make code more simple. e.g. the
`getChannelOwnerAsync` can be implemented like:
```java
return leaderElectionService.readCurrentLeader().thenApply(leader ->
leader.map(LeaderBroker::getServiceUrl)
.map(url -> url.substring(url.lastIndexOf('/') +
1)));
```
`isChannelOwnerAsync`:
```java
return getChannelOwnerAsync().thenApply(optOwner ->
optOwner.map(this::isTargetBroker).orElse(false));
```
If you didn't return an `Optional`, the caller side might mix the expected
error (i.e. the leader is absent) and unexpected errors (i.e. NPE or other
unchecked exceptions).
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]