Skip to content

Commit 6ac2892

Browse files
committed
update
1 parent 17845e6 commit 6ac2892

File tree

19 files changed

+248
-15
lines changed

19 files changed

+248
-15
lines changed

spring-boot-data-aggregate-autoconfigure/src/main/java/org/feego/spring/annotation/DataBeanConsumer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@
1313
@Documented
1414
public @interface DataBeanConsumer {
1515
String id();
16-
String namespace();
1716
}

spring-boot-data-aggregate-autoconfigure/src/main/java/org/feego/spring/annotation/DataBeanProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@
1313
@Documented
1414
public @interface DataBeanProvider {
1515
String id();
16-
String namespace();
1716
long timeout() default 1000;
1817
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
package org.feego.spring.autoconfigure;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.feego.spring.aggregate.facade.DataBeanAggregateQueryFacade;
45
import org.feego.spring.aggregate.facade.impl.DataBeanAggregateQueryFacadeImpl;
6+
import org.feego.spring.aggregate.model.DataProvider;
7+
import org.feego.spring.aggregate.repository.DataProviderRepository;
8+
import org.feego.spring.aggregate.repository.impl.DataProviderRepositoryImpl;
9+
import org.feego.spring.aggregate.service.DataBeanAgregateQueryServiceImpl;
10+
import org.feego.spring.annotation.DataBeanProvider;
11+
import org.reflections.Reflections;
12+
import org.reflections.scanners.MethodAnnotationsScanner;
513
import org.springframework.beans.BeansException;
14+
import org.springframework.beans.factory.annotation.Autowired;
615
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
716
import org.springframework.boot.context.properties.EnableConfigurationProperties;
817
import org.springframework.context.ApplicationContext;
918
import org.springframework.context.ApplicationContextAware;
1019
import org.springframework.context.annotation.Bean;
1120
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
22+
23+
import java.lang.reflect.Method;
24+
import java.util.Set;
25+
import java.util.concurrent.ExecutorService;
26+
import java.util.concurrent.LinkedBlockingDeque;
27+
import java.util.concurrent.ThreadPoolExecutor;
28+
import java.util.concurrent.TimeUnit;
1229

1330
/**
1431
1532
* @since 2019/5/31 23:28
1633
*/
1734
@Configuration
1835
@EnableConfigurationProperties(BeanAggregateProperties.class)
36+
@Slf4j
1937
public class BeanAggregateAutoConfiguration implements ApplicationContextAware {
20-
2138
private ApplicationContext applicationContext;
2239

40+
@Autowired
41+
private BeanAggregateProperties properties;
42+
2343
@Override
2444
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
2545
this.applicationContext = applicationContext;
@@ -28,6 +48,40 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
2848
@Bean
2949
@ConditionalOnMissingBean
3050
public DataBeanAggregateQueryFacade dataBeanAggregateQueryFacade() {
31-
return new DataBeanAggregateQueryFacadeImpl();
51+
DataProviderRepository repository = new DataProviderRepositoryImpl();
52+
scanProviders(repository);
53+
DataBeanAgregateQueryServiceImpl service = new DataBeanAgregateQueryServiceImpl(repository);
54+
service.setExecutorService(aggregateExecutorService());
55+
service.setApplicationContext(applicationContext);
56+
return new DataBeanAggregateQueryFacadeImpl(service);
57+
}
58+
59+
@Bean(name = "aggregateExecutorService")
60+
@ConditionalOnMissingBean(name = "aggregateExecutorService")
61+
public ExecutorService aggregateExecutorService() {
62+
log.info("create a ThreadPoolExecutor");
63+
return new ThreadPoolExecutor(
64+
4,
65+
properties.getThreadNumber() < 4 ? 4 : properties.getThreadNumber() ,
66+
2L, TimeUnit.HOURS,
67+
new LinkedBlockingDeque<>(properties.getQueueSize()),
68+
new CustomizableThreadFactory("aggregateThread-"));
69+
}
70+
71+
private void scanProviders(DataProviderRepository repository) {
72+
if(properties.getBasePackpages() != null) {
73+
for (String basePackage : properties.getBasePackpages()) {
74+
Reflections reflections = new Reflections(basePackage, new MethodAnnotationsScanner());
75+
Set<Method> providerMethods = reflections.getMethodsAnnotatedWith(DataBeanProvider.class);
76+
for (Method method : providerMethods) {
77+
DataProvider provider = new DataProvider();
78+
DataBeanProvider beanProvider = method.getAnnotation(DataBeanProvider.class);
79+
provider.setId(beanProvider.id());
80+
provider.setMethod(method);
81+
provider.setTimeout(beanProvider.timeout());
82+
repository.put(beanProvider.id(),provider);
83+
}
84+
}
85+
}
3286
}
3387
}

spring-boot-data-aggregate-autoconfigure/src/main/java/org/feego/spring/autoconfigure/BeanAggregateProperties.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
@ConfigurationProperties(prefix = "org.feego.spring")
1111
@Data
1212
public class BeanAggregateProperties {
13-
String basePackpages;
13+
private String [] basePackpages;
14+
private int threadNumber = Runtime.getRuntime().availableProcessors() * 3 ;
15+
private int queueSize = 1000;
1416
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818
</properties>
1919

2020
<dependencies>
21-
21+
<dependency>
22+
<groupId>org.projectlombok</groupId>
23+
<artifactId>lombok</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter</artifactId>
28+
</dependency>
2229
</dependencies>
2330

2431
<build>

spring-boot-data-aggregate-core/src/main/java/org/feego/spring/.gitignore

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.feego.spring.aggregate.facade;
22

3+
import java.util.Map;
4+
35
/**
46
57
* @since 2019/6/1 0:22
68
*/
79
public interface DataBeanAggregateQueryFacade {
8-
<T> T get(String id, Class<T> clazz);
10+
<T> T get(String id, Map<String,Object> invokeParams, Class<T> clazz);
911
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
package org.feego.spring.aggregate.facade.impl;
22

33
import org.feego.spring.aggregate.facade.DataBeanAggregateQueryFacade;
4+
import org.feego.spring.aggregate.service.DataBeanAgregateQueryService;
5+
import org.springframework.util.Assert;
6+
7+
import java.util.Collections;
8+
import java.util.Map;
49

510
/**
611
712
* @since 2019/6/1 0:22
813
*/
914
public class DataBeanAggregateQueryFacadeImpl implements DataBeanAggregateQueryFacade {
1015

16+
private DataBeanAgregateQueryService dataBeanAgregateQueryService;
17+
18+
public DataBeanAggregateQueryFacadeImpl(DataBeanAgregateQueryService dataBeanAgregateQueryService) {
19+
this.dataBeanAgregateQueryService = dataBeanAgregateQueryService;
20+
}
21+
1122
@Override
12-
public <T> T get(String id, Class<T> clazz) {
13-
return null;
23+
public <T> T get(String id, Map<String,Object> invokeParams, Class<T> clazz) {
24+
Assert.notNull(id,"id must be not null!");
25+
Assert.notNull(clazz,"clazz must be not null !");
26+
if(invokeParams == null) {
27+
invokeParams = Collections.emptyMap();
28+
}
29+
return dataBeanAgregateQueryService.get(id,invokeParams,clazz);
1430
}
1531
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.feego.spring.aggregate.model;
2+
3+
import lombok.Data;
4+
5+
/**
6+
7+
* @since 2019/6/2 22:13
8+
*/
9+
@Data
10+
public class DataDepend {
11+
private String id;
12+
private Class<?> clazz;
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.feego.spring.aggregate.model;
2+
3+
import lombok.Data;
4+
5+
import java.lang.reflect.Method;
6+
import java.util.List;
7+
8+
/**
9+
10+
* @since 2019/6/2 21:30
11+
*/
12+
@Data
13+
public class DataProvider {
14+
private String id;
15+
private Method method;
16+
private Long timeout;
17+
private List<DataDepend> depends;
18+
private List<InvokeParam> params;
19+
}

0 commit comments

Comments
 (0)