当前位置:网站首页>断路器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
边栏推荐
- Detailed explanation of SolidWorks mass characteristics (inertia tensor, moment of inertia, inertia spindle)
- Guolin was crowned the third place of global popularity of perfect master in the third quarter of 2022
- After recording 7000 IELTS words in 100 sentences, there are only 1043 words (including simple words such as I and you)
- ArcGIS Pro + PS 矢量化用地规划图
- What is the real performance of CK5, the king machine of CKB?
- Robot system dynamics - inertia parameters
- 技能梳理[email protected]体感机械臂
- WGet -- 404 not found due to spaces in URL
- "Kunming City coffee map" activity was launched again
- 【Rust日报】2021-01-22 首份Rust月刊杂志邀请大家一起参与
猜你喜欢

Harvester ch1 of CKB and HNS, connection tutorial analysis

WGet -- 404 not found due to spaces in URL

Why can't you rob scientists of NFT

GeoffreyHinton:我的五十年深度学习生涯与研究心法

苹果5G芯片被曝研发失败,QQ密码bug引热议,蔚来回应做空传闻,今日更多大新闻在此...

Migrate full RT thread to gd32f4xx (detailed)
[email protected]体感机械臂"/>技能梳理[email protected]体感机械臂

MySQL log management, backup and recovery of databases (1)

GNN hands on practice (II): reproduction graph attention network gat

Configure Yii: display MySQL extension module verification failed
随机推荐
MySQL advanced SQL statement of database (2)
六月集训(第30天) —— 拓扑排序
CSDN博客运营团队2022年H1总结
SGD有多种改进的形式,为什么大多数论文中仍然用SGD?
After recording 7000 IELTS words in 100 sentences, there are only 1043 words (including simple words such as I and you)
Curl --- the request fails when the post request parameter is too long (more than 1024b)
“昆明城市咖啡地图”活动再度开启
Detailed explanation of SolidWorks mass characteristics (inertia tensor, moment of inertia, inertia spindle)
Oracle creates a stored procedure successfully, but the compilation fails
Musk has more than 100 million twitter fans, but he has been lost online for a week
[AGC] build service 3- authentication service example
ArcGIS Pro脚本工具(6)——修复CAD图层数据源
“昆明城市咖啡地圖”活動再度開啟
今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
mysql数据库基础:存储过程和函数
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
跳跃表介绍
Arm新CPU性能提升22%,最高可组合12核,GPU首配硬件光追,网友:跟苹果的差距越来越大了...
How to seize the opportunity of NFT's "chaos"?
GD32 RT-Thread PWM驱动函数