Last active
August 9, 2021 00:11
-
-
Save vthacker/91e0990017a90a2f730add2841f4f7e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method that overrides the gRPC | |
@Override | |
public void search( | |
SearchRequest request, | |
StreamObserver<SearchResult> responseObserver) { | |
doSearch(request) | |
.whenCompleteAsync( | |
(result, t) -> { | |
if (t != null) { | |
LOG.error("Error completing the future", t); | |
responseObserver.onError(t); | |
} else { | |
responseObserver.onNext(result); | |
responseObserver.onCompleted(); | |
} | |
}); | |
} | |
public CompletableFuture<SearchResult> doSearch(SearchRequest request) { | |
List<CompletableFuture<KaldbSearch.SearchResult>> queryServers = new ArrayList<>(servers.size()); | |
for (String server : servers) { | |
// get stub | |
queryServers.add(ListenableFuturesExtra.toCompletableFuture(stub.search(request))); | |
} | |
// query all servers | |
CompletableFuture<List<SearchResult>> searchResults = CompletableFutures.successfulAsList(queryServers, t -> emptyResult); | |
// aggregate | |
// convert to proto | |
return SearchResultUtils.toSearchResultProto(aggregatedResult); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment