Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.1.x #344

Merged
merged 24 commits into from
Dec 27, 2018
Merged

0.1.x #344

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
87806df
Bug fix on test case
mercyblitz Dec 14, 2018
276b7db
Polish apache/incubator-dubbo-spring-boot-project#327 & apache/incuba…
mercyblitz Dec 14, 2018
93be35d
Polish apache/incubator-dubbo-spring-boot-project#321
mercyblitz Dec 14, 2018
7bad4d2
Polish apache/incubator-dubbo-spring-boot-project#220 no program
mercyblitz Dec 14, 2018
c092b3f
Switch Yaml file
mercyblitz Dec 14, 2018
ff9df81
Update version to be 0.2.0
mercyblitz Dec 14, 2018
c104c2a
Polish apache/incubator-dubbo-spring-boot-project#218
mercyblitz Dec 18, 2018
0e8d108
Update Documents
mercyblitz Dec 18, 2018
6f871e6
Fix the test case's bugs
mercyblitz Dec 18, 2018
d8ad05f
Fix plugins' issues
mercyblitz Dec 18, 2018
feec9ce
Merge branch '0.1.x' into 0.1.x
mercyblitz Dec 18, 2018
04b1b46
Merge pull request #2 from apache/0.1.x
mercyblitz Dec 18, 2018
5149000
Fix test-cases
Dec 18, 2018
d8fb065
Fix test cases
mercyblitz Dec 18, 2018
0fbd38f
Merge branch '0.1.x' of github.com:mercyblitz/incubator-dubbo-spring-…
mercyblitz Dec 18, 2018
696d2ad
Fixes an issue on DubboMvcEndpoint
mercyblitz Dec 18, 2018
bedf686
Polish: Fix a relaxed property name issue
mercyblitz Dec 18, 2018
3460ecf
Merge branch '0.1.x' into 0.1.x
mercyblitz Dec 18, 2018
4d796b0
Optimize Awaiting implementation
mercyblitz Dec 21, 2018
04227e3
Merge remote-tracking branch 'origin/0.1.x' into 0.1.x
mercyblitz Dec 21, 2018
90b8687
Remove author from JavaDoc
mercyblitz Dec 21, 2018
5fec0ad
Refactor
mercyblitz Dec 21, 2018
f390991
Merge branch '0.1.x' into 0.1.x
mercyblitz Dec 27, 2018
73ca6d6
Merge
mercyblitz Dec 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* Dubbo {@link Endpoint} Auto Configuration
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see DubboEndpoint
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicator;
import com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicatorProperties;
import com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration;

import org.springframework.boot.actuate.autoconfigure.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration;
import org.springframework.boot.actuate.health.HealthIndicator;
Expand All @@ -33,7 +34,7 @@
/**
* Dubbo {@link DubboHealthIndicator} Auto Configuration
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see HealthIndicator
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
* Dubbo {@link MvcEndpoint} {@link ManagementContextConfiguration}
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see ManagementContextConfiguration
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@

import com.alibaba.boot.dubbo.util.DubboUtils;
import com.alibaba.dubbo.common.Version;

import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.LinkedHashMap;
import java.util.Map;

import static com.alibaba.boot.dubbo.util.DubboUtils.*;
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_GITHUB_URL;
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_MAILING_LIST;
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL;
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GIT_URL;
import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_ISSUES_URL;

/**
* Actuator {@link Endpoint} to expose Dubbo Meta Data
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see Endpoint
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
/**
* {@link MvcEndpoint} to expose Dubbo Metadata
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see MvcEndpoint
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alibaba.dubbo.common.status.StatusChecker;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.ProviderConfig;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
Expand All @@ -37,7 +38,7 @@
/**
* Dubbo {@link HealthIndicator}
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see HealthIndicator
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Dubbo {@link HealthIndicator} Properties
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see HealthIndicator
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alibaba.boot.dubbo.actuate.endpoint;

import com.alibaba.boot.dubbo.util.DubboUtils;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -31,7 +32,7 @@
/**
* {@link DubboEndpoint} Test
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see DubboEndpoint
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* {@link DubboMvcEndpoint} Test
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see DubboMvcEndpoint
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alibaba.boot.dubbo.actuate.health;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -33,7 +34,7 @@
/**
* {@link DubboHealthIndicator} Test
*
* @author <a href="mailto:[email protected]">Mercy</a>

* @see DubboHealthIndicator
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
/**
* Dubbo Auto {@link Configuration}
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @see ApplicationConfig
* @see Service
* @see Reference
Expand Down Expand Up @@ -117,5 +116,4 @@ public RelaxedDubboConfigBinder relaxedDubboConfigBinder() {
public ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor() {
return new ReferenceAnnotationBeanPostProcessor();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
/**
* Spring Boot Relaxed {@link DubboConfigBinder} implementation
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 0.1.1
*/
public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,77 +20,144 @@
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.util.ObjectUtils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
* Awaiting Non-Web Spring Boot {@link ApplicationListener}
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 0.1.1
*/
public class AwaitingNonWebApplicationListener implements ApplicationListener<ApplicationReadyEvent> {
public class AwaitingNonWebApplicationListener implements SmartApplicationListener {

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 Class<? extends ApplicationEvent>[] SUPPORTED_APPLICATION_EVENTS =
of(ApplicationReadyEvent.class, ContextClosedEvent.class);

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

private final Lock lock = new ReentrantLock();

private final Condition condition = lock.newCondition();

private final ExecutorService executorService = Executors.newSingleThreadExecutor();

private static <T> T[] of(T... values) {
return values;
}

@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
return ObjectUtils.containsElement(SUPPORTED_APPLICATION_EVENTS, eventType);
}

@Override
public boolean supportsSourceType(Class<?> sourceType) {
return true;
}

@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ApplicationReadyEvent) {
onApplicationReadyEvent((ApplicationReadyEvent) event);
} else if (event instanceof ContextClosedEvent) {
onContextClosedEvent((ContextClosedEvent) event);
}
}

@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
}

protected void onApplicationReadyEvent(ApplicationReadyEvent event) {

final SpringApplication springApplication = event.getSpringApplication();

if (springApplication.isWebEnvironment()) {
return;
}

await();

}

protected void onContextClosedEvent(ContextClosedEvent event) {
release();
shutdown();
}

protected void await() {

// has been waited, return immediately
if (awaited.get()) {
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();
executeMutually(new Runnable() {
@Override
public void run() {
while (!awaited.get()) {
if (logger.isInfoEnabled()) {
logger.info(" [Dubbo] Current Spring Boot Application is await...");
}
try {
condition.await();
} 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();
}
protected void release() {
executeMutually(new Runnable() {
@Override
public void run() {
while (awaited.compareAndSet(false, true)) {
if (logger.isInfoEnabled()) {
logger.info(" [Dubbo] Current Spring Boot Application is about to shutdown...");
}
condition.signalAll();
}
}));
}
});
}

private void shutdown() {
if (!executorService.isShutdown()) {
// Shutdown executorService
executorService.shutdown();
}
}

private void executeMutually(Runnable runnable) {
try {
lock.lock();
runnable.run();
} finally {
lock.unlock();
}
}

private void registerShutdownHook(Thread thread) {
Runtime.getRuntime().addShutdownHook(thread);
static AtomicBoolean getAwaited() {
return awaited;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
* {@link ConfigUtils#getProperties() Dubbo Config}.
* {@link AbstractConfig Dubbo Config} on {@link ApplicationEnvironmentPreparedEvent}.
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @see ConfigUtils
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
/**
* Dubbo Welcome Logo {@link ApplicationListener}
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @see ApplicationListener
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
/**
* The utilities class for Dubbo
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 1.0.0
*/
public abstract class DubboUtils {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
*/
package com.alibaba.boot.dubbo.util;

import org.springframework.core.env.*;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.util.ObjectUtils;

import java.util.Collections;
Expand All @@ -26,7 +31,6 @@
/**
* The utilities class for {@link Environment}
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @see Environment
* @since 1.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
/**
* {@link DubboAutoConfiguration} Test On multiple Dubbo Configuration
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 1.0.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
Expand Down
Loading