Class ZookeeperLockRegistry
java.lang.Object
org.springframework.integration.zookeeper.lock.ZookeeperLockRegistry
- All Implemented Interfaces:
- DisposableBean,- ExpirableLockRegistry,- LockRegistry
ExpirableLockRegistry implementation using Zookeeper, or more specifically,
 Curator InterProcessMutex.- Since:
- 4.2
- Author:
- Gary Russell, Artem Bilan, Vedran Pavic, Unseok Kim, Christian Tzolov
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceStrategy to convert a lock key (e.g.
- 
Constructor SummaryConstructorsConstructorDescriptionZookeeperLockRegistry(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, 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 SummaryModifier and TypeMethodDescriptionvoiddestroy()voidexpireUnusedOlderThan(long age) Remove locks last acquired more than 'age' ago that are not currently locked.Obtain the lock associated with the parameter object.voidsetCacheCapacity(int cacheCapacity) Set the capacity of cached locks.voidsetMutexTaskExecutor(AsyncTaskExecutor mutexTaskExecutor) Set anAsyncTaskExecutorto use when establishing (and testing) the connection with Zookeeper.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.integration.support.locks.LockRegistryexecuteLocked, executeLocked, executeLocked, executeLocked
- 
Constructor Details- 
ZookeeperLockRegistrypublic ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client) Construct a lock registry using the defaultZookeeperLockRegistry.KeyToPathStrategywhich simple appends the key to '/SpringIntegration-LockRegistry/'.- Parameters:
- client- the- CuratorFramework.
 
- 
ZookeeperLockRegistryConstruct a lock registry using the defaultZookeeperLockRegistry.KeyToPathStrategywhich simple appends the key to'<root>/'.- Parameters:
- client- the- CuratorFramework.
- root- the path root (no trailing /).
 
- 
ZookeeperLockRegistrypublic ZookeeperLockRegistry(org.apache.curator.framework.CuratorFramework client, ZookeeperLockRegistry.KeyToPathStrategy keyToPath) Construct a lock registry using the suppliedZookeeperLockRegistry.KeyToPathStrategy.- Parameters:
- client- the- CuratorFramework.
- keyToPath- the implementation of- ZookeeperLockRegistry.KeyToPathStrategy.
 
 
- 
- 
Method Details- 
setMutexTaskExecutorSet 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
 
- 
setCacheCapacitypublic void setCacheCapacity(int cacheCapacity) Set the capacity of cached locks.- Parameters:
- cacheCapacity- The capacity of cached lock, (default 30_000).
- Since:
- 5.5.6
 
- 
obtainDescription copied from interface:LockRegistryObtain the lock associated with the parameter object.- Specified by:
- obtainin interface- LockRegistry
- Parameters:
- lockKey- The object with which the lock is associated.
- Returns:
- The associated lock.
 
- 
expireUnusedOlderThanpublic 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 interface- ExpirableLockRegistry
- Parameters:
- age- the time since the lock was last obtained.
 
- 
destroypublic void destroy()- Specified by:
- destroyin interface- DisposableBean
 
 
-