albertogpz commented on a change in pull request #7108:
URL: https://github.com/apache/geode/pull/7108#discussion_r753431300



##########
File path: 
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/StopGatewaySenderCommandDelegateParallelImpl.java
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+
+package org.apache.geode.management.internal.cli.commands;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+import org.apache.geode.annotations.VisibleForTesting;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.logging.internal.executors.LoggingExecutors;
+import org.apache.geode.management.internal.SystemManagementService;
+import org.apache.geode.management.internal.cli.result.model.ResultModel;
+import 
org.apache.geode.management.internal.cli.result.model.TabularResultModel;
+import org.apache.geode.management.internal.i18n.CliStrings;
+
+class StopGatewaySenderCommandDelegateParallelImpl
+    implements StopGatewaySenderCommandDelegate {
+
+  private final ExecutorService executorService;
+  private final SystemManagementService managementService;
+  private final StopGatewaySenderOnMemberFactory stopperOnMemberFactory;
+
+  @VisibleForTesting
+  public StopGatewaySenderCommandDelegateParallelImpl(ExecutorService 
executorService,
+      SystemManagementService managementService,
+      StopGatewaySenderOnMemberFactory stopperOnMemberFactory) {
+    this.executorService = executorService;
+    this.managementService = managementService;
+    this.stopperOnMemberFactory = stopperOnMemberFactory;
+  }
+
+  public StopGatewaySenderCommandDelegateParallelImpl(SystemManagementService 
managementService) {
+    executorService = LoggingExecutors.newCachedThreadPool("Stop Sender 
Command Thread ", true);;
+    stopperOnMemberFactory = new 
StopGatewaySenderOnMemberFactoryWithBeanImpl();
+    this.managementService = managementService;
+  }
+
+  public ResultModel executeStopGatewaySender(String id, Cache cache,
+      Set<DistributedMember> dsMembers) {
+    List<Callable<List<String>>> callables = new ArrayList<>();
+    for (final DistributedMember member : dsMembers) {
+      callables.add(() -> 
stopperOnMemberFactory.create().executeStopGatewaySenderOnMember(id,
+          cache, managementService, member));
+    }
+
+    List<Future<List<String>>> futures;
+    try {
+      futures = executorService.invokeAll(callables);
+    } catch (InterruptedException ite) {
+      Thread.currentThread().interrupt();
+      return ResultModel.createError(
+          
CliStrings.format(CliStrings.GATEWAY_SENDER_STOP_0_COULD_NOT_BE_INVOKED_DUE_TO_1,
 id,
+              ite.getMessage()));
+    } finally {
+      executorService.shutdown();
+    }
+
+    return buildResultModelFromMembersResponses(id, dsMembers, futures);
+  }
+
+  private ResultModel buildResultModelFromMembersResponses(String id,
+      Set<DistributedMember> dsMembers, List<Future<List<String>>> futures) {
+    ResultModel resultModel = new ResultModel();
+    TabularResultModel resultData = 
resultModel.addTable(CliStrings.STOP_GATEWAYSENDER);
+    Iterator<DistributedMember> memberIterator = dsMembers.iterator();
+    for (Future<List<String>> future : futures) {
+      DistributedMember member = memberIterator.next();

Review comment:
       I have created a `List` from the `dsMembers` `Set` and I have passed it 
to the method so that we can be sure that the order between the `dsMembers` and 
the `futures` is the same.




-- 
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]


Reply via email to