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