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



##########
File path: 
geode-core/src/main/java/org/apache/geode/management/internal/configuration/functions/GatewaySenderManageFunction.java
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.configuration.functions;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.annotations.Immutable;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.wan.GatewaySender;
+import org.apache.geode.internal.cache.execute.InternalFunction;
+import org.apache.geode.internal.cache.xmlcache.CacheXml;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.management.internal.configuration.domain.XmlEntity;
+import org.apache.geode.management.internal.functions.CliFunctionResult;
+
+public class GatewaySenderManageFunction implements InternalFunction {
+  private static final Logger logger = LogService.getLogger();
+  private static final long serialVersionUID = -6022504778575202026L;
+
+  @Immutable
+  public static final GatewaySenderManageFunction INSTANCE = new 
GatewaySenderManageFunction();
+
+  private static final String ID = GatewaySenderManageFunction.class.getName();
+
+  @Override
+  public boolean hasResult() {
+    return true;
+  }
+
+
+  /**
+   * This function is used to report all the gateway sender instances for a 
given sender
+   * if all intances are stopped. In order to do so, it invokes the 
setMustQueueDroppedEvents()
+   * method
+   * on every gateway sender instance for the gateway sender passed as a 
parameter.
+   * The function requires an Object[] as context.getArguments() in which
+   * - the first parameter must be a Boolean stating of all gateway sender 
instances are stopped
+   * - the second parameter must be a String containing the name of the sender.
+   */
+  @Override
+  public void execute(FunctionContext context) {
+    String memberName = context.getMemberName();
+    try {
+      Object[] arguments;
+
+      Boolean stop = getStopFromArguments(context.getArguments());
+      if (stop == null) {
+        context.getResultSender().lastResult(new CliFunctionResult("", false,
+            "Wrong arguments passed"));
+        return;
+      }
+      String senderId = getSenderIdFromArguments(context.getArguments());
+      if (senderId == null) {
+        context.getResultSender().lastResult(new CliFunctionResult("", false,
+            "Wrong arguments passed"));
+        return;
+      }
+
+      Cache cache = context.getCache();
+      GatewaySender sender = cache.getGatewaySender(senderId);
+
+      if (sender == null) {
+        context.getResultSender().lastResult(new CliFunctionResult(memberName, 
false,
+            String.format("Sender '%s' does not exist", senderId)));
+        return;
+      }
+
+      sender.setMustQueueDroppedEvents(!stop);
+      XmlEntity xmlEntity = new XmlEntity(CacheXml.GATEWAY_SENDER, "name", 
senderId);

Review comment:
       I did not want to extend CliFunction because I intended this function to 
be used by users of the Java API as @gesterzhou was after.
   
   In a new commit:
   
   - I have simplified the function a bit because the first level try/catch was 
already taking care of any exception.
   
   - I have also changed the name of the setter/flag from 
setMustQueueDroppedEvents to setAllInstancesStopped. I think it is a more 
understandable name without knowing the low level details about the dropped 
events.
   
   @gesterzhou Would this solution be acceptable for you having fixed the 
problem in gfsh and at the same time having a function that could be called by 
Java API users?




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to