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

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


The following commit(s) were added to refs/heads/master by this push:
     new 09768be  [type: refactor] reconstruct some code (#2730)
09768be is described below

commit 09768be89ee0827c13fc3c55d859f4529f9a44d5
Author: xiaoyu <[email protected]>
AuthorDate: Fri Jan 7 18:04:41 2022 +0800

    [type: refactor] reconstruct some code (#2730)
    
    * [type: refactor] reconstruct some code
    
    * [type: refactor] reconstruct some code
    
    * [type: refactor] reconstruct some code
---
 shenyu-examples/shenyu-examples-eureka/pom.xml     |  6 +--
 .../loadbalancer/cache/UpstreamCacheManager.java   | 11 +----
 .../loadbalancer/cache/UpstreamCheckTask.java      | 53 ++++++++++++----------
 shenyu-web/pom.xml                                 |  3 +-
 4 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/shenyu-examples/shenyu-examples-eureka/pom.xml 
b/shenyu-examples/shenyu-examples-eureka/pom.xml
index 4b41352..e275653 100644
--- a/shenyu-examples/shenyu-examples-eureka/pom.xml
+++ b/shenyu-examples/shenyu-examples-eureka/pom.xml
@@ -52,17 +52,17 @@
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
         </dependency>
-        <!--spring boot的核心启动器-->
+  
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
-        <!--aop支持-->
+     
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-aop</artifactId>
         </dependency>
-        <!--自动配置-->
+       
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-configuration-processor</artifactId>
diff --git 
a/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
 
b/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
index 0b2a4d4..1d11cb2 100644
--- 
a/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
+++ 
b/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManager.java
@@ -96,7 +96,7 @@ public final class UpstreamCacheManager {
             if (printEnable) {
                 ThreadFactory printFactory = 
ShenyuThreadFactory.create("upstream-health-print", true);
                 new ScheduledThreadPoolExecutor(1, printFactory)
-                        .scheduleWithFixedDelay(task::printHealthyUpstream, 
printInterval, printInterval, TimeUnit.MILLISECONDS);
+                        .scheduleWithFixedDelay(task::print, printInterval, 
printInterval, TimeUnit.MILLISECONDS);
             }
         }
     }
@@ -139,19 +139,10 @@ public final class UpstreamCacheManager {
     public void submit(final String selectorId, final List<Upstream> 
upstreamList) {
         if (CollectionUtils.isNotEmpty(upstreamList)) {
             List<Upstream> existUpstream = 
UPSTREAM_MAP.computeIfAbsent(selectorId, k -> Lists.newArrayList());
-            /**
-             * check upstream delete.
-             */
             existUpstream.stream().filter(upstream -> 
!upstreamList.contains(upstream))
                     .forEach(upstream -> task.triggerRemoveOne(selectorId, 
upstream));
-            /**
-             * check upstream add.
-             */
             upstreamList.stream().filter(upstream -> 
!existUpstream.contains(upstream))
                     .forEach(upstream -> task.triggerAddOne(selectorId, 
upstream));
-            /**
-             * replace upstream
-             */
             UPSTREAM_MAP.put(selectorId, upstreamList);
         } else {
             UPSTREAM_MAP.remove(selectorId);
diff --git 
a/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCheckTask.java
 
b/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCheckTask.java
index 9b2c37d..856a5e6 100644
--- 
a/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCheckTask.java
+++ 
b/shenyu-loadbalancer/src/main/java/org/apache/shenyu/loadbalancer/cache/UpstreamCheckTask.java
@@ -68,20 +68,25 @@ public final class UpstreamCheckTask implements Runnable {
     private int healthyThreshold = 1;
 
     private int unhealthyThreshold = 1;
-
+    
+    /**
+     * Instantiates a new Upstream check task.
+     *
+     * @param checkInterval the check interval
+     */
     public UpstreamCheckTask(final int checkInterval) {
         this.checkInterval = checkInterval;
     }
-
+    
     /**
      * get checkStarted.
      *
-     * @return checkStarted
+     * @return checkStarted check started
      */
     public AtomicBoolean getCheckStarted() {
         return checkStarted;
     }
-
+    
     /**
      * Schedule health check task.
      */
@@ -95,7 +100,7 @@ public final class UpstreamCheckTask implements Runnable {
         ThreadFactory requestFactory = 
ShenyuThreadFactory.create("upstream-health-check-request", true);
         executor = new ScheduledThreadPoolExecutor(10, requestFactory);
     }
-
+    
     /**
      * Set check timeout.
      *
@@ -104,7 +109,7 @@ public final class UpstreamCheckTask implements Runnable {
     public void setCheckTimeout(final int checkTimeout) {
         this.checkTimeout = checkTimeout;
     }
-
+    
     /**
      * Set healthy threshold.
      *
@@ -113,7 +118,7 @@ public final class UpstreamCheckTask implements Runnable {
     public void setHealthyThreshold(final int healthyThreshold) {
         this.healthyThreshold = healthyThreshold;
     }
-
+    
     /**
      * Set unhealthy threshold.
      *
@@ -130,7 +135,7 @@ public final class UpstreamCheckTask implements Runnable {
 
     private void healthCheck() {
         try {
-            /**
+            /*
              * If there is no synchronized. when check is done and all 
upstream check result is in the futures list.
              * In the same time, triggerRemoveAll() called before 
waitFinish(), there will be dirty data stay in map.
              */
@@ -222,22 +227,22 @@ public final class UpstreamCheckTask implements Runnable {
     private void finishHealthCheck() {
         checkStarted.set(false);
     }
-
+    
     /**
      * Add one upstream via selectorData.
      *
      * @param selectorId selectorId
-     * @param upstream     upstream
+     * @param upstream upstream
      */
     public void triggerAddOne(final String selectorId, final Upstream 
upstream) {
         putToMap(healthyUpstream, selectorId, upstream);
     }
-
+    
     /**
      * Remove a specific upstream via selectorId.
      *
      * @param selectorId selectorId
-     * @param upstream   upstream
+     * @param upstream upstream
      */
     public void triggerRemoveOne(final String selectorId, final Upstream 
upstream) {
         removeFromMap(healthyUpstream, selectorId, upstream);
@@ -261,7 +266,7 @@ public final class UpstreamCheckTask implements Runnable {
             }
         }
     }
-
+    
     /**
      * Remove all upstream via selectorId.
      *
@@ -273,11 +278,16 @@ public final class UpstreamCheckTask implements Runnable {
             unhealthyUpstream.remove(selectorId);
         }
     }
-
+    
     /**
-     * Print healthy upstream.
+     * Print healthy and unhealthy check log.
      */
-    public void printHealthyUpstream() {
+    public void print() {
+        printHealthyUpstream();
+        printUnhealthyUpstream();
+    }
+    
+    private void printHealthyUpstream() {
         healthyUpstream.forEach((k, v) -> {
             if (Objects.nonNull(v)) {
                 List<String> list = 
v.stream().map(Upstream::getUrl).collect(Collectors.toList());
@@ -285,11 +295,8 @@ public final class UpstreamCheckTask implements Runnable {
             }
         });
     }
-
-    /**
-     * Print unhealthy upstream.
-     */
-    public void printUnhealthyUpstream() {
+    
+    private void printUnhealthyUpstream() {
         unhealthyUpstream.forEach((k, v) -> {
             if (Objects.nonNull(v)) {
                 List<String> list = 
v.stream().map(Upstream::getUrl).collect(Collectors.toList());
@@ -297,7 +304,7 @@ public final class UpstreamCheckTask implements Runnable {
             }
         });
     }
-
+    
     /**
      * Get healthy upstream map.
      *
@@ -306,7 +313,7 @@ public final class UpstreamCheckTask implements Runnable {
     public Map<String, List<Upstream>> getHealthyUpstream() {
         return healthyUpstream;
     }
-
+    
     /**
      * Get unhealthy upstream map.
      *
diff --git a/shenyu-web/pom.xml b/shenyu-web/pom.xml
index 7c71778..32c49f9 100644
--- a/shenyu-web/pom.xml
+++ b/shenyu-web/pom.xml
@@ -31,8 +31,7 @@
             <artifactId>shenyu-plugin-base</artifactId>
             <version>${project.version}</version>
         </dependency>
-
-        <!--自动配置-->
+        
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-configuration-processor</artifactId>

Reply via email to