Implements atomic distributed Long using optimistic locking mechanism.
Implements atomic distributed Long using optimistic locking mechanism. The principle of changing the persisted counter/long value is to: 1) read the value from Consul including the latest ModificationIndex. 2) store the updated value to Consul using compare-and-set with the read ModificationIndex. Should the write fail due to concurrency issues, we loop back to step 1 and try again. Generally all operations will fail if there is no such key/path or the key doesn't have a numerical value.
Represents a candidate in the leader election
Encapsulates functions towards Consul.
Observer to be notified for changes in election state.
A semaphore is a construction to control access to a common resource in a concurrent system.
A semaphore is a construction to control access to a common resource in a concurrent system. The semaphore in this library allows for creation of a distributed lock. In principle a semaphore is initiated with 1..n permits, instances of a semaphore then try to acquire one permit either succeeding or failing in case there are no more permits left to take. The simplest form is a binary semaphore which has only one permit thus only allowing a single instance to acquire a permit. Semaphores are traditionally used to control access to a protected source like a database or some task that only should be executed by a single process.
Each instance of the Semaphore class can hold exactly 0 or 1 permit thus invoking any of the tryAcquire functions mulitple times will not acquire additional permits.
Companion object to CASLong
Companion object to Consul
Factory for creating candidates for leader election
Companion object to Semaphore