-
Notifications
You must be signed in to change notification settings - Fork 59
Feego edited this page Sep 7, 2019
·
2 revisions
io.github.lvyahui8.spring.base-packages=com.package1,com.package2....
声明需要扫描Aggregator库相关注解的包. 为保证效率, 框架不会扫描所有包目录, 必须指定
io.github.lvyahui8.spring.thread-prefix=aggregateTask-
指定异步线程前缀, 如果使用自定义的线程池Bean替代框架的线程池, 此配置不生效.
io.github.lvyahui8.spring.thread-number=12
指定异步线程池的大小, 线程池中coreThreadSize和maxThreadSize相同. 默认值是CPU个数. 如果使用自定义的线程池Bean替代框架的线程池, 此配置不生效.
io.github.lvyahui8.spring.queue-size=1000
设置线程池任务队列的大小. 如果使用自定义的线程池Bean替代框架的线程池, 此配置不生效.
io.github.lvyahui8.spring.default-timeout=3000
设置data provider 执行的默认超时时间. 更精细的控制在@DataProvider
注解参数中配置.
io.github.lvyahui8.spring.enable-logging=true
设置是否允许框架输出日志, 默认为false.
io.github.lvyahui8.spring.ignore-exception=true
设置是否忽略data provider执行时发生的异常, 如果为true, 则将忽略异常, 方法返回null, 否则将逐级抛出异常.
框架支持自定义Bean替代框架中的Bean, 以便扩展功能
- Bean名称: aggregateExecutorService
- Bean类型: java.util.concurrent.ExecutorService
支持自定义线程池, 也可以复用应用中已有的线程池, 避免线程数泛滥.
比如:
/**
* 自定义ExecutorService, 替代aggregator库使用的executorService
* @return
*/
@Bean
public ExecutorService aggregateExecutorService() {
return new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),Runtime.getRuntime().availableProcessors() * 2 ,
2L, TimeUnit.HOURS,
new LinkedBlockingDeque<>(1024),
new CustomizableThreadFactory("example-async"));
}
- Bean名称: dataProviderRepository
- Bean类型: io.github.lvyahui8.spring.aggregate.repository.DataProviderRepository
应用启动后, 框架会扫描注解并记录每个data provider的信息, 默认的实现是使用ConcurrentHashMap实现. 你可以自定义这个Bean来更换实现.
定义框架查询拦截器链. 目前实现的拦截器链式应用全局的, 会作用在应用的所有此框架的查询上. 默认的拦截器链为空, 你可以自定义这个Bean来添加拦截器. 并通过org.springframework.core.annotation.Order
注解控制拦截器顺序
@Component
@Order(1)
@Slf4j
public class PerSetupAggregateQueryInterceptor extends AggregateQueryInterceptorAdapter {
@Override
public boolean querySubmitted(AggregationContext aggregationContext) {
log.info("current thread {}", Thread.currentThread().getName());
return super.querySubmitted(aggregationContext);
}
}
/**
* @author lvyahui (lvyahui8@gmail.com,lvyahui8@126.com)
* @since 2019/8/4 15:16
*/
public class AggregateQueryInterceptorAdapter implements AggregateQueryInterceptor {
@Override
public boolean querySubmitted(AggregationContext aggregationContext) {
return true;
}
@Override
public void queryBefore(AggregationContext aggregationContext, DataProvideDefinition provideDefinition) {
}
@Override
public Object queryAfter(AggregationContext aggregationContext, DataProvideDefinition provideDefinition, Object result) {
return result;
}
@Override
public void exceptionHandle(AggregationContext aggregationContext, DataProvideDefinition provideDefinition, Exception e) {
}
@Override
public void queryFinished(AggregationContext aggregationContext) {
}
}