Skip to content

Commit 6646564

Browse files
authored
Merge pull request #5 from lvyahui8/develop
Develop merge into master
2 parents ef61097 + bb3d492 commit 6646564

File tree

24 files changed

+482
-175
lines changed

24 files changed

+482
-175
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: java
2+
jdk:
3+
- openjdk8
4+
sudo: false
5+
script: "mvn cobertura:cobertura"
6+
after_success:
7+
- bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Spring Boot 并发数据聚合库
22

3+
[![Build Status](https://travis-ci.org/lvyahui8/spring-boot-data-aggregator.svg?branch=develop)](https://travis-ci.org/lvyahui8/spring-boot-data-aggregator)
4+
[![Codecov](https://codecov.io/gh/lvyahui8/spring-boot-data-aggregator/branch/develop/graph/badge.svg)](https://codecov.io/gh/lvyahui8/spring-boot-data-aggregator/branch/develop)
35
[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
46
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.lvyahui8/spring-boot-data-aggregator-starter/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.lvyahui8/spring-boot-data-aggregator-starter)
57
[![GitHub release](https://img.shields.io/github/release/lvyahui8/spring-boot-data-aggregator.svg)](https://github.com/lvyahui8/spring-boot-data-aggregator/releases)

README_EN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Spring Boot Data Parallel Aggregation Library
22

3+
[![Build Status](https://travis-ci.org/lvyahui8/spring-boot-data-aggregator.svg?branch=develop)](https://travis-ci.org/lvyahui8/spring-boot-data-aggregator)
4+
[![Codecov](https://codecov.io/gh/lvyahui8/spring-boot-data-aggregator/branch/develop/graph/badge.svg)](https://codecov.io/gh/lvyahui8/spring-boot-data-aggregator/branch/develop)
35
[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
46
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.lvyahui8/spring-boot-data-aggregator-starter/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.lvyahui8/spring-boot-data-aggregator-starter)
57
[![GitHub release](https://img.shields.io/github/release/lvyahui8/spring-boot-data-aggregator.svg)](https://github.com/lvyahui8/spring-boot-data-aggregator/releases)

pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
<groupId>io.github.lvyahui8</groupId>
2222
<artifactId>spring-boot-data-aggregator</artifactId>
23-
<version>1.0.5</version>
23+
<version>1.1.0-SNAPSHOT</version>
2424
<modules>
2525
<module>spring-boot-data-aggregator-core</module>
2626
<module>spring-boot-data-aggregator-autoconfigure</module>
@@ -223,5 +223,19 @@ limitations under the License.
223223
</plugin>
224224
</plugins>
225225
</pluginManagement>
226+
<plugins>
227+
<plugin>
228+
<groupId>org.codehaus.mojo</groupId>
229+
<artifactId>cobertura-maven-plugin</artifactId>
230+
<version>2.7</version>
231+
<configuration>
232+
<formats>
233+
<format>html</format>
234+
<format>xml</format>
235+
</formats>
236+
<check />
237+
</configuration>
238+
</plugin>
239+
</plugins>
226240
</build>
227241
</project>

spring-boot-data-aggregator-autoconfigure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>spring-boot-data-aggregator</artifactId>
77
<groupId>io.github.lvyahui8</groupId>
8-
<version>1.0.5</version>
8+
<version>1.1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

spring-boot-data-aggregator-autoconfigure/src/main/java/io/github/lvyahui8/spring/autoconfigure/BeanAggregateAutoConfiguration.java

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.github.lvyahui8.spring.aggregate.config.RuntimeSettings;
44
import io.github.lvyahui8.spring.aggregate.facade.DataBeanAggregateQueryFacade;
55
import io.github.lvyahui8.spring.aggregate.facade.impl.DataBeanAggregateQueryFacadeImpl;
6+
import io.github.lvyahui8.spring.aggregate.interceptor.AggregateQueryInterceptorChain;
7+
import io.github.lvyahui8.spring.aggregate.interceptor.impl.AggregateQueryInterceptorChainImpl;
68
import io.github.lvyahui8.spring.aggregate.model.DataProvideDefinition;
79
import io.github.lvyahui8.spring.aggregate.repository.DataProviderRepository;
810
import io.github.lvyahui8.spring.aggregate.repository.impl.DataProviderRepositoryImpl;
@@ -15,6 +17,7 @@
1517
import org.reflections.scanners.MethodAnnotationsScanner;
1618
import org.springframework.beans.BeansException;
1719
import org.springframework.beans.factory.annotation.Autowired;
20+
import org.springframework.beans.factory.annotation.Qualifier;
1821
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
1922
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2023
import org.springframework.context.ApplicationContext;
@@ -54,22 +57,52 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
5457

5558
@Bean
5659
@ConditionalOnMissingBean
57-
public DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade() {
58-
return new DataBeanAggregateQueryFacadeImpl(dataBeanAggregateQueryService());
60+
public DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade(
61+
@Qualifier("dataProviderRepository") DataProviderRepository dataProviderRepository) {
62+
return new DataBeanAggregateQueryFacadeImpl(dataBeanAggregateQueryService(dataProviderRepository));
5963
}
6064

6165
@Bean
6266
@ConditionalOnMissingBean
63-
public DataBeanAggregateQueryService dataBeanAggregateQueryService () {
64-
DataProviderRepository repository = new DataProviderRepositoryImpl();
65-
scanProviders(repository);
66-
DataBeanAggregateQueryServiceImpl service = new DataBeanAggregateQueryServiceImpl(repository);
67-
service.setRuntimeSettings(createRuntimeSettings());
67+
public DataBeanAggregateQueryService dataBeanAggregateQueryService (
68+
@Qualifier("dataProviderRepository") DataProviderRepository dataProviderRepository) {
69+
if(properties.getBasePackages() != null) {
70+
for (String basePackage : properties.getBasePackages()) {
71+
Reflections reflections = new Reflections(basePackage, new MethodAnnotationsScanner());
72+
Set<Method> providerMethods = reflections.getMethodsAnnotatedWith(DataProvider.class);
73+
for (Method method : providerMethods) {
74+
DataProvider beanProvider = AnnotationUtils.findAnnotation(method, DataProvider.class);
75+
@SuppressWarnings("ConstantConditions")
76+
String dataId = beanProvider.id();
77+
Assert.isTrue(Modifier.isPublic(method.getModifiers()),"data provider method must be public");
78+
Assert.isTrue(! StringUtils.isEmpty(dataId),"data id must be not null!");
79+
DataProvideDefinition provider = DefinitionUtils.getProvideDefinition(method);
80+
provider.setId(dataId);
81+
provider.setIdempotent(beanProvider.idempotent());
82+
provider.setTimeout(beanProvider.timeout() > 0 ? beanProvider.timeout() : properties.getDefaultTimeout());
83+
dataProviderRepository.put(provider);
84+
}
85+
}
86+
}
87+
DataBeanAggregateQueryServiceImpl service = new DataBeanAggregateQueryServiceImpl();
88+
RuntimeSettings runtimeSettings = new RuntimeSettings();
89+
runtimeSettings.setEnableLogging(properties.getEnableLogging() != null
90+
? properties.getEnableLogging() : false);
91+
runtimeSettings.setIgnoreException(properties.isIgnoreException());
92+
runtimeSettings.setTimeout(properties.getDefaultTimeout());
93+
service.setRepository(dataProviderRepository);
94+
service.setRuntimeSettings(runtimeSettings);
6895
service.setExecutorService(aggregateExecutorService());
96+
service.setInterceptorChain(aggregateQueryInterceptorChain());
6997
service.setApplicationContext(applicationContext);
7098
return service;
7199
}
72100

101+
/**
102+
* 允许用户自定义线程池
103+
*
104+
* @return
105+
*/
73106
@Bean(name = "aggregateExecutorService")
74107
@ConditionalOnMissingBean(name = "aggregateExecutorService")
75108
public ExecutorService aggregateExecutorService() {
@@ -81,39 +114,21 @@ public ExecutorService aggregateExecutorService() {
81114
new CustomizableThreadFactory(properties.getThreadPrefix()));
82115
}
83116

84-
private void scanProviders(DataProviderRepository repository) {
85-
if(properties.getBasePackages() != null) {
86-
for (String basePackage : properties.getBasePackages()) {
87-
Reflections reflections = new Reflections(basePackage, new MethodAnnotationsScanner());
88-
Set<Method> providerMethods = reflections.getMethodsAnnotatedWith(DataProvider.class);
89-
for (Method method : providerMethods) {
90-
dealProviderMethod(repository, method);
91-
}
92-
}
93-
}
94-
}
95-
96-
private void dealProviderMethod(DataProviderRepository repository, Method method) {
97-
DataProvider beanProvider = AnnotationUtils.findAnnotation(method, DataProvider.class);
98-
@SuppressWarnings("ConstantConditions")
99-
String dataId = beanProvider.id();
100-
Assert.isTrue(Modifier.isPublic(method.getModifiers()),"data provider method must be public");
101-
Assert.isTrue(! StringUtils.isEmpty(dataId),"data id must be not null!");
102-
DataProvideDefinition provider = DefinitionUtils.getProvideDefinition(method);
103-
provider.setId(dataId);
104-
provider.setIdempotent(beanProvider.idempotent());
105-
provider.setTimeout(beanProvider.timeout() > 0 ? beanProvider.timeout() : properties.getDefaultTimeout());
106-
repository.put(dataId,provider);
117+
/**
118+
* 允许用户自定义provider存储
119+
*
120+
* @return
121+
*/
122+
@Bean(name = "dataProviderRepository")
123+
@ConditionalOnMissingBean(DataProviderRepository.class)
124+
public DataProviderRepository dataProviderRepository() {
125+
return new DataProviderRepositoryImpl();
107126
}
108127

109128

110-
private RuntimeSettings createRuntimeSettings() {
111-
RuntimeSettings runtimeSettings = new RuntimeSettings();
112-
runtimeSettings.setEnableLogging(properties.getEnableLogging() != null
113-
? properties.getEnableLogging() : false);
114-
runtimeSettings.setIgnoreException(properties.isIgnoreException());
115-
runtimeSettings.setTimeout(properties.getDefaultTimeout());
116-
return runtimeSettings;
129+
@Bean(name = "aggregateQueryInterceptorChain")
130+
@ConditionalOnMissingBean(AggregateQueryInterceptorChain.class)
131+
public AggregateQueryInterceptorChain aggregateQueryInterceptorChain() {
132+
return new AggregateQueryInterceptorChainImpl();
117133
}
118-
119134
}

spring-boot-data-aggregator-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>spring-boot-data-aggregator</artifactId>
77
<groupId>io.github.lvyahui8</groupId>
8-
<version>1.0.5</version>
8+
<version>1.1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

spring-boot-data-aggregator-core/src/main/java/io/github/lvyahui8/spring/aggregate/context/AggregationContext.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.lvyahui8.spring.aggregate.context;
22

33
import io.github.lvyahui8.spring.aggregate.model.DataProvideDefinition;
4+
import io.github.lvyahui8.spring.aggregate.model.InvokeSignature;
45
import lombok.Data;
56

67
import java.util.Map;
@@ -14,13 +15,13 @@ public class AggregationContext {
1415
/**
1516
* 发起一次递归查询的主调线程
1617
*/
17-
Thread rootThread;
18+
Thread rootThread;
1819
/**
1920
* 根provider
2021
*/
21-
DataProvideDefinition rootProvideDefinition;
22+
DataProvideDefinition rootProvideDefinition;
2223
/**
2324
* 此次查询生命周期中的缓存
2425
*/
25-
Map<String,Object> cacheMap;
26+
Map<InvokeSignature,Object> cacheMap;
2627
}

spring-boot-data-aggregator-core/src/main/java/io/github/lvyahui8/spring/aggregate/facade/impl/DataBeanAggregateQueryFacadeImpl.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.lvyahui8.spring.aggregate.facade.impl;
22

3-
import io.github.lvyahui8.spring.aggregate.consts.AggregationConstant;
43
import io.github.lvyahui8.spring.aggregate.facade.DataBeanAggregateQueryFacade;
54
import io.github.lvyahui8.spring.aggregate.func.MultipleArgumentsFunction;
65
import io.github.lvyahui8.spring.aggregate.model.DataProvideDefinition;
@@ -13,7 +12,6 @@
1312
import java.lang.reflect.Modifier;
1413
import java.util.Collections;
1514
import java.util.Map;
16-
import java.util.concurrent.ConcurrentHashMap;
1715

1816

1917
/**
@@ -35,8 +33,7 @@ public <T> T get(String id, Map<String,Object> invokeParams, Class<T> clazz) thr
3533
if(invokeParams == null) {
3634
invokeParams = Collections.emptyMap();
3735
}
38-
return dataBeanAggregateQueryService.get(id,invokeParams,clazz,
39-
new ConcurrentHashMap<>(AggregationConstant.DEFAULT_INITIAL_CAPACITY));
36+
return dataBeanAggregateQueryService.get(id,invokeParams,clazz);
4037
}
4138

4239
@Override
@@ -74,8 +71,7 @@ public <T> T get(Map<String, Object> invokeParams, MultipleArgumentsFunction<T>
7471
}
7572
try {
7673
@SuppressWarnings("unchecked")
77-
T ret = (T) dataBeanAggregateQueryService.get(provider, invokeParams, applyMethod.getReturnType(),
78-
new ConcurrentHashMap<>(AggregationConstant.DEFAULT_INITIAL_CAPACITY));
74+
T ret = (T) dataBeanAggregateQueryService.get(provider, invokeParams, applyMethod.getReturnType());
7975

8076
return ret;
8177
} finally {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @author lvyahui (lvyahui8@gmail.com,lvyahui8@126.com)
1010
* @since 2019/7/21 22:28
1111
*/
12-
public interface AbstractAggregateQueryInterceptor {
12+
public interface AggregateQueryInterceptor {
1313
/**
1414
* 查询正常提交, Context已经创建
1515
*
@@ -23,9 +23,8 @@ public interface AbstractAggregateQueryInterceptor {
2323
*
2424
* @param aggregationContext 查询上下文
2525
* @param provideDefinition 将被执行的Provider
26-
* @return 返回为true才继续执行
2726
*/
28-
boolean queryBefore(AggregationContext aggregationContext, DataProvideDefinition provideDefinition);
27+
void queryBefore(AggregationContext aggregationContext, DataProvideDefinition provideDefinition);
2928

3029
/**
3130
* 每个Provider方法执行成功之后, 调用此方法. 存在并发调用

0 commit comments

Comments
 (0)