A counting semaphore that works across JVMs. All processes in all JVMs that use the same lock path will achieve an inter-process limited set of leases. Further, this semaphore is mostly "fair" - each user will get a lease in the order requested (from ZK's point of view).
There are two modes for determining the max leases for the semaphore. In the first mode the max leases is a convention maintained by the users of a given path. In the second mode a {@link SharedCountReader} is used as the method for semaphores of a given path to determinethe max leases.
If a {@link SharedCountReader} is not used, no internal checks are done to preventProcess A acting as if there are 10 leases and Process B acting as if there are 20. Therefore, make sure that all instances in all processes use the same numberOfLeases value.
The various acquire methods return {@link Lease} objects that represent acquired leases. Clientsmust take care to close lease objects (ideally in a finally
block) else the lease will be lost. However, if the client session drops (crash, etc.), any leases held by the client are automatically closed and made available to other clients.
Thanks to Ben Bangert (ben@groovie.org) for the algorithm used.
|
|
|
|
|
|