Skip to content

Commit

Permalink
replaced optional
Browse files Browse the repository at this point in the history
  • Loading branch information
heesung-sn committed May 13, 2023
1 parent 4ee4b99 commit 2e8eb09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -380,19 +381,19 @@ public CompletableFuture<Optional<BrokerLookupData>> assign(Optional<ServiceUnit
}

public CompletableFuture<Optional<String>> selectAsync(ServiceUnitId bundle) {
return selectAsync(bundle, Optional.empty());
return selectAsync(bundle, Collections.emptySet());
}

public CompletableFuture<Optional<String>> selectAsync(ServiceUnitId bundle,
Optional<Set<String>> excludeBrokerSet) {
Set<String> excludeBrokerSet) {
BrokerRegistry brokerRegistry = getBrokerRegistry();
return brokerRegistry.getAvailableBrokerLookupDataAsync()
.thenCompose(availableBrokers -> {
LoadManagerContext context = this.getContext();

Map<String, BrokerLookupData> availableBrokerCandidates = new HashMap<>(availableBrokers);
if (excludeBrokerSet.isPresent()) {
for (String exclude : excludeBrokerSet.get()) {
if (!excludeBrokerSet.isEmpty()) {
for (String exclude : excludeBrokerSet) {
availableBrokerCandidates.remove(exclude);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ private synchronized void doCleanup(String broker) {

private Optional<String> selectBroker(String serviceUnit, String inactiveBroker) {
try {
return loadManager.selectAsync(getNamespaceBundle(serviceUnit), Optional.of(Set.of(inactiveBroker)))
return loadManager.selectAsync(getNamespaceBundle(serviceUnit), Set.of(inactiveBroker))
.get(inFlightStateWaitingTimeInMillis, MILLISECONDS);
} catch (Throwable e) {
log.error("Failed to select a broker for serviceUnit:{}", serviceUnit);
Expand Down

0 comments on commit 2e8eb09

Please sign in to comment.