Skip to content

Configuration

Feego edited this page Sep 7, 2019 · 2 revisions

Configuration Item

basePackages

Io.github.lvyahui8.spring.base-packages=com.package1,com.package2....

Declare the package that needs to scan the Aggregator library for the solution. To ensure efficiency, the framework does not scan all package directories, you must specify

threadPrefix

Io.github.lvyahui8.spring.thread-prefix=aggregateTask-

Specifies the asynchronous thread prefix. If a custom thread pool bean is used instead of the thread pool of the framework, this configuration does not take effect.

threadNumber

Io.github.lvyahui8.spring.thread-number=12

Specifies the size of the asynchronous thread pool. The coreThreadSize and maxThreadSize are the same in the thread pool. The default value is the number of CPUs. If you use a custom thread pool bean instead of the thread pool of the framework, this configuration does not take effect.

queueSize

Io.github.lvyahui8.spring.queue-size=1000

Set the size of the thread pool task queue. If you use a custom thread pool bean instead of the framework's thread pool, this configuration does not take effect.

defaultTimeout

Io.github.lvyahui8.spring.default-timeout=3000

Set the default timeout for the data provider to execute. Finer control is configured in the @DataProvider annotation parameter.

enableLogging

Io.github.lvyahui8.spring.enable-logging=true

Set whether to allow the framework to output logs. The default is false.

ignoreException

Io.github.lvyahui8.spring.ignore-exception=true

Set whether to ignore the exception that occurs when the data provider is executed. If it is true, the exception will be ignored, the method will return null, otherwise the exception will be thrown step by step.

Custom Bean

The framework supports custom beans instead of beans in the framework for extended functionality

Thread Pool

  • Bean name: aggregateExecutorService
  • Bean type: java.util.concurrent.ExecutorService

Support for custom thread pools, you can also reuse existing thread pools in your application to avoid flooding of threads.

such as:

/**
 * Customize ExecutorService, replace the executorService used by the aggregator library
 * @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"));
}

Provider Repository

  • Bean Name: dataProviderRepository
  • Bean type: io.github.lvyahui8.spring.aggregate.repository.DataProviderRepository

After the application is launched, the framework will scan the annotations and record the information of each data provider. The default implementation is implemented using ConcurrentHashMap. You can customize this bean to replace the implementation.

Interceptor Chain

Define the framework query interceptor chain. The currently implemented interceptor chain application globally will be applied to all the framework's queries of the application. The default interceptor chain is empty, you can customize this bean to add the interceptor. Control the interceptor order via the org.springframework.core.annotation.Order annotation

solution 1

@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);
    }
}

solution 2

/**
 * @author lvyahui ([email protected],[email protected])
 * @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) {

    }
}