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 d79615b05f54b2f9f7ca6af00d3f0be98f30c7bf
Author: zhengyangyong <yangyong.zh...@huawei.com>
AuthorDate: Wed May 9 15:59:08 2018 +0800

    SCB-548 improvement and fix it failed
    
    Signed-off-by: zhengyangyong <yangyong.zh...@huawei.com>
---
 .../servicecomb/core/CseApplicationListener.java       | 18 +++---------------
 .../servicecomb/core/handler/ShutdownHookHandler.java  |  8 ++++++++
 .../servicecomb/foundation/vertx/VertxUtils.java       |  7 +++++++
 .../springmvc/tests/RawSpringMvcIntegrationTest.java   |  2 +-
 ...gMvcSimplifiedMappingAnnotationIntegrationTest.java |  2 +-
 5 files changed, 20 insertions(+), 17 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 060309e..0cd57f6 100644
--- a/core/src/main/java/org/apache/servicecomb/core/CseApplicationListener.java
+++ b/core/src/main/java/org/apache/servicecomb/core/CseApplicationListener.java
@@ -51,8 +51,6 @@ 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);
@@ -150,26 +148,16 @@ public class CseApplicationListener
       LOGGER.warn("cse is closing now...");
       triggerEvent(EventType.BEFORE_CLOSE);
 
-      //Unregister microservice instance from Service Center
+      //Unregister microservice instance from Service Center and close vertx
+      //We need unregister from service center immediately
       RegistryUtils.destroy();
-
-      //Stop vertx threads to prevent blocking exit
-      closeVertx("registry");
-      closeVertx("config-center");
-      closeVertx("transport");
+      VertxUtils.closeVertxByName("registry");
 
       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}
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/handler/ShutdownHookHandler.java
 
b/core/src/main/java/org/apache/servicecomb/core/handler/ShutdownHookHandler.java
index 8d1318a..c4d9a3a 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/handler/ShutdownHookHandler.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/handler/ShutdownHookHandler.java
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.servicecomb.core.Handler;
 import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.foundation.vertx.VertxUtils;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.slf4j.Logger;
@@ -56,6 +57,8 @@ public final class ShutdownHookHandler implements Handler, 
Runnable {
   @Override
   public void handle(Invocation invocation, AsyncResponse asyncResp) throws 
Exception {
     if (shuttingDown) {
+      System.out.println("shutting down in progress");
+
       asyncResp.handle(Response.createFail(invocation.getInvocationType(),
           "shutting down in progress"));
       return;
@@ -92,6 +95,11 @@ public final class ShutdownHookHandler implements Handler, 
Runnable {
       time = time + period;
       LOG.warn("waiting invocation to finish in seconds " + time);
     }
+
+    //Stop vertx to prevent blocking exit, this work need do after invocation 
waiting timeout
+    VertxUtils.closeVertxByName("config-center");
+    VertxUtils.closeVertxByName("transport");
+
     LOG.warn("handler chain is shut down");
   }
 }
diff --git 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
index 4aba612..d5e55f4 100644
--- 
a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
+++ 
b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java
@@ -157,6 +157,13 @@ public final class VertxUtils {
     return vertxMap.get(name);
   }
 
+  public static void closeVertxByName(String name) {
+    Vertx vertx = vertxMap.remove(name);
+    if (vertx != null) {
+      vertx.close();
+    }
+  }
+
   public static <T> void runInContext(Context context, AsyncResultCallback<T> 
callback, T result, Throwable e) {
     if (context == Vertx.currentContext()) {
       complete(callback, result, e);
diff --git 
a/integration-tests/springmvc-tests/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
 
b/integration-tests/springmvc-tests/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
index dd11460..7149755 100644
--- 
a/integration-tests/springmvc-tests/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
+++ 
b/integration-tests/springmvc-tests/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcIntegrationTest.java
@@ -33,7 +33,7 @@ public class RawSpringMvcIntegrationTest extends 
SpringMvcIntegrationTestBase {
   }
 
   @AfterClass
-  public static void shutdown() throws Exception {
+  public static void shutdown() {
     CseApplicationListener cal = 
BeanUtils.getBean("org.apache.servicecomb.core.CseApplicationListener");
     ContextClosedEvent event = new ContextClosedEvent(BeanUtils.getContext());
     cal.onApplicationEvent(event);
diff --git 
a/integration-tests/springmvc-tests/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcSimplifiedMappingAnnotationIntegrationTest.java
 
b/integration-tests/springmvc-tests/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcSimplifiedMappingAnnotationIntegrationTest.java
index a4cd050..f25f080 100644
--- 
a/integration-tests/springmvc-tests/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcSimplifiedMappingAnnotationIntegrationTest.java
+++ 
b/integration-tests/springmvc-tests/src/test/java/org/apache/servicecomb/demo/springmvc/tests/RawSpringMvcSimplifiedMappingAnnotationIntegrationTest.java
@@ -34,7 +34,7 @@ public class 
RawSpringMvcSimplifiedMappingAnnotationIntegrationTest extends Spri
   }
 
   @AfterClass
-  public static void shutdown() throws Exception {
+  public static void shutdown() {
     CseApplicationListener cal = 
BeanUtils.getBean("org.apache.servicecomb.core.CseApplicationListener");
     ContextClosedEvent event = new ContextClosedEvent(BeanUtils.getContext());
     cal.onApplicationEvent(event);

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

Reply via email to