当前位置: 首页 > news >正文

建设网站要电脑才能吗网站怎样推广 优帮云

建设网站要电脑才能吗,网站怎样推广 优帮云,乌克兰vps国外服务器,制作网站参考ImadcnIdentifierGenerator 深度解析 这是一个基于Zookeeper的分布式ID生成器实现,结合了雪花算法(Snowflake)和压缩UUID生成能力。下面我将从多个维度详细分析这个实现类。 // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fer…

ImadcnIdentifierGenerator 深度解析

这是一个基于Zookeeper的分布式ID生成器实现,结合了雪花算法(Snowflake)和压缩UUID生成能力。下面我将从多个维度详细分析这个实现类。

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package com.baomidou.mybatisplus.core.incrementer;import com.imadcn.framework.idworker.config.ApplicationConfiguration;
import com.imadcn.framework.idworker.config.ZookeeperConfiguration;
import com.imadcn.framework.idworker.generator.CompressUUIDGenerator;
import com.imadcn.framework.idworker.generator.SnowflakeGenerator;
import com.imadcn.framework.idworker.register.zookeeper.ZookeeperWorkerRegister;
import com.imadcn.framework.idworker.registry.zookeeper.ZookeeperRegistryCenter;
import java.io.Closeable;
import java.io.IOException;public class ImadcnIdentifierGenerator implements IdentifierGenerator, Closeable {private final SnowflakeGenerator idGenerator;private final CompressUUIDGenerator uuidGenerator;public ImadcnIdentifierGenerator(String serverLists) {this(configuration(serverLists));}public ImadcnIdentifierGenerator(ZookeeperConfiguration zookeeperConfiguration) {this(zookeeperConfiguration, new ApplicationConfiguration());}public ImadcnIdentifierGenerator(ZookeeperConfiguration zookeeperConfiguration, ApplicationConfiguration applicationConfiguration) {this.uuidGenerator = new CompressUUIDGenerator();ZookeeperRegistryCenter center = new ZookeeperRegistryCenter(zookeeperConfiguration);ZookeeperWorkerRegister register = new ZookeeperWorkerRegister(center, applicationConfiguration);this.idGenerator = new SnowflakeGenerator(register);this.idGenerator.init();}private static ZookeeperConfiguration configuration(String serverLists) {ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration();zookeeperConfiguration.setServerLists(serverLists);return zookeeperConfiguration;}public Number nextId(Object entity) {return this.idGenerator.nextId();}public String nextUUID(Object entity) {return this.uuidGenerator.nextStringId();}public void close() throws IOException {this.idGenerator.close();}
}

类继承与实现关系

ImadcnIdentifierGenerator
├─ implements IdentifierGenerator (MyBatis-Plus接口)
├─ implements Closeable (资源关闭接口)

核心组件

1. ID生成器成员

private final SnowflakeGenerator idGenerator;  // 雪花算法ID生成器
private final CompressUUIDGenerator uuidGenerator;  // 压缩UUID生成器

2. 构造方法链

提供了三种构造方式:

// 1. 最简单构造(仅需Zookeeper服务器地址)
public ImadcnIdentifierGenerator(String serverLists)// 2. 使用Zookeeper配置
public ImadcnIdentifierGenerator(ZookeeperConfiguration zookeeperConfiguration)// 3. 完整配置(Zookeeper+应用配置)
public ImadcnIdentifierGenerator(ZookeeperConfiguration zookeeperConfiguration, ApplicationConfiguration applicationConfiguration)

核心方法实现

1. ID生成方法

@Override
public Number nextId(Object entity) {return this.idGenerator.nextId(); // 使用雪花算法生成数字ID
}@Override
public String nextUUID(Object entity) {return this.uuidGenerator.nextStringId(); // 生成压缩格式UUID
}

2. 资源清理

@Override
public void close() throws IOException {this.idGenerator.close(); // 关闭雪花算法生成器
}

技术实现细节

雪花算法初始化流程

  1. 创建Zookeeper注册中心

  2. 创建Worker注册器

  3. 初始化雪花ID生成器

    ZookeeperRegistryCenter center = new ZookeeperRegistryCenter(zookeeperConfiguration);
    ZookeeperWorkerRegister register = new ZookeeperWorkerRegister(center, applicationConfiguration);
    this.idGenerator = new SnowflakeGenerator(register);
    this.idGenerator.init();
    

配置处理

private static ZookeeperConfiguration configuration(String serverLists) {ZookeeperConfiguration config = new ZookeeperConfiguration();config.setServerLists(serverLists); // 设置Zookeeper集群地址return config;
}

设计亮点

  1. 分布式支持:通过Zookeeper协调Worker ID分配,避免集群环境下ID冲突
  2. 双ID策略:同时提供有序数字ID和高性能UUID生成能力
  3. 资源管理:实现Closeable接口确保正确释放Zookeeper连接
  4. 配置灵活:提供多种构造方法适应不同使用场景

典型使用场景

1. MyBatis-Plus集成

@Bean
public IdentifierGenerator idGenerator() {return new ImadcnIdentifierGenerator("zk1:2181,zk2:2181");
}

2. 直接调用生成ID

ImadcnIdentifierGenerator generator = new ImadcnIdentifierGenerator(config);// 生成订单ID
Long orderId = generator.nextId(orderEntity).longValue();// 生成业务流水号
String traceId = generator.nextUUID(null);

性能考量

  1. 雪花算法优势

    • 64位ID结构(时间戳+WorkerID+序列号)
    • 单机每秒可生成400万+ ID
    • 趋势递增,适合数据库索引
  2. 压缩UUID优化

    • 相比标准UUID更节省存储空间
    • 仍保持全局唯一性

扩展建议

  1. 故障转移:增加Zookeeper连接失败的备用方案
  2. 监控集成:添加ID生成速率等监控指标
  3. 自定义配置:支持更多雪花算法参数调整
  4. ID解析:添加从ID反解生成时间、WorkerID等信息的方法

与其他组件的对比

特性ImadcnIdentifierGenerator数据库序列Redis自增UUID
分布式支持
有序性
性能极高中等
依赖外部服务Zookeeper数据库Redis
ID长度64位数字数字数字32位字符串

这个实现非常适合需要高吞吐量、分布式部署的场景,特别是在微服务架构中为各类业务实体生成唯一标识符。

http://www.dtcms.com/a/508376.html

相关文章:

  • 一区直接写!CEEMDAN分解 + Informer-LSTM +XGBoost组合预测模型
  • 性价比高的网站建设上海企业网站的建设
  • 合规审核类智能体构建范式
  • Keil编译输出map文件主要信息和打开方式
  • 360网站推广微信h5作品欣赏
  • 优化网站软文网站制作收费明细表
  • 哪些公司网站做的很好eclipse 制作网站开发
  • 【线性代数-非线性优化算法】高斯-牛顿法和LM法
  • 自带浏览器建设银行网站打不开黄骅市原来叫什么名字
  • 如何用易语言做网站企业网站手机端
  • 互联网项目管理人员后期发展路线
  • 网络层次划分
  • 建设的网站服务器新手怎么做详情页
  • 做视频网站技术壁垒在哪里邮箱号怎么注册?
  • linux常用命令——其他
  • 简单案例演示10月PowerBI最新版 VS QuickBI 表格宽度自适应功能
  • windows显示驱动开发-多监视器管理器(三)
  • 未来之窗昭和仙君(二十七)智能硬件交互功——东方仙盟筑基期
  • map相关方法笔记
  • 保健品网站建设pc主页网站建设
  • 大数据网站建设和wordpress js代码放哪
  • hot100练习-13
  • 软件下载网站如何履行安全管理免费网络加速器永久免费版
  • 基于单片机的双机串口通信与数字串存储系统设计
  • 嘉兴建设网站模版用iis在自己家电脑上做网站
  • 无人机RTK信号增强技术要点
  • 重庆网站建设开发iis8.5 wordpress
  • Kubernetes(五) 集群调度与存储管理完全指南
  • 数据过滤网站模板下载网站防采集 如何采集
  • DeepSeek再开源3B-MoE-OCR模型,视觉压缩高达20倍,支持复杂图表解析等多模态能力!