Skip to content

Commit 82d6902

Browse files
authored
0.1.x (#344)
* Bug fix on test case * Polish #327 & #325 * Polish #321 * Polish #220 no program * Switch Yaml file * Update version to be 0.2.0 * Polish #218 * Update Documents * Fix the test case's bugs * Fix plugins' issues * Fix test-cases * Fix test cases * Fixes an issue on DubboMvcEndpoint * Polish: Fix a relaxed property name issue * Optimize Awaiting implementation * Remove author from JavaDoc * Refactor * Merge
1 parent c58053d commit 82d6902

File tree

31 files changed

+197
-70
lines changed

31 files changed

+197
-70
lines changed

dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboEndpointAutoConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* Dubbo {@link Endpoint} Auto Configuration
3131
*
32-
* @author <a href="mailto:[email protected]">Mercy</a>
32+
3333
* @see DubboEndpoint
3434
* @since 1.0.0
3535
*/

dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboHealthIndicatorAutoConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicator;
2020
import com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicatorProperties;
2121
import com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration;
22+
2223
import org.springframework.boot.actuate.autoconfigure.ConditionalOnEnabledHealthIndicator;
2324
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
2425
import org.springframework.boot.actuate.health.HealthIndicator;
@@ -33,7 +34,7 @@
3334
/**
3435
* Dubbo {@link DubboHealthIndicator} Auto Configuration
3536
*
36-
* @author <a href="mailto:[email protected]">Mercy</a>
37+
3738
* @see HealthIndicator
3839
* @since 1.0.0
3940
*/

dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboMvcEndpointManagementContextConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Dubbo {@link MvcEndpoint} {@link ManagementContextConfiguration}
3434
*
35-
* @author <a href="mailto:[email protected]">Mercy</a>
35+
3636
* @see ManagementContextConfiguration
3737
* @since 1.0.0
3838
*/

dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpoint.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@
1818

1919
import com.alibaba.boot.dubbo.util.DubboUtils;
2020
import com.alibaba.dubbo.common.Version;
21+
2122
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
2223
import org.springframework.boot.actuate.endpoint.Endpoint;
2324
import org.springframework.boot.context.properties.ConfigurationProperties;
2425

2526
import java.util.LinkedHashMap;
2627
import java.util.Map;
2728

28-
import static com.alibaba.boot.dubbo.util.DubboUtils.*;
29+
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_GITHUB_URL;
30+
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_MAILING_LIST;
31+
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL;
32+
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GIT_URL;
33+
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_ISSUES_URL;
2934

3035
/**
3136
* Actuator {@link Endpoint} to expose Dubbo Meta Data
3237
*
33-
* @author <a href="mailto:[email protected]">Mercy</a>
38+
3439
* @see Endpoint
3540
* @since 1.0.0
3641
*/

dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/mvc/DubboMvcEndpoint.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
/**
8484
* {@link MvcEndpoint} to expose Dubbo Metadata
8585
*
86-
* @author <a href="mailto:[email protected]">Mercy</a>
86+
8787
* @see MvcEndpoint
8888
* @since 1.0.0
8989
*/

dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.alibaba.dubbo.common.status.StatusChecker;
2121
import com.alibaba.dubbo.config.ProtocolConfig;
2222
import com.alibaba.dubbo.config.ProviderConfig;
23+
2324
import org.springframework.beans.factory.annotation.Autowired;
2425
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
2526
import org.springframework.boot.actuate.health.Health;
@@ -37,7 +38,7 @@
3738
/**
3839
* Dubbo {@link HealthIndicator}
3940
*
40-
* @author <a href="mailto:[email protected]">Mercy</a>
41+
4142
* @see HealthIndicator
4243
* @since 1.0.0
4344
*/

dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* Dubbo {@link HealthIndicator} Properties
3232
*
33-
* @author <a href="mailto:[email protected]">Mercy</a>
33+
3434
* @see HealthIndicator
3535
* @since 1.0.0
3636
*/

dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.alibaba.boot.dubbo.actuate.endpoint;
1818

1919
import com.alibaba.boot.dubbo.util.DubboUtils;
20+
2021
import org.junit.Assert;
2122
import org.junit.Test;
2223
import org.junit.runner.RunWith;
@@ -31,7 +32,7 @@
3132
/**
3233
* {@link DubboEndpoint} Test
3334
*
34-
* @author <a href="mailto:[email protected]">Mercy</a>
35+
3536
* @see DubboEndpoint
3637
* @since 1.0.0
3738
*/

dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/mvc/DubboMvcEndpointTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* {@link DubboMvcEndpoint} Test
3838
*
39-
* @author <a href="mailto:[email protected]">Mercy</a>
39+
4040
* @see DubboMvcEndpoint
4141
* @since 1.0.0
4242
*/

dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.alibaba.boot.dubbo.actuate.health;
1818

1919
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig;
20+
2021
import org.junit.Assert;
2122
import org.junit.Test;
2223
import org.junit.runner.RunWith;
@@ -33,7 +34,7 @@
3334
/**
3435
* {@link DubboHealthIndicator} Test
3536
*
36-
* @author <a href="mailto:[email protected]">Mercy</a>
37+
3738
* @see DubboHealthIndicator
3839
* @since 1.0.0
3940
*/

dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfiguration.java

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
/**
5151
* Dubbo Auto {@link Configuration}
5252
*
53-
* @author <a href="mailto:[email protected]">Mercy</a>
5453
* @see ApplicationConfig
5554
* @see Service
5655
* @see Reference
@@ -117,5 +116,4 @@ public RelaxedDubboConfigBinder relaxedDubboConfigBinder() {
117116
public ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor() {
118117
return new ReferenceAnnotationBeanPostProcessor();
119118
}
120-
121119
}

dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinder.java

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
/**
3131
* Spring Boot Relaxed {@link DubboConfigBinder} implementation
3232
*
33-
* @author <a href="mailto:[email protected]">Mercy</a>
3433
* @since 0.1.1
3534
*/
3635
public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder {

dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListener.java

+101-34
Original file line numberDiff line numberDiff line change
@@ -20,77 +20,144 @@
2020
import org.slf4j.LoggerFactory;
2121
import org.springframework.boot.SpringApplication;
2222
import org.springframework.boot.context.event.ApplicationReadyEvent;
23+
import org.springframework.context.ApplicationEvent;
2324
import org.springframework.context.ApplicationListener;
25+
import org.springframework.context.event.ContextClosedEvent;
26+
import org.springframework.context.event.SmartApplicationListener;
27+
import org.springframework.util.ObjectUtils;
2428

2529
import java.util.concurrent.ExecutorService;
2630
import java.util.concurrent.Executors;
2731
import java.util.concurrent.atomic.AtomicBoolean;
32+
import java.util.concurrent.locks.Condition;
33+
import java.util.concurrent.locks.Lock;
34+
import java.util.concurrent.locks.ReentrantLock;
2835

2936
/**
3037
* Awaiting Non-Web Spring Boot {@link ApplicationListener}
3138
*
32-
* @author <a href="mailto:[email protected]">Mercy</a>
3339
* @since 0.1.1
3440
*/
35-
public class AwaitingNonWebApplicationListener implements ApplicationListener<ApplicationReadyEvent> {
41+
public class AwaitingNonWebApplicationListener implements SmartApplicationListener {
3642

3743
private static final Logger logger = LoggerFactory.getLogger(AwaitingNonWebApplicationListener.class);
3844

39-
private static final ExecutorService executorService = Executors.newSingleThreadExecutor();
40-
41-
private static final AtomicBoolean shutdownHookRegistered = new AtomicBoolean(false);
45+
private static final Class<? extends ApplicationEvent>[] SUPPORTED_APPLICATION_EVENTS =
46+
of(ApplicationReadyEvent.class, ContextClosedEvent.class);
4247

4348
private static final AtomicBoolean awaited = new AtomicBoolean(false);
4449

50+
private final Lock lock = new ReentrantLock();
51+
52+
private final Condition condition = lock.newCondition();
53+
54+
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
55+
56+
private static <T> T[] of(T... values) {
57+
return values;
58+
}
59+
60+
@Override
61+
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
62+
return ObjectUtils.containsElement(SUPPORTED_APPLICATION_EVENTS, eventType);
63+
}
64+
65+
@Override
66+
public boolean supportsSourceType(Class<?> sourceType) {
67+
return true;
68+
}
69+
4570
@Override
46-
public void onApplicationEvent(ApplicationReadyEvent event) {
71+
public void onApplicationEvent(ApplicationEvent event) {
72+
if (event instanceof ApplicationReadyEvent) {
73+
onApplicationReadyEvent((ApplicationReadyEvent) event);
74+
} else if (event instanceof ContextClosedEvent) {
75+
onContextClosedEvent((ContextClosedEvent) event);
76+
}
77+
}
78+
79+
@Override
80+
public int getOrder() {
81+
return LOWEST_PRECEDENCE;
82+
}
83+
84+
protected void onApplicationReadyEvent(ApplicationReadyEvent event) {
4785

4886
final SpringApplication springApplication = event.getSpringApplication();
4987

5088
if (springApplication.isWebEnvironment()) {
5189
return;
5290
}
5391

92+
await();
93+
94+
}
95+
96+
protected void onContextClosedEvent(ContextClosedEvent event) {
97+
release();
98+
shutdown();
99+
}
100+
101+
protected void await() {
102+
103+
// has been waited, return immediately
104+
if (awaited.get()) {
105+
return;
106+
}
107+
54108
executorService.execute(new Runnable() {
55109
@Override
56110
public void run() {
57-
58-
synchronized (springApplication) {
59-
if (logger.isInfoEnabled()) {
60-
logger.info(" [Dubbo] Current Spring Boot Application is await...");
61-
}
62-
while (!awaited.get()) {
63-
try {
64-
springApplication.wait();
65-
} catch (InterruptedException e) {
66-
Thread.currentThread().interrupt();
111+
executeMutually(new Runnable() {
112+
@Override
113+
public void run() {
114+
while (!awaited.get()) {
115+
if (logger.isInfoEnabled()) {
116+
logger.info(" [Dubbo] Current Spring Boot Application is await...");
117+
}
118+
try {
119+
condition.await();
120+
} catch (InterruptedException e) {
121+
Thread.currentThread().interrupt();
122+
}
67123
}
68124
}
69-
}
125+
});
70126
}
71127
});
128+
}
72129

73-
// register ShutdownHook
74-
if (shutdownHookRegistered.compareAndSet(false, true)) {
75-
registerShutdownHook(new Thread(new Runnable() {
76-
@Override
77-
public void run() {
78-
synchronized (springApplication) {
79-
if (awaited.compareAndSet(false, true)) {
80-
springApplication.notifyAll();
81-
if (logger.isInfoEnabled()) {
82-
logger.info(" [Dubbo] Current Spring Boot Application is about to shutdown...");
83-
}
84-
// Shutdown executorService
85-
executorService.shutdown();
86-
}
130+
protected void release() {
131+
executeMutually(new Runnable() {
132+
@Override
133+
public void run() {
134+
while (awaited.compareAndSet(false, true)) {
135+
if (logger.isInfoEnabled()) {
136+
logger.info(" [Dubbo] Current Spring Boot Application is about to shutdown...");
87137
}
138+
condition.signalAll();
88139
}
89-
}));
140+
}
141+
});
142+
}
143+
144+
private void shutdown() {
145+
if (!executorService.isShutdown()) {
146+
// Shutdown executorService
147+
executorService.shutdown();
148+
}
149+
}
150+
151+
private void executeMutually(Runnable runnable) {
152+
try {
153+
lock.lock();
154+
runnable.run();
155+
} finally {
156+
lock.unlock();
90157
}
91158
}
92159

93-
private void registerShutdownHook(Thread thread) {
94-
Runtime.getRuntime().addShutdownHook(thread);
160+
static AtomicBoolean getAwaited() {
161+
return awaited;
95162
}
96163
}

dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListener.java

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
* {@link ConfigUtils#getProperties() Dubbo Config}.
4040
* {@link AbstractConfig Dubbo Config} on {@link ApplicationEnvironmentPreparedEvent}.
4141
*
42-
* @author <a href="mailto:[email protected]">Mercy</a>
4342
* @see ConfigUtils
4443
* @since 1.0.0
4544
*/

dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListener.java

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
/**
3434
* Dubbo Welcome Logo {@link ApplicationListener}
3535
*
36-
* @author <a href="mailto:[email protected]">Mercy</a>
3736
* @see ApplicationListener
3837
* @since 1.0.0
3938
*/

dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/DubboUtils.java

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
/**
2727
* The utilities class for Dubbo
2828
*
29-
* @author <a href="mailto:[email protected]">Mercy</a>
3029
* @since 1.0.0
3130
*/
3231
public abstract class DubboUtils {

dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/EnvironmentUtils.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
*/
1717
package com.alibaba.boot.dubbo.util;
1818

19-
import org.springframework.core.env.*;
19+
import org.springframework.core.env.CompositePropertySource;
20+
import org.springframework.core.env.ConfigurableEnvironment;
21+
import org.springframework.core.env.EnumerablePropertySource;
22+
import org.springframework.core.env.Environment;
23+
import org.springframework.core.env.MutablePropertySources;
24+
import org.springframework.core.env.PropertySource;
2025
import org.springframework.util.ObjectUtils;
2126

2227
import java.util.Collections;
@@ -26,7 +31,6 @@
2631
/**
2732
* The utilities class for {@link Environment}
2833
*
29-
* @author <a href="mailto:[email protected]">Mercy</a>
3034
* @see Environment
3135
* @since 1.0.0
3236
*/

dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
/**
4444
* {@link DubboAutoConfiguration} Test On multiple Dubbo Configuration
4545
*
46-
* @author <a href="mailto:[email protected]">Mercy</a>
4746
* @since 1.0.0
4847
*/
4948
@RunWith(SpringJUnit4ClassRunner.class)

0 commit comments

Comments
 (0)