public class ZookeeperLockRegistry
extends java.lang.Object
implements org.springframework.integration.support.locks.ExpirableLockRegistry, org.springframework.beans.factory.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,
java.lang.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.
|
java.util.concurrent.locks.Lock |
obtain(java.lang.Object lockKey) |
void |
setMutexTaskExecutor(org.springframework.core.task.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,
java.lang.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(org.springframework.core.task.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 java.util.concurrent.locks.Lock obtain(java.lang.Object lockKey)
obtain in interface org.springframework.integration.support.locks.LockRegistrypublic 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 org.springframework.integration.support.locks.ExpirableLockRegistryage - the time since the lock was last obtained.public void destroy()
throws java.lang.Exception
destroy in interface org.springframework.beans.factory.DisposableBeanjava.lang.Exception