Class ZookeeperLockRegistry
java.lang.Object
org.springframework.integration.zookeeper.lock.ZookeeperLockRegistry
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean,org.springframework.integration.support.locks.ExpirableLockRegistry,org.springframework.integration.support.locks.LockRegistry
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.- Since:
- 4.2
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceZookeeperLockRegistry.KeyToPathStrategyStrategy to convert a lock key (e.g. -
Constructor Summary
Constructors Constructor Description ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client)Construct a lock registry using the defaultZookeeperLockRegistry.KeyToPathStrategywhich simple appends the key to '/SpringIntegration-LockRegistry/'.ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client, java.lang.String root)Construct a lock registry using the defaultZookeeperLockRegistry.KeyToPathStrategywhich simple appends the key to'<root>/'.ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client, ZookeeperLockRegistry.KeyToPathStrategy keyToPath)Construct a lock registry using the suppliedZookeeperLockRegistry.KeyToPathStrategy. -
Method Summary
Modifier and Type Method Description voiddestroy()voidexpireUnusedOlderThan(long age)Remove locks last acquired more than 'age' ago that are not currently locked.java.util.concurrent.locks.Lockobtain(java.lang.Object lockKey)voidsetMutexTaskExecutor(org.springframework.core.task.AsyncTaskExecutor mutexTaskExecutor)Set anAsyncTaskExecutorto use when establishing (and testing) the connection with Zookeeper.
-
Constructor Details
-
ZookeeperLockRegistry
public ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client)Construct a lock registry using the defaultZookeeperLockRegistry.KeyToPathStrategywhich simple appends the key to '/SpringIntegration-LockRegistry/'.- Parameters:
client- theCuratorFramework.
-
ZookeeperLockRegistry
public ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client, java.lang.String root)Construct a lock registry using the defaultZookeeperLockRegistry.KeyToPathStrategywhich simple appends the key to'<root>/'.- Parameters:
client- theCuratorFramework.root- the path root (no trailing /).
-
ZookeeperLockRegistry
public ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client, ZookeeperLockRegistry.KeyToPathStrategy keyToPath)Construct a lock registry using the suppliedZookeeperLockRegistry.KeyToPathStrategy.- Parameters:
client- theCuratorFramework.keyToPath- the implementation ofZookeeperLockRegistry.KeyToPathStrategy.
-
-
Method Details
-
setMutexTaskExecutor
public void setMutexTaskExecutor(org.springframework.core.task.AsyncTaskExecutor mutexTaskExecutor)Set anAsyncTaskExecutorto use when establishing (and testing) the connection with Zookeeper. This must be performed asynchronously so theLock.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 aWorkManagerTaskExecutor.- Parameters:
mutexTaskExecutor- the executor.- Since:
- 4.2.10
-
obtain
public java.util.concurrent.locks.Lock obtain(java.lang.Object lockKey)- Specified by:
obtainin interfaceorg.springframework.integration.support.locks.LockRegistry
-
expireUnusedOlderThan
public void expireUnusedOlderThan(long age)Remove locks last acquired more than 'age' ago that are not currently locked. Expiry is not supported if theZookeeperLockRegistry.KeyToPathStrategyis bounded (returns a finite number of paths). With such aZookeeperLockRegistry.KeyToPathStrategy, the overhead of tracking when a lock is obtained is avoided.- Specified by:
expireUnusedOlderThanin interfaceorg.springframework.integration.support.locks.ExpirableLockRegistry- Parameters:
age- the time since the lock was last obtained.
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-