Skip to content

模块概览

Simba 组织为多模块 Gradle 项目。每个模块职责明确,从核心抽象到后端特定实现以及 Spring Boot 自动配置。

模块依赖关系图

mermaid
graph TB
    subgraph sg_82 ["Build & Analysis"]

        BOM["simba-bom"]
        DEPS["simba-dependencies"]
        CR["code-coverage-report"]
    end
    subgraph sg_83 ["Application"]

        EX["simba-example"]
    end
    subgraph sg_84 ["Spring Boot"]

        STARTER["simba-spring-boot-starter"]
    end
    subgraph sg_85 ["Backend Implementations"]

        JDBC["simba-jdbc"]
        REDIS["simba-spring-redis"]
        ZK["simba-zookeeper"]
    end
    subgraph sg_86 ["Core"]

        CORE["simba-core"]
        TEST["simba-test"]
    end

    CORE --> DEPS
    JDBC --> CORE
    REDIS --> CORE
    ZK --> CORE
    STARTER --> CORE
    STARTER -.->|"springRedisSupport"| REDIS
    STARTER -.->|"jdbcSupport"| JDBC
    STARTER -.->|"zookeeperSupport"| ZK
    TEST --> CORE
    EX --> STARTER
    CR --> JDBC
    CR --> REDIS
    CR --> ZK
    CR --> STARTER
    CR --> CORE
    CR --> TEST

    style BOM fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style DEPS fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style CR fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style EX fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style STARTER fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style JDBC fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style REDIS fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style ZK fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style CORE fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style TEST fill:#2d333b,stroke:#6d5dfc,color:#e6edf3

模块目录

模块职责关键类型依赖
simba-core核心接口、抽象类、值对象MutexContenderMutexContendServiceSimbaLockerAbstractSchedulerkotlin-logging、cosid-core、guava
simba-jdbcJDBC/MySQL 后端,使用乐观锁JdbcMutexContendServiceJdbcMutexOwnerRepositorysimba-core、JDBC 驱动
simba-spring-redisRedis 后端,使用 Lua 脚本和发布/订阅SpringRedisMutexContendService、Lua 脚本simba-core、spring-data-redis
simba-zookeeperZookeeper 后端,使用 Curator LeaderLatchZookeeperMutexContendServicesimba-core、curator-recipes
simba-spring-boot-starter所有后端的自动配置SimbaJdbcAutoConfigurationSimbaSpringRedisAutoConfigurationSimbaZookeeperAutoConfigurationsimba-core + 条件性后端依赖
simba-testTCK(技术兼容性套件)MutexContendServiceSpecLockSpecsimba-core、JUnit 5
simba-bomBOM(物料清单),用于版本管理----
simba-dependencies依赖版本约束----
simba-example示例应用ExampleAppsimba-spring-boot-starter
code-coverage-reportJaCoCo 聚合报告--所有模块

后端对比

mermaid
graph LR
    subgraph sg_87 ["JDBC Backend"]

        J_REPO["MutexOwnerRepository"]
        J_SCHED["ScheduledThreadPoolExecutor<br>(polling)"]
        J_DDL["simba_mutex table<br>optimistic locking"]
    end
    subgraph sg_88 ["Redis Backend"]

        R_LUA["Lua Scripts<br>acquire/guard/release"]
        R_PS["Pub/Sub<br>RedisMessageListenerContainer"]
        R_ZSET["Sorted Set<br>contender queue"]
    end
    subgraph sg_89 ["Zookeeper Backend"]

        Z_LATCH["LeaderLatch<br>/simba/{mutex}"]
        Z_CUR["CuratorFramework"]
    end

    style J_REPO fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style J_SCHED fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style J_DDL fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style R_LUA fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style R_PS fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style R_ZSET fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style Z_LATCH fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
    style Z_CUR fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
特性JDBCRedisZookeeper
协调机制使用 ScheduledThreadPoolExecutor 轮询Lua 脚本 + 发布/订阅Curator LeaderLatch
锁存储simba_mutexRedis 键(simba:{mutex}ZNode(/simba/{mutex}
所有权转移通过 version 列进行乐观锁有序集合等待队列 + 发布/订阅通知ZK 对 latch 参与者的 watcher
时间源MySQL current_timestamp(3)系统时钟(客户端侧)ZK 服务器时间
外部依赖MySQL 实例Redis 实例ZooKeeper 集群
最适合已有关系型数据库基础设施高吞吐量、低延迟强一致性保证

Gradle 功能变体

simba-spring-boot-starter 使用 Gradle 功能变体,使消费者只需引入所需的后端依赖:

kotlin
dependencies {
    // 仅引入 Redis 后端
    implementation("me.ahoo.simba:simba-spring-boot-starter") {
        capabilities {
            requireCapability("me.ahoo.simba:spring-redis-support")
        }
    }
}

可用的功能变体:

变体功能标识后端模块
springRedisSupportme.ahoo.simba:spring-redis-supportsimba-spring-redis
jdbcSupportme.ahoo.simba:jdbc-supportsimba-jdbc
zookeeperSupportme.ahoo.simba:zookeeper-supportsimba-zookeeper

另请参阅

基于 Apache License 2.0 发布。