Search in sources :

Example 1 with InstancesDetectTask

use of com.tencent.polaris.circuitbreak.client.task.InstancesDetectTask in project polaris-java by polarismesh.

the class ServiceCallResultChecker method init.

@Override
public synchronized void init(SDKContext sdkContext) {
    if (!state.compareAndSet(0, 1)) {
        return;
    }
    extensions = sdkContext.getExtensions();
    CircuitBreakerConfig cbConfig = sdkContext.getConfig().getConsumer().getCircuitBreaker();
    if (cbConfig.isEnable()) {
        priorityTaskScheduler = new PriorityTaskScheduler();
        cbTaskExecutors = Executors.newSingleThreadScheduledExecutor();
        CheckServicesCircuitBreak checker = new CheckServicesCircuitBreak(sdkContext.getExtensions(), priorityTaskScheduler);
        long checkPeriodMs = cbConfig.getCheckPeriod();
        cbTaskExecutors.scheduleAtFixedRate(checker, checkPeriodMs, checkPeriodMs / 2, TimeUnit.MILLISECONDS);
    }
    OutlierDetectionConfig outlierDetection = sdkContext.getConfig().getConsumer().getOutlierDetection();
    if (outlierDetection.getWhen() != When.never) {
        detectTaskExecutors = Executors.newSingleThreadScheduledExecutor();
        long checkPeriodMs = outlierDetection.getCheckPeriod();
        detectTask = new InstancesDetectTask(extensions);
        detectTaskExecutors.scheduleAtFixedRate(detectTask, checkPeriodMs, checkPeriodMs, TimeUnit.MILLISECONDS);
    }
}
Also used : OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) InstancesDetectTask(com.tencent.polaris.circuitbreak.client.task.InstancesDetectTask) PriorityTaskScheduler(com.tencent.polaris.circuitbreak.client.task.PriorityTaskScheduler) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig)

Aggregations

CircuitBreakerConfig (com.tencent.polaris.api.config.consumer.CircuitBreakerConfig)1 OutlierDetectionConfig (com.tencent.polaris.api.config.consumer.OutlierDetectionConfig)1 InstancesDetectTask (com.tencent.polaris.circuitbreak.client.task.InstancesDetectTask)1 PriorityTaskScheduler (com.tencent.polaris.circuitbreak.client.task.PriorityTaskScheduler)1