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

mercyblitz pushed a commit to branch 0.1.1
in repository 
https://gitbox.apache.org/repos/asf/incubator-dubbo-spring-boot-project.git


The following commit(s) were added to refs/heads/0.1.1 by this push:
     new d436a4b  Polish #67
d436a4b is described below

commit d436a4ba42e9ba84a6f34ede31375c79131071f4
Author: mercyblitz <mercybl...@gmail.com>
AuthorDate: Tue Mar 27 00:10:48 2018 +0800

    Polish #67
---
 .../event/AwaitingNonWebApplicationListener.java   | 96 ++++++++++++++++++++++
 .../src/main/resources/META-INF/spring.factories   |  3 +-
 .../src/main/resources/application.properties      |  2 +-
 .../dubbo-spring-boot-sample-provider/pom.xml      |  2 +-
 .../demo/provider/bootstrap/DubboProviderDemo.java |  6 +-
 .../src/main/resources/application.properties      |  2 +-
 6 files changed, 105 insertions(+), 6 deletions(-)

diff --git 
a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListener.java
 
b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListener.java
new file mode 100644
index 0000000..a2b8b3f
--- /dev/null
+++ 
b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListener.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alibaba.boot.dubbo.context.event;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.ApplicationListener;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Awaiting Non-Web Spring Boot {@link ApplicationListener}
+ *
+ * @author <a href="mailto:mercybl...@gmail.com";>Mercy</a>
+ * @since 0.1.1
+ */
+public class AwaitingNonWebApplicationListener implements 
ApplicationListener<ApplicationReadyEvent> {
+
+    private static final Logger logger = 
LoggerFactory.getLogger(AwaitingNonWebApplicationListener.class);
+
+    private static final ExecutorService executorService = 
Executors.newSingleThreadExecutor();
+
+    private static final AtomicBoolean shutdownHookRegistered = new 
AtomicBoolean(false);
+
+    private static final AtomicBoolean awaited = new AtomicBoolean(false);
+
+    @Override
+    public void onApplicationEvent(ApplicationReadyEvent event) {
+
+        final SpringApplication springApplication = 
event.getSpringApplication();
+
+        if (springApplication.isWebEnvironment()) {
+            return;
+        }
+
+        executorService.execute(new Runnable() {
+            @Override
+            public void run() {
+
+                synchronized (springApplication) {
+                    if (logger.isInfoEnabled()) {
+                        logger.info(" [Dubbo] Current Spring Boot Application 
is await...");
+                    }
+                    while (!awaited.get()) {
+                        try {
+                            springApplication.wait();
+                        } catch (InterruptedException e) {
+                            Thread.currentThread().interrupt();
+                        }
+                    }
+                }
+            }
+        });
+
+        // register ShutdownHook
+        if (shutdownHookRegistered.compareAndSet(false, true)) {
+            registerShutdownHook(new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    synchronized (springApplication) {
+                        if (awaited.compareAndSet(false, true)) {
+                            springApplication.notifyAll();
+                            if (logger.isInfoEnabled()) {
+                                logger.info(" [Dubbo] Current Spring Boot 
Application is about to shutdown...");
+                            }
+                            // Shutdown executorService
+                            executorService.shutdown();
+                        }
+                    }
+                }
+            }));
+        }
+    }
+
+    private void registerShutdownHook(Thread thread) {
+        Runtime.getRuntime().addShutdownHook(thread);
+    }
+}
diff --git 
a/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories 
b/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
index 8a9cc1d..52fe93c 100644
--- 
a/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
+++ 
b/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories
@@ -4,4 +4,5 @@ com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration
 
 org.springframework.context.ApplicationListener=\
 com.alibaba.boot.dubbo.context.event.OverrideDubboConfigApplicationListener,\
-com.alibaba.boot.dubbo.context.event.WelcomeLogoApplicationListener
\ No newline at end of file
+com.alibaba.boot.dubbo.context.event.WelcomeLogoApplicationListener,\
+com.alibaba.boot.dubbo.context.event.AwaitingNonWebApplicationListener
\ No newline at end of file
diff --git 
a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.properties
 
b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.properties
index 50a1f8b..7fc14dd 100644
--- 
a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.properties
+++ 
b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.properties
@@ -2,7 +2,7 @@
 spring.application.name = dubbo-consumer-demo
 server.port = 8080
 management.port = 8081
-
+management.security.enabled = false
 
 # Dubbo Config properties
 ## ApplicationConfig Bean
diff --git 
a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml 
b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml
index 5dd4eb7..070e3dc 100644
--- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml
+++ b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml
@@ -18,7 +18,7 @@
         <!-- Spring Boot dependencies -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
+            <artifactId>spring-boot-starter</artifactId>
         </dependency>
 
         <dependency>
diff --git 
a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboProviderDemo.java
 
b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboProviderDemo.java
index a521e3d..db3fcf1 100644
--- 
a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboProviderDemo.java
+++ 
b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/bootstrap/DubboProviderDemo.java
@@ -17,8 +17,8 @@
 package com.alibaba.boot.dubbo.demo.provider.bootstrap;
 
 import com.alibaba.boot.dubbo.demo.provider.service.DefaultDemoService;
-import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
 
 /**
  * Dubbo Provider Demo
@@ -32,7 +32,9 @@ public class DubboProviderDemo {
 
     public static void main(String[] args) {
 
-        SpringApplication.run(DubboProviderDemo.class,args);
+        new SpringApplicationBuilder(DubboProviderDemo.class)
+                .web(false)
+                .run(args);
 
     }
 
diff --git 
a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties
 
b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties
index 4ea4730..9583845 100644
--- 
a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties
+++ 
b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties
@@ -2,7 +2,7 @@
 spring.application.name = dubbo-provider-demo
 server.port = 9090
 management.port = 9091
-
+management.security.enabled = false
 
 # Base packages to scan Dubbo Components (e.g @Service , @Reference)
 dubbo.scan.basePackages  = com.alibaba.boot.dubbo.demo.provider.service

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

Reply via email to