当前位置:网站首页>Circuit breaker hystrixcircuitbreaker
Circuit breaker hystrixcircuitbreaker
2022-06-30 10:39:00 【Full stack programmer webmaster】
package com.netflix.hystrix;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import com.netflix.hystrix.HystrixCommandMetrics.HealthCounts;
import rx.Subscriber;
import rx.Subscription;
public interface HystrixCircuitBreaker {
boolean allowRequest();
boolean isOpen();
void markSuccess();
void markNonSuccess();
boolean attemptExecution();
class Factory {
// String is HystrixCommandKey.name() (we can't use HystrixCommandKey directly as we can't guarantee it implements hashcode/equals correctly)
private static ConcurrentHashMap<String, HystrixCircuitBreaker> circuitBreakersByCommand = new ConcurrentHashMap<String, HystrixCircuitBreaker>();
}
class HystrixCircuitBreakerImpl implements HystrixCircuitBreaker {
}
static class NoOpCircuitBreaker implements HystrixCircuitBreaker {
}
}Let's take a look at the abstract methods of this interface :
allowRequest(): Every Hystrix The request of the command is judged to be executed by it ( No longer in use , Use attemptExecution() Method to judge ) attemptExecution(): Every Hystrix The request of the command is judged to be executed by it isOpen(): Returns whether the current circuit breaker is open markSuccess(): Used to close the circuit breaker markNonSuccess: Used to open the circuit breaker
Let's take a look at the classes in this interface :
Factory: One was maintained Hystrix Command and HystrixCircuitBreaker Collection of relationships for ConcurrentHashMap<String, HystrixCircuitBreaker> circuitBreakersByCommand. among key adopt HystrixCommandKey To define , every last Hystrix Commands need to have one Key To mark , At the same time, according to this Key The corresponding circuit breaker instance can be found . NoOpCircuitBreaker: A circuit breaker that does nothing , It allows all requests to pass , And the circuit breaker is always closed HystrixCircuitBreakerImpl: Another implementation class for circuit breakers .
HystrixCircuitBreakerImpl Introduce
Five core objects of circuit breaker are defined in this class :
HystrixCommandProperties properties: The attribute collection object of the corresponding instance of the circuit breaker / The circuit breaker corresponds to HystrixCommand The property object of the instance HystrixCommandMetrics metrics: Used to make HystrixCommand Record the objects of various metrics AtomicReference<Status> status: Used to record the status of the circuit breaker , The default is off AtomicLong circuitOpened: Time stamp of circuit breaker opening , Default -1, Indicates that the circuit breaker is not open AtomicReference<Subscription> activeSubscription: Record HystrixCommand
The implementation of the interface is as follows :
@Override
public boolean isOpen() {
if (properties.circuitBreakerForceOpen().get()) {
return true;
}
if (properties.circuitBreakerForceClosed().get()) {
return false;
}
return circuitOpened.get() >= 0;
}Used to judge whether the circuit breaker is open or closed . The main steps are :
If the circuit breaker is forced open , return true If the circuit breaker is forced to close , return false Judge circuitOpened Value , If greater than or equal to 0, return true, Otherwise return to false
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/101128.html Link to the original text :https://javaforall.cn
边栏推荐
- 技能梳理[email protected]在oled上控制一条狗的奔跑
- Questions about cookies and sessions
- SGD有多种改进的形式,为什么大多数论文中仍然用SGD?
- I found a wave of "alchemy artifact" in the goose factory. The developer should pack it quickly
- Node environment configuration
- Compare the maximum computing power of the Cenozoic top ant s19xp and the existing s19pro in bitland
- Turn to cartoon learning notes
- Highlight display of Jinbei LB box, adhering to mini special effects
- Koreano essential creates a professional style
- Getting started with X86 - take over bare metal control
猜你喜欢

移植完整版RT-Thread到GD32F4XX(详细)

Remember the experience of an internship. It is necessary to go to the pit (I)
[email protected] voice module +stm32+nfc"/>Skill combing [email protected] voice module +stm32+nfc

mysql数据库基础:存储过程和函数

透过华为军团看科技之变(五):智慧园区

ArcGIS Pro脚本工具(5)——排序后删除重复项

记一次实习的经历,趟坑必备(一)

Apple's 5g chip was revealed to have failed in research and development, and the QQ password bug caused heated discussion. Wei Lai responded to the short selling rumors. Today, more big news is here

Voir le changement technologique à travers la Légion Huawei (5): Smart Park

“昆明城市咖啡地图”再度开启,咖啡拉近城市距离
随机推荐
技能梳理[email protected]体感机械臂
Voir le changement technologique à travers la Légion Huawei (5): Smart Park
华南产业集团发力数字经济,城链科技发布会成功召开
Foster design method
【深度学习】深度学习检测小目标常用方法
Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
从0使用keil5软件仿真调试GD32F305
SGD有多种改进的形式,为什么大多数论文中仍然用SGD?
RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装
Compétences Comb 27 @ Body sense Manipulator
透過華為軍團看科技之變(五):智慧園區
Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home
ArcGIS Pro脚本工具(6)——修复CAD图层数据源
Configure Yii: display MySQL extension module verification failed
Jinbei LT6 is powerful in the year of the tiger, making waves
GD32 RT-Thread RTC驱动函数
技能梳理[email protected]體感機械臂
【Rust每周一库】num-bigint - 大整数
技能梳理[email protected]+adxl345+电机震动+串口输出
Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine