Skip to content
Leader docs0.4

Hazelcast backend

Latest stable Based on Leader release 0.4.0

Library module

Implements single and fixed-slot group election with Hazelcast IMap TTL entries and owner tokens. Blocking, future, and coroutine paths share the Core skip-on-contention contract.

Choose it when the application already operates a Hazelcast cluster and wants coordination in the same failure domain.

Artifact: io.github.bluetape4k.leader:bluetape4k-leader-hazelcast

dependencies {
implementation(platform("io.github.bluetape4k:bluetape4k-dependencies:<version>"))
implementation("io.github.bluetape4k.leader:bluetape4k-leader-hazelcast")
}

putIfAbsent plus TTL acquires a token-owned entry. The lock is not thread-bound; extend and release must still verify the token so an old holder cannot modify a newer lease.

val elector = HazelcastLeaderElector(
hazelcastInstance,
LeaderElectionOptions(leaseTime = 30.seconds)
)
elector.runIfLeader("cache-warmer") { warmCache() }

Use single/group electors and suspend variants; factories connect framework integrations. State APIs read the shared map but do not grant execution rights.

Keep the Hazelcast instance caller-owned, use stable lock names, leave capacity for election maps, and make protected work idempotent.

Spring factories can use a HazelcastInstance. The cache-warmer example demonstrates an ordinary scheduled workload.

Tune wait, lease, minimum lease, group size, cluster discovery, split-brain protection, and map backup policy. The default single-lock map is bluetape4k:leader:locks.

Contention returns null. Cluster disconnects, serialization/configuration errors, and owner-safe extend/release failures propagate. TTL expiry can overlap a paused old action.

Monitor cluster membership, partition migration, map operation latency, backup health, extension failures, and skip rate.

Use a multi-member test cluster for contention, partition/membership changes, TTL expiry, owner-token release, group slots, and suspend cancellation.

Run cache-warmer, then compare the in-memory distributed model with Redis and MongoDB backends.

Hazelcast availability and split-brain policy become election dependencies. TTL ownership is not an external fencing token.

These diagrams are loaded directly from README assets published with the 0.4.0 release and pinned to its immutable commit. They describe this manual’s released structure and runtime flows, not later Snapshot changes. Select a preview to open the SVG at the same release commit.

leader-hazelcast implementation structure diagram

Section titled “leader-hazelcast implementation structure diagram”

leader-hazelcast implementation structure diagram

Release README: leader-hazelcast/README.md

Lock acquire/release sequence diagram

Release README: leader-hazelcast/README.md

Group election slot sequence (maxLeaders = N) diagram

Section titled “Group election slot sequence (maxLeaders = N) diagram”

Group election slot sequence (maxLeaders = N) diagram

Release README: leader-hazelcast/README.md

Elector · Lock implementation · Stable guide