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

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


The following commit(s) were added to refs/heads/master by this push:
     new 366a41e14 simplify code (#2795)
366a41e14 is described below

commit 366a41e14a4d520533c2e04e20c0a4842393a523
Author: weihubeats <[email protected]>
AuthorDate: Mon Jan 2 16:39:30 2023 +0800

    simplify code (#2795)
---
 .../processor/RemoteUnSubscribeEventProcessor.java | 38 ++++++++++++----------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git 
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/RemoteUnSubscribeEventProcessor.java
 
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/RemoteUnSubscribeEventProcessor.java
index 992030d12..af991063d 100644
--- 
a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/RemoteUnSubscribeEventProcessor.java
+++ 
b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/RemoteUnSubscribeEventProcessor.java
@@ -17,17 +17,21 @@
 
 package org.apache.eventmesh.runtime.core.protocol.http.processor;
 
+import static 
org.apache.eventmesh.runtime.constants.EventMeshConstants.CONTENT_TYPE;
+
 import org.apache.eventmesh.common.Constants;
 import org.apache.eventmesh.common.protocol.SubscriptionItem;
 import org.apache.eventmesh.common.protocol.http.HttpEventWrapper;
 import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode;
 import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
 import org.apache.eventmesh.common.protocol.http.common.RequestURI;
+import org.apache.eventmesh.common.utils.AssertUtils;
 import org.apache.eventmesh.common.utils.IPUtils;
 import org.apache.eventmesh.common.utils.JsonUtils;
 import org.apache.eventmesh.common.utils.ThreadUtils;
 import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer;
 import org.apache.eventmesh.runtime.common.EventMeshTrace;
+import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration;
 import org.apache.eventmesh.runtime.constants.EventMeshConstants;
 import org.apache.eventmesh.runtime.core.protocol.http.async.AsyncContext;
 import 
org.apache.eventmesh.runtime.core.protocol.http.processor.inf.AbstractEventProcessor;
@@ -59,10 +63,9 @@ import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.http.HttpRequest;
 
 import com.fasterxml.jackson.core.type.TypeReference;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 
-@EventMeshTrace(isEnable = false)
+@EventMeshTrace
 public class RemoteUnSubscribeEventProcessor extends AbstractEventProcessor {
 
     public Logger httpLogger = 
LoggerFactory.getLogger(EventMeshConstants.PROTOCOL_HTTP);
@@ -131,11 +134,12 @@ public class RemoteUnSubscribeEventProcessor extends 
AbstractEventProcessor {
         long startTime = System.currentTimeMillis();
         try {
             // request to remote
-            String env = 
eventMeshHTTPServer.getEventMeshHttpConfiguration().getEventMeshEnv();
-            String idc = 
eventMeshHTTPServer.getEventMeshHttpConfiguration().getEventMeshIDC();
-            String cluster = 
eventMeshHTTPServer.getEventMeshHttpConfiguration().getEventMeshCluster();
-            String sysId = 
eventMeshHTTPServer.getEventMeshHttpConfiguration().getSysID();
-            String meshGroup = env + "-" + idc + "-" + cluster + "-" + sysId;
+            EventMeshHTTPConfiguration eventMeshHttpConfiguration = 
eventMeshHTTPServer.getEventMeshHttpConfiguration();
+            String env = eventMeshHttpConfiguration.getEventMeshEnv();
+            String idc = eventMeshHttpConfiguration.getEventMeshIDC();
+            String cluster = eventMeshHttpConfiguration.getEventMeshCluster();
+            String sysId = eventMeshHttpConfiguration.getSysID();
+            String meshGroup = String.join("-", env, idc, cluster, sysId);
 
             Map<String, String> remoteHeaderMap = new HashMap<>();
             remoteHeaderMap.put(ProtocolKey.ClientInstanceKey.ENV, env);
@@ -150,7 +154,7 @@ public class RemoteUnSubscribeEventProcessor extends 
AbstractEventProcessor {
 
             // local unSubscription url
             String unsubscribeUrl = "http://"; + IPUtils.getLocalAddress() + ":"
-                + 
eventMeshHTTPServer.getEventMeshHttpConfiguration().httpServerPort
+                + eventMeshHttpConfiguration.httpServerPort
                 + RequestURI.PUBLISH_BRIDGE.getRequestURI();
 
             Map<String, Object> remoteBodyMap = new HashMap<>();
@@ -161,7 +165,7 @@ public class RemoteUnSubscribeEventProcessor extends 
AbstractEventProcessor {
             List<String> unSubTopicList = 
Optional.ofNullable(JsonUtils.deserialize(
                 
JsonUtils.serialize(requestBodyMap.get(EventMeshConstants.MANAGE_TOPIC)),
                 new TypeReference<List<String>>() {}
-            )).orElse(Collections.emptyList());
+            )).orElseGet(Collections::emptyList);
 
             String targetMesh = "";
             if (!Objects.isNull(requestBodyMap.get("remoteMesh"))) {
@@ -187,7 +191,7 @@ public class RemoteUnSubscribeEventProcessor extends 
AbstractEventProcessor {
             Map<String, String> remoteResultMap = 
Optional.ofNullable(JsonUtils.deserialize(
                 remoteResult,
                 new TypeReference<Map<String, String>>() {}
-            )).orElse(Maps.newHashMap());
+            )).orElseGet(Maps::newHashMap);
 
             if 
(String.valueOf(EventMeshRetCode.SUCCESS.getRetCode()).equals(remoteResultMap.get(EventMeshConstants.RET_CODE)))
 {
                 responseBodyMap.put(EventMeshConstants.RET_CODE, 
EventMeshRetCode.SUCCESS.getRetCode());
@@ -216,20 +220,18 @@ public class RemoteUnSubscribeEventProcessor extends 
AbstractEventProcessor {
     public static String post(CloseableHttpClient client, String uri,
                               Map<String, String> requestHeader, Map<String, 
Object> requestBody,
                               ResponseHandler<String> responseHandler) throws 
IOException {
-        Preconditions.checkState(client != null, "client can't be null");
-        Preconditions.checkState(StringUtils.isNotBlank(uri), "uri can't be 
null");
-        Preconditions.checkState(requestHeader != null, "requestParam can't be 
null");
-        Preconditions.checkState(responseHandler != null, "responseHandler 
can't be null");
+        AssertUtils.notNull(client, "client can't be null");
+        AssertUtils.notBlack(uri, "uri can't be null");
+        AssertUtils.notNull(requestHeader, "requestParam can't be null");
+        AssertUtils.notNull(responseHandler, "responseHandler can't be null");
 
         HttpPost httpPost = new HttpPost(uri);
 
-        httpPost.addHeader("Content-Type", 
ContentType.APPLICATION_JSON.getMimeType());
+        httpPost.addHeader(CONTENT_TYPE, 
ContentType.APPLICATION_JSON.getMimeType());
 
         //header
         if (MapUtils.isNotEmpty(requestHeader)) {
-            for (Map.Entry<String, String> entry : requestHeader.entrySet()) {
-                httpPost.addHeader(entry.getKey(), entry.getValue());
-            }
+            requestHeader.forEach(httpPost::addHeader);
         }
 
         //body


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

Reply via email to