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

wujimin pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 35512028e50a8ca39173fe91d99b19a7ac8d9497
Author: zhengyangyong <yangyong.zh...@huawei.com>
AuthorDate: Tue May 8 18:37:38 2018 +0800

    SCB-548 support gracefully shutdown
    
    Signed-off-by: zhengyangyong <yangyong.zh...@huawei.com>
---
 .../servicecomb/core/CseApplicationListener.java    | 21 +++++++++++++++++++--
 .../zuul/tracing/SpringCloudZuulTracingTest.java    |  1 -
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git 
a/core/src/main/java/org/apache/servicecomb/core/CseApplicationListener.java 
b/core/src/main/java/org/apache/servicecomb/core/CseApplicationListener.java
index 4952f35..060309e 100644
--- a/core/src/main/java/org/apache/servicecomb/core/CseApplicationListener.java
+++ b/core/src/main/java/org/apache/servicecomb/core/CseApplicationListener.java
@@ -33,6 +33,7 @@ import org.apache.servicecomb.core.transport.TransportManager;
 import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.foundation.common.utils.BeanUtils;
 import org.apache.servicecomb.foundation.common.utils.FortifyUtils;
+import org.apache.servicecomb.foundation.vertx.VertxUtils;
 import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import 
org.apache.servicecomb.serviceregistry.task.MicroserviceInstanceRegisterTask;
 import org.slf4j.Logger;
@@ -50,6 +51,8 @@ import org.springframework.util.StringUtils;
 
 import com.google.common.eventbus.Subscribe;
 
+import io.vertx.core.Vertx;
+
 public class CseApplicationListener
     implements ApplicationListener<ApplicationEvent>, Ordered, 
ApplicationContextAware {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(CseApplicationListener.class);
@@ -135,8 +138,6 @@ public class CseApplicationListener
           RegistryUtils.run();
 
           // 当程序退出时,进行相关清理,注意:kill -9 {pid}下无效
-          // 1. 去注册实例信息
-          // TODO 服务优雅退出
           if (applicationContext instanceof AbstractApplicationContext) {
             ((AbstractApplicationContext) 
applicationContext).registerShutdownHook();
           }
@@ -148,12 +149,28 @@ public class CseApplicationListener
     } else if (event instanceof ContextClosedEvent) {
       LOGGER.warn("cse is closing now...");
       triggerEvent(EventType.BEFORE_CLOSE);
+
+      //Unregister microservice instance from Service Center
       RegistryUtils.destroy();
+
+      //Stop vertx threads to prevent blocking exit
+      closeVertx("registry");
+      closeVertx("config-center");
+      closeVertx("transport");
+
       triggerEvent(EventType.AFTER_CLOSE);
       isInit = false;
     }
   }
 
+  private void closeVertx(String name) {
+    Vertx vertx = VertxUtils.getVertxByName(name);
+    if (vertx != null) {
+      vertx.close();
+      VertxUtils.getVertxMap().remove(name);
+    }
+  }
+
   /**
    * <p>As the process of instance registry is asynchronous, the {@code 
AFTER_REGISTRY}
    * event should not be sent immediately after {@link RegistryUtils#run()} is 
invoked.
diff --git 
a/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/SpringCloudZuulTracingTest.java
 
b/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/SpringCloudZuulTracingTest.java
index 35a82b1..1402cc2 100644
--- 
a/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/SpringCloudZuulTracingTest.java
+++ 
b/integration-tests/spring-zuul-tracing-tests/src/test/java/org/apache/servicecomb/spring/cloud/zuul/tracing/SpringCloudZuulTracingTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.servicecomb.spring.cloud.zuul.tracing;
 
-import static com.seanyinx.github.unit.scaffolding.AssertUtils.expectFailing;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertEquals;

-- 
To stop receiving notification emails like this one, please contact
wuji...@apache.org.

Reply via email to