{"id":15663680,"url":"https://github.com/ahoo-wang/simba","last_synced_at":"2025-10-13T17:35:08.684Z","repository":{"id":40357550,"uuid":"402773769","full_name":"Ahoo-Wang/Simba","owner":"Ahoo-Wang","description":"Distributed lock service | 分布式锁服务","archived":false,"fork":false,"pushed_at":"2025-09-18T22:44:48.000Z","size":1085,"stargazers_count":24,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-09-19T00:42:55.673Z","etag":null,"topics":["distributed","java","kotlin","lock","mutex","mutex-lock","redis","scheduler","spring","spring-boot","zookeeper"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ahoo-Wang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-09-03T13:08:22.000Z","updated_at":"2025-09-18T22:44:51.000Z","dependencies_parsed_at":"2023-10-17T05:02:32.796Z","dependency_job_id":"7fb2b59e-0fca-4541-9710-2f13f387e5a1","html_url":"https://github.com/Ahoo-Wang/Simba","commit_stats":{"total_commits":286,"total_committers":3,"mean_commits":95.33333333333333,"dds":0.3076923076923077,"last_synced_commit":"61daaffe86f998b2badba66f71540f9a436abc7f"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"purl":"pkg:github/Ahoo-Wang/Simba","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FSimba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FSimba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FSimba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FSimba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ahoo-Wang","download_url":"https://codeload.github.com/Ahoo-Wang/Simba/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2FSimba/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279016355,"owners_count":26085828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed","java","kotlin","lock","mutex","mutex-lock","redis","scheduler","spring","spring-boot","zookeeper"],"created_at":"2024-10-03T13:39:23.506Z","updated_at":"2025-10-13T17:35:08.669Z","avatar_url":"https://github.com/Ahoo-Wang.png","language":"Kotlin","readme":"# Simba(Distributed Mutex)\n\n[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)\n[![GitHub release](https://img.shields.io/github/release/Ahoo-Wang/Simba.svg)](https://github.com/Ahoo-Wang/Simba/releases)\n[![Maven Central Version](https://img.shields.io/maven-central/v/me.ahoo.simba/simba-core)](https://central.sonatype.com/artifact/me.ahoo.simba/simba-core)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/41f28a111d9c457ab7a9aae6861185eb)](https://www.codacy.com/gh/Ahoo-Wang/Simba/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=Ahoo-Wang/Simba\u0026amp;utm_campaign=Badge_Grade)\n[![codecov](https://codecov.io/gh/Ahoo-Wang/Simba/branch/main/graph/badge.svg?token=P9EMJKJ2I5)](https://codecov.io/gh/Ahoo-Wang/Simba)\n[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Ahoo-Wang/Simba)\n\n## Introduction\n\nSimba aims to provide easy-to-use and flexible distributed lock services and supports multiple storage implementations: relational databases, Redis, and Zookeeper.\n\n## Installation\n\n### Gradle\n\n\u003e Kotlin DSL\n\n``` kotlin\n    implementation(\"me.ahoo.simba:simba-spring-boot-starter:${simbaVersion}\")\n```\n\n### Maven\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\n\u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\u003e\n\n    \u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n    \u003cartifactId\u003edemo\u003c/artifactId\u003e\n    \u003cproperties\u003e\n        \u003csimba.version\u003esimbaVersion\u003c/simba.version\u003e\n    \u003c/properties\u003e\n\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eme.ahoo.simba\u003c/groupId\u003e\n            \u003cartifactId\u003esimba-spring-boot-starter\u003c/artifactId\u003e\n            \u003cversion\u003e${simba.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n    \n\u003c/project\u003e\n```\n### application.yaml\n\n```yaml\nsimba:\n  jdbc:\n    enabled: true\n#  redis:\n#    enabled: true\n\nspring:\n  datasource:\n    url: jdbc:mysql://localhost:3306/simba_db\n    username: root\n    password: root\n```\n\n### Optional-1: JdbcMutexContendService\n\n![JdbcMutexContendService](docs/JdbcMutexContendService.png)\n\n\u003e Kotlin DSL\n\n``` kotlin\n    implementation(\"me.ahoo.simba:simba-jdbc:${simbaVersion}\")\n```\n\n```sql\ncreate table simba_mutex\n(\n    mutex             varchar(66)     not null primary key comment 'mutex name',\n    acquired_at       bigint unsigned not null,\n    ttl_at         bigint unsigned not null,\n    transition_at bigint unsigned not null,\n    owner_id          char(32)        not null,\n    version           int unsigned    not null\n);\n```\n\n### Optional-2: RedisMutexContendService\n\n\u003e Kotlin DSL\n\n``` kotlin\n    implementation(\"me.ahoo.simba:simba-redis:${simbaVersion}\")\n```\n\n### Optional-3: ZookeeperMutexContendService\n\n\u003e Kotlin DSL\n\n``` kotlin\n    implementation(\"me.ahoo.simba:simba-zookeeper:${simbaVersion}\")\n```\n\n## Examples\n\n[Simba-Examples](https://github.com/Ahoo-Wang/Simba/tree/main/simba-example)\n\n## Usage\n\n### MutexContender\n\n```java\n        MutexContendService contendService = contendServiceFactory.createMutexContendService(new AbstractMutexContender(mutex) {\n            @Override\n            public void onAcquired(MutexState mutexState) {\n                    log.info(\"onAcquired\");\n            }\n            \n            @Override\n            public void onReleased(MutexState mutexState) {\n                    log.info(\"onReleased\");\n            }\n        });\n        contendService.start();\n```\n\n### SimbaLocker\n\n```java\n        try (Locker locker = new SimbaLocker(\"mutex-locker\", this.mutexContendServiceFactory)) {\n            locker.acquire(Duration.ofSeconds(1));\n        /**\n         * doSomething\n         */\n        } catch (Exception e) {\n            log.error(e.getMessage(), e);\n        }\n```\n\n### Scheduler\n\n```kotlin\npublic class ExampleScheduler extends AbstractScheduler implements SmartLifecycle {\n\n    public ExampleScheduler(MutexContendServiceFactory contendServiceFactory) {\n        super(\"example-scheduler\", ScheduleConfig.ofDelay(Duration.ofSeconds(0), Duration.ofSeconds(10)), contendServiceFactory);\n    }\n\n    @Override\n    protected String getWorker() {\n        return \"ExampleScheduler\";\n    }\n\n    @Override\n    protected void work() {\n        if (log.isInfoEnabled()) {\n            log.info(\"do some work!\");\n        }\n    }\n}\n```\n\n#### Use Cases\n\n- [Govern-EventBus](https://github.com/Ahoo-Wang/govern-eventbus/tree/master/eventbus-core/src/main/java/me/ahoo/eventbus/core/compensate)\n- [CoSky](https://github.com/Ahoo-Wang/CoSky/blob/main/cosky-rest-api/src/main/kotlin/me/ahoo/cosky/rest/stat/StatServiceScheduler.kt)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoo-wang%2Fsimba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahoo-wang%2Fsimba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoo-wang%2Fsimba/lists"}