当前位置:网站首页>断路器HystrixCircuitBreaker
断路器HystrixCircuitBreaker
2022-06-30 09:50:00 【全栈程序员站长】
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 {
}
}下面先看一下该接口的抽象方法:
allowRequest(): 每个Hystrix命令的请求都通过它判断是否被执行(已经不再使用,使用attemptExecution()方法进行判断) attemptExecution(): 每个Hystrix命令的请求都通过它判断是否被执行 isOpen(): 返回当前断路器是否打开 markSuccess(): 用来关闭断路器 markNonSuccess: 用来打开断路器
下面看一下该接口中的类:
Factory: 维护了一个Hystrix命令和HystrixCircuitBreaker的关系的集合ConcurrentHashMap<String, HystrixCircuitBreaker> circuitBreakersByCommand。其中key通过HystrixCommandKey来定义,每一个Hystrix命令都需要有一个Key来标识,同时根据这个Key可以找到对应的断路器实例。 NoOpCircuitBreaker: 一个啥都不做的断路器,它允许所有请求通过,并且断路器始终处于闭合状态 HystrixCircuitBreakerImpl:断路器的另一个实现类。
HystrixCircuitBreakerImpl介绍
在该类中定义了断路器的五个核心对象:
HystrixCommandProperties properties:断路器对应实例的属性集合对象/断路器对应HystrixCommand实例的属性对象 HystrixCommandMetrics metrics:用来让HystrixCommand记录各类度量指标的对象 AtomicReference<Status> status: 用来记录断路器的状态,默认是关闭状态 AtomicLong circuitOpened:断路器打开的时间戳,默认-1,表示断路器未打开 AtomicReference<Subscription> activeSubscription: 记录HystrixCommand
对接口的实现如下:
@Override
public boolean isOpen() {
if (properties.circuitBreakerForceOpen().get()) {
return true;
}
if (properties.circuitBreakerForceClosed().get()) {
return false;
}
return circuitOpened.get() >= 0;
}用来判断断路器是否打开或关闭。主要步骤有:
如果断路器强制打开,返回true 如果断路器强制关闭,返回false 判断circuitOpened的值,如果大于等于0,返回true, 否则返回false
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/101128.html原文链接:https://javaforall.cn
边栏推荐
- Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony
- Harvester ch1 of CKB and HNS, connection tutorial analysis
- Why can't you rob scientists of NFT
- Gd32 RT thread ota/bootloader driver function
- Oracle creates a stored procedure successfully, but the compilation fails
- 今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
- 【Rust每周一库】num-bigint - 大整数
- Skill sorting [email protected]+adxl345+ Motor vibration + serial port output
- ArcGIS Pro脚本工具(5)——排序后删除重复项
- 光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述
猜你喜欢

Use keil5 software to simulate and debug gd32f305 from 0

我在鹅厂淘到了一波“炼丹神器”,开发者快打包

Detailed explanation of commissioning methods and techniques

Why can't you rob scientists of NFT

光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述
[email protected] voice module +stm32+nfc"/>Skill combing [email protected] voice module +stm32+nfc

L'activité "Kunming City coffee map" a rouvert

“昆明城市咖啡地图”活动再度开启

MySQL index, transaction and storage engine of database (3)

ArcGIS PRO + PS vectorized land use planning map
随机推荐
Auto Seg-Loss: 自动损失函数设计
MySQL index, transaction and storage engine of database (3)
那个程序员,被打了。
打通供应链 深圳礼品展助跨境电商寻破局之道
GD32 RT-Thread PWM驱动函数
Remember the experience of an internship. It is necessary to go to the pit (I)
Deploy lvs-dr cluster
著名画家史国良《丰收时节》数字藏品上线长城数艺
L'activité "Kunming City coffee map" a rouvert
《锦绣中华》中老年公益文旅游-走进佛山敬老院
【Rust日报】2021-01-22 首份Rust月刊杂志邀请大家一起参与
IPhone address book import into Excel
What is the real performance of CK5, the king machine of CKB?
CSDN博客运营团队2022年H1总结
Getting started with X86 - take over bare metal control
我在鹅厂淘到了一波“炼丹神器”,开发者快打包
潘多拉 IOT 开发板学习(HAL 库)—— 实验1 跑马灯(RGB)实验(学习笔记)
光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述
Foster design method
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