You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2023/07/14 06:25:14 UTC

[eventmesh] branch master updated: [ISSUE #4197] Use switch instead of if else

This is an automated email from the ASF dual-hosted git repository.

mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new d9f1087e3 [ISSUE #4197] Use switch instead of if else
d9f1087e3 is described below

commit d9f1087e3102751f15d5ae37c640ea1193900214
Author: Kartik Tayal <47...@users.noreply.github.com>
AuthorDate: Fri Jul 14 11:55:07 2023 +0530

    [ISSUE #4197] Use switch instead of if else
    
    Fix #4197
    
    Signed-off-by: Kartik Tayal <ta...@gmail.com>
---
 .../protocol/grpc/push/WebhookPushRequest.java     | 45 ++++++++++++----------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/WebhookPushRequest.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/WebhookPushRequest.java
index 662774fc4..42ef037d8 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/WebhookPushRequest.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/WebhookPushRequest.java
@@ -201,10 +201,17 @@ public class WebhookPushRequest extends AbstractPushRequest {
                     "message|eventMesh2client|{}|url={}|topic={}|bizSeqNo={}"
                         + "|uniqueId={}|cost={}", result, selectedPushUrl, EventMeshCloudEventUtils.getSubject(eventMeshCloudEvent),
                     EventMeshCloudEventUtils.getSeqNum(eventMeshCloudEvent), EventMeshCloudEventUtils.getUniqueId(eventMeshCloudEvent), cost);
-                if (result == ClientRetCode.OK || result == ClientRetCode.FAIL) {
-                    complete();
-                } else if (result == ClientRetCode.RETRY || result == ClientRetCode.NOLISTEN) {
-                    delayRetry();
+                switch (result) {
+                    case OK:
+                    case FAIL:
+                        complete();
+                        break;
+                    case RETRY:
+                    case NOLISTEN:
+                        delayRetry();
+                        break;
+                    default:
+                        //do nothing
                 }
             }
             return new Object();
@@ -237,27 +244,23 @@ public class WebhookPushRequest extends AbstractPushRequest {
         List<String> localIdcUrl = MapUtils.getObject(urls,
             eventMeshGrpcConfiguration.getEventMeshIDC(), null);
         if (CollectionUtils.isNotEmpty(localIdcUrl)) {
-            if (subscriptionMode == SubscriptionMode.CLUSTERING) {
-                return Collections.singletonList(localIdcUrl.get((startIdx + retryTimes) % localIdcUrl.size()));
-            } else if (subscriptionMode == SubscriptionMode.BROADCASTING) {
-                return localIdcUrl;
-            } else {
-                MESSAGE_LOGGER.error("Invalid Subscription Mode, no message returning back to subscriber.");
-                return Collections.emptyList();
-            }
+            return getStringList(localIdcUrl);
+        } else if (CollectionUtils.isNotEmpty(totalUrls)) {
+            return getStringList(totalUrls);
         }
+        MESSAGE_LOGGER.error("No event emitters from subscriber, no message returning.");
+        return Collections.emptyList();
+    }
 
-        if (CollectionUtils.isNotEmpty(totalUrls)) {
-            if (subscriptionMode == SubscriptionMode.CLUSTERING) {
-                return Collections.singletonList(totalUrls.get((startIdx + retryTimes) % totalUrls.size()));
-            } else if (subscriptionMode == SubscriptionMode.BROADCASTING) {
-                return totalUrls;
-            } else {
+    private List<String> getStringList(List<String> stringList) {
+        switch (subscriptionMode) {
+            case CLUSTERING:
+                return Collections.singletonList(stringList.get((startIdx + retryTimes) % stringList.size()));
+            case BROADCASTING:
+                return stringList;
+            default:
                 MESSAGE_LOGGER.error("Invalid Subscription Mode, no message returning back to subscriber.");
                 return Collections.emptyList();
-            }
         }
-        MESSAGE_LOGGER.error("No event emitters from subscriber, no message returning.");
-        return Collections.emptyList();
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org