public class ZookeeperLockRegistry extends Object implements ExpirableLockRegistry, DisposableBean
ExpirableLockRegistry
implementation using Zookeeper, or more specifically,
Curator InterProcessMutex
.Modifier and Type | Class and Description |
---|---|
static interface |
ZookeeperLockRegistry.KeyToPathStrategy
Strategy to convert a lock key (e.g.
|
Constructor and Description |
---|
ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client)
Construct a lock registry using the default
ZookeeperLockRegistry.KeyToPathStrategy which
simple appends the key to '/SpringIntegration-LockRegistry/'. |
ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client,
String root)
Construct a lock registry using the default
ZookeeperLockRegistry.KeyToPathStrategy which
simple appends the key to '<root>/' . |
ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client,
ZookeeperLockRegistry.KeyToPathStrategy keyToPath)
Construct a lock registry using the supplied
ZookeeperLockRegistry.KeyToPathStrategy . |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
expireUnusedOlderThan(long age)
Remove locks last acquired more than 'age' ago that are not currently locked.
|
Lock |
obtain(Object lockKey)
Obtains the lock associated with the parameter object.
|
void |
setMutexTaskExecutor(AsyncTaskExecutor mutexTaskExecutor)
Set an
AsyncTaskExecutor to use when establishing (and testing) the
connection with Zookeeper. |
public ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client)
ZookeeperLockRegistry.KeyToPathStrategy
which
simple appends the key to '/SpringIntegration-LockRegistry/'.client
- the CuratorFramework
.public ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client, String root)
ZookeeperLockRegistry.KeyToPathStrategy
which
simple appends the key to '<root>/'
.client
- the CuratorFramework
.root
- the path root (no trailing /).public ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client, ZookeeperLockRegistry.KeyToPathStrategy keyToPath)
ZookeeperLockRegistry.KeyToPathStrategy
.client
- the CuratorFramework
.keyToPath
- the implementation of ZookeeperLockRegistry.KeyToPathStrategy
.public void setMutexTaskExecutor(AsyncTaskExecutor mutexTaskExecutor)
AsyncTaskExecutor
to use when establishing (and testing) the
connection with Zookeeper. This must be performed asynchronously so the
Lock.tryLock(long, TimeUnit)
contract can be honored. While an executor is
used internally, an external executor may be required in some environments, for
example those that require the use of a WorkManagerTaskExecutor
.mutexTaskExecutor
- the executor.public Lock obtain(Object lockKey)
LockRegistry
obtain
in interface LockRegistry
lockKey
- The object with which the lock is associated.public void expireUnusedOlderThan(long age)
ZookeeperLockRegistry.KeyToPathStrategy
is bounded (returns a finite
number of paths). With such a ZookeeperLockRegistry.KeyToPathStrategy
, the overhead of tracking when
a lock is obtained is avoided.expireUnusedOlderThan
in interface ExpirableLockRegistry
age
- the time since the lock was last obtained.public void destroy()
destroy
in interface DisposableBean