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

mxsm 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 85ee0fb69 [ISSUE #4191] Do some code 
optimization.[StreamPushRequest](#4356)
85ee0fb69 is described below

commit 85ee0fb69efb841ee6083fb2af0086a649e7f392
Author: Himanshu Sharma <[email protected]>
AuthorDate: Mon Aug 14 06:57:51 2023 +0530

    [ISSUE #4191] Do some code optimization.[StreamPushRequest](#4356)
---
 .../core/protocol/grpc/push/StreamPushRequest.java | 30 ++++++++++------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git 
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/StreamPushRequest.java
 
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/StreamPushRequest.java
index 3a1df1855..04225d1aa 100644
--- 
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/StreamPushRequest.java
+++ 
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/grpc/push/StreamPushRequest.java
@@ -101,28 +101,26 @@ public class StreamPushRequest extends 
AbstractPushRequest {
         List<EventEmitter<CloudEvent>> emitterList = 
MapUtils.getObject(idcEmitters,
             eventMeshGrpcConfiguration.getEventMeshIDC(), null);
         if (CollectionUtils.isNotEmpty(emitterList)) {
-            if (subscriptionMode == SubscriptionMode.CLUSTERING) {
-                return Collections.singletonList(emitterList.get((startIdx + 
retryTimes) % emitterList.size()));
-            } else if (subscriptionMode == SubscriptionMode.BROADCASTING) {
-                return emitterList;
-            } else {
-                log.error("Invalid Subscription Mode, no message returning 
back to subscriber.");
-                return Collections.emptyList();
-            }
+            return getEventEmitters(emitterList);
         }
 
         if (CollectionUtils.isNotEmpty(totalEmitters)) {
-            if (subscriptionMode == SubscriptionMode.CLUSTERING) {
-                return Collections.singletonList(totalEmitters.get((startIdx + 
retryTimes) % totalEmitters.size()));
-            } else if (subscriptionMode == SubscriptionMode.BROADCASTING) {
-                return totalEmitters;
-            } else {
-                log.error("Invalid Subscription Mode, no message returning 
back to subscriber.");
-                return Collections.emptyList();
-            }
+            return getEventEmitters(totalEmitters);
         }
 
         log.error("No event emitters from subscriber, no message returning.");
         return Collections.emptyList();
     }
+
+    private List<EventEmitter<CloudEvent>> 
getEventEmitters(List<EventEmitter<CloudEvent>> emitterList) {
+        switch (subscriptionMode) {
+            case CLUSTERING:
+                return Collections.singletonList(emitterList.get((startIdx + 
retryTimes) % emitterList.size()));
+            case BROADCASTING:
+                return emitterList;
+            default:
+                log.error("Invalid Subscription Mode, no message returning 
back to subscriber.");
+                return Collections.emptyList();
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to