use of io.crate.execution.support.MultiActionListener in project crate by crate.
the class TransportAnalyzeAction method publishTableStats.
private CompletableFuture<AcknowledgedResponse> publishTableStats(Map<RelationName, Stats> newTableStats) {
List<DiscoveryNode> nodesOn41OrAfter = StreamSupport.stream(clusterService.state().nodes().spliterator(), false).filter(x -> x.getVersion().onOrAfter(Version.V_4_1_0)).collect(Collectors.toList());
var listener = new FutureActionListener<AcknowledgedResponse, AcknowledgedResponse>(x -> x);
var multiListener = new MultiActionListener<>(nodesOn41OrAfter.size(), Collectors.reducing(new AcknowledgedResponse(true), (resp1, resp2) -> new AcknowledgedResponse(resp1.isAcknowledged() && resp2.isAcknowledged())), listener);
var responseHandler = new ActionListenerResponseHandler<>(multiListener, AcknowledgedResponse::new, ThreadPool.Names.SAME);
PublishTableStatsRequest request = new PublishTableStatsRequest(newTableStats);
for (DiscoveryNode node : nodesOn41OrAfter) {
transportService.sendRequest(node, RECEIVE_TABLE_STATS, request, responseHandler);
}
return listener;
}
use of io.crate.execution.support.MultiActionListener in project crate by crate.
the class TransportAnalyzeAction method fetchSamples.
private CompletableFuture<Samples> fetchSamples(RelationName relationName, List<Reference> columns) {
FutureActionListener<FetchSampleResponse, Samples> listener = new FutureActionListener<>(FetchSampleResponse::samples);
List<DiscoveryNode> nodesOn41OrAfter = StreamSupport.stream(clusterService.state().nodes().spliterator(), false).filter(x -> x.getVersion().onOrAfter(Version.V_4_1_0)).collect(Collectors.toList());
MultiActionListener<FetchSampleResponse, ?, FetchSampleResponse> multiListener = new MultiActionListener<>(nodesOn41OrAfter.size(), Collectors.reducing(new FetchSampleResponse(Samples.EMPTY), (FetchSampleResponse s1, FetchSampleResponse s2) -> FetchSampleResponse.merge(TransportAnalyzeAction.NUM_SAMPLES, s1, s2)), listener);
List<Streamer> streamers = Arrays.asList(Symbols.streamerArray(columns));
ActionListenerResponseHandler<FetchSampleResponse> responseHandler = new ActionListenerResponseHandler<>(multiListener, in -> new FetchSampleResponse(streamers, in), ThreadPool.Names.SAME);
for (DiscoveryNode node : nodesOn41OrAfter) {
transportService.sendRequest(node, FETCH_SAMPLES, new FetchSampleRequest(relationName, columns, TransportAnalyzeAction.NUM_SAMPLES), responseHandler);
}
return listener;
}
use of io.crate.execution.support.MultiActionListener in project crate by crate.
the class TransportKillNodeAction method broadcast.
public void broadcast(Request request, ActionListener<Long> listener, Collection<String> excludedNodeIds) {
Stream<DiscoveryNode> nodes = StreamSupport.stream(clusterService.state().nodes().spliterator(), false);
Collection<DiscoveryNode> filteredNodes = nodes.filter(node -> !excludedNodeIds.contains(node.getId())).collect(Collectors.toList());
MultiActionListener<KillResponse, ?, Long> multiListener = new MultiActionListener<>(filteredNodes.size(), Collectors.summingLong(KillResponse::numKilled), listener);
TransportResponseHandler<KillResponse> responseHandler = new ActionListenerResponseHandler<>(multiListener, KillResponse::new);
for (DiscoveryNode node : filteredNodes) {
transportService.sendRequest(node, name, request, responseHandler);
}
}
Aggregations