Skip to content

Commit f3a9ae2

Browse files
authored
Merge pull request #6 from lvyahui8/develop
Develop merge into master
2 parents 6646564 + e90571f commit f3a9ae2

File tree

11 files changed

+59
-32
lines changed

11 files changed

+59
-32
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
## 使用方法
4444

45-
### 配置
45+
### 1. 配置
4646

4747
pom.xml
4848

@@ -61,13 +61,13 @@ application.properties
6161
io.github.lvyahui8.spring.base-packages=io.github.lvyahui8.spring.example
6262
```
6363

64-
### 添加注解
64+
### 2. 添加注解
6565

6666
- `@DataProvider` 定义数据提供者
6767
- `@DataConsumer` 定义方法参数依赖类型为其他接口返回值, 其他接口是一个`@DataProvider`
6868
- `@InvokeParameter` 定义方法参数依赖类型为用户输入值
6969

70-
### 查询
70+
### 3. 查询
7171

7272
Spring Bean `DataBeanAggregateQueryFacade` 查询指定的数据的门面
7373

README_EN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Of course, in an extremely high concurrent scenario, the parallel call interface
4343

4444
## Getting Started
4545

46-
### Configuration
46+
### 1. Configuration
4747

4848
pom.xml
4949

@@ -62,15 +62,15 @@ application.properties
6262
io.github.lvyahui8.spring.base-packages=io.github.lvyahui8.spring.example
6363
```
6464

65-
### Annotation
65+
### 2. Annotation
6666

6767
- `@DataProvider`: define the data provider
6868

6969
- `@DataConsumer`: define the method parameter dependency type as return the value of other interfaces, the other interface is a `@DataProvider`
7070

7171
- `@InvokeParameter`: define the method parameter dependency type as the user input value
7272

73-
### Query
73+
### 3. Query
7474

7575
Spring Bean `dataBeanAggregateQueryFacade` query data facade API
7676

pom.xml

Lines changed: 1 addition & 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.1.0-SNAPSHOT</version>
23+
<version>1.1.0</version>
2424
<modules>
2525
<module>spring-boot-data-aggregator-core</module>
2626
<module>spring-boot-data-aggregator-autoconfigure</module>

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.1.0-SNAPSHOT</version>
8+
<version>1.1.0</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: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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.AggregateQueryInterceptor;
67
import io.github.lvyahui8.spring.aggregate.interceptor.AggregateQueryInterceptorChain;
78
import io.github.lvyahui8.spring.aggregate.interceptor.impl.AggregateQueryInterceptorChainImpl;
89
import io.github.lvyahui8.spring.aggregate.model.DataProvideDefinition;
@@ -24,14 +25,16 @@
2425
import org.springframework.context.ApplicationContextAware;
2526
import org.springframework.context.annotation.Bean;
2627
import org.springframework.context.annotation.Configuration;
28+
import org.springframework.core.Ordered;
2729
import org.springframework.core.annotation.AnnotationUtils;
30+
import org.springframework.core.annotation.Order;
2831
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
2932
import org.springframework.util.Assert;
3033
import org.springframework.util.StringUtils;
3134

3235
import java.lang.reflect.Method;
3336
import java.lang.reflect.Modifier;
34-
import java.util.Set;
37+
import java.util.*;
3538
import java.util.concurrent.ExecutorService;
3639
import java.util.concurrent.LinkedBlockingDeque;
3740
import java.util.concurrent.ThreadPoolExecutor;
@@ -104,7 +107,7 @@ public DataBeanAggregateQueryService dataBeanAggregateQueryService (
104107
* @return
105108
*/
106109
@Bean(name = "aggregateExecutorService")
107-
@ConditionalOnMissingBean(name = "aggregateExecutorService")
110+
@ConditionalOnMissingBean(name = "aggregateExecutorService",value=ExecutorService.class)
108111
public ExecutorService aggregateExecutorService() {
109112
return new ThreadPoolExecutor(
110113
properties.getThreadNumber(),
@@ -129,6 +132,24 @@ public DataProviderRepository dataProviderRepository() {
129132
@Bean(name = "aggregateQueryInterceptorChain")
130133
@ConditionalOnMissingBean(AggregateQueryInterceptorChain.class)
131134
public AggregateQueryInterceptorChain aggregateQueryInterceptorChain() {
132-
return new AggregateQueryInterceptorChainImpl();
135+
Map<String, AggregateQueryInterceptor> interceptorMap = applicationContext.getBeansOfType(AggregateQueryInterceptor.class);
136+
AggregateQueryInterceptorChainImpl interceptorChain = new AggregateQueryInterceptorChainImpl();
137+
if(interceptorMap != null && ! interceptorMap.isEmpty()) {
138+
List<AggregateQueryInterceptor> interceptors = new ArrayList<>(interceptorMap.values());
139+
interceptors.sort(new Comparator<AggregateQueryInterceptor>() {
140+
@Override
141+
public int compare(AggregateQueryInterceptor o1, AggregateQueryInterceptor o2) {
142+
Order order1 = o1.getClass().getAnnotation(Order.class);
143+
Order order2 = o2.getClass().getAnnotation(Order.class);
144+
int oi1 = order1 == null ? Ordered.LOWEST_PRECEDENCE : order1.value();
145+
int oi2 = order2 == null ? Ordered.LOWEST_PRECEDENCE : order2.value();
146+
return oi1 - oi2;
147+
}
148+
});
149+
for (AggregateQueryInterceptor interceptor : interceptors) {
150+
interceptorChain.addInterceptor(interceptor);
151+
}
152+
}
153+
return interceptorChain;
133154
}
134155
}

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.1.0-SNAPSHOT</version>
8+
<version>1.1.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

spring-boot-data-aggregator-example/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.1.0-SNAPSHOT</version>
8+
<version>1.1.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/configuration/AggregatorCustomConfiguration.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package io.github.lvyahui8.spring.example.configuration;
22

3-
import io.github.lvyahui8.spring.aggregate.interceptor.AggregateQueryInterceptorChain;
4-
import io.github.lvyahui8.spring.aggregate.interceptor.impl.AggregateQueryInterceptorChainImpl;
5-
import io.github.lvyahui8.spring.example.interceptor.SampleAggregateQueryInterceptor;
6-
import org.springframework.beans.factory.annotation.Qualifier;
73
import org.springframework.context.annotation.Bean;
84
import org.springframework.context.annotation.Configuration;
95
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
@@ -30,18 +26,4 @@ public ExecutorService aggregateExecutorService() {
3026
new LinkedBlockingDeque<>(1024),
3127
new CustomizableThreadFactory("example-async"));
3228
}
33-
34-
/**
35-
* 自定义拦截器处理链
36-
*
37-
* @param sampleAggregateQueryInterceptor
38-
* @return
39-
*/
40-
@Bean(name = "aggregateQueryInterceptorChain")
41-
public AggregateQueryInterceptorChain aggregateQueryInterceptorChain(
42-
@Qualifier("sampleAggregateQueryInterceptor") SampleAggregateQueryInterceptor sampleAggregateQueryInterceptor) {
43-
AggregateQueryInterceptorChainImpl aggregateQueryInterceptorChain = new AggregateQueryInterceptorChainImpl();
44-
aggregateQueryInterceptorChain.addInterceptor(sampleAggregateQueryInterceptor);
45-
return aggregateQueryInterceptorChain;
46-
}
4729
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.github.lvyahui8.spring.example.interceptor;
2+
3+
import io.github.lvyahui8.spring.aggregate.context.AggregationContext;
4+
import io.github.lvyahui8.spring.aggregate.interceptor.impl.AggregateQueryInterceptorAdapter;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.core.annotation.Order;
7+
import org.springframework.stereotype.Component;
8+
9+
/**
10+
* @author lvyahui (lvyahui8@gmail.com,lvyahui8@126.com)
11+
* @since 2019/9/7 23:02
12+
*/
13+
@Component
14+
@Order(1)
15+
@Slf4j
16+
public class PerSetupAggregateQueryInterceptor extends AggregateQueryInterceptorAdapter {
17+
@Override
18+
public boolean querySubmitted(AggregationContext aggregationContext) {
19+
log.info("current thread {}", Thread.currentThread().getName());
20+
return super.querySubmitted(aggregationContext);
21+
}
22+
}

spring-boot-data-aggregator-example/src/main/java/io/github/lvyahui8/spring/example/interceptor/SampleAggregateQueryInterceptor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import io.github.lvyahui8.spring.aggregate.interceptor.AggregateQueryInterceptor;
55
import io.github.lvyahui8.spring.aggregate.model.DataProvideDefinition;
66
import lombok.extern.slf4j.Slf4j;
7+
import org.springframework.core.annotation.Order;
78
import org.springframework.stereotype.Component;
89

910
/**
1011
* @author lvyahui (lvyahui8@gmail.com,lvyahui8@126.com)
1112
* @since 2019/8/4 17:24
1213
*/
1314
@Component
15+
@Order(2)
1416
@Slf4j
1517
public class SampleAggregateQueryInterceptor implements AggregateQueryInterceptor {
1618
@Override

0 commit comments

Comments
 (0)