Class DistributedLocker
- java.lang.Object
-
- fr.ens.biologie.genomique.eoulsan.util.locker.DistributedLocker
-
- All Implemented Interfaces:
Locker,org.apache.zookeeper.Watcher
public class DistributedLocker extends Object implements Locker, org.apache.zookeeper.Watcher
This class implements a locker using Zookeeper based on Twiter's DistributedLock class. See @see Twitter Commons code.- Since:
- 2.0
- Author:
- Laurent Jourdren
-
-
Constructor Summary
Constructors Constructor Description DistributedLocker(String connectString, int sessionTimeout, String lockBasePath, String lockName)Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidlock()Wait the token and then lock the resource.voidprocess(org.apache.zookeeper.WatchedEvent event)voidunlock()Unlock the resource.
-
-
-
Constructor Detail
-
DistributedLocker
public DistributedLocker(String connectString, int sessionTimeout, String lockBasePath, String lockName) throws IOException
Public constructor.- Parameters:
connectString- Zookeeper connection stringsessionTimeout- session time outlockBasePath- lock base pathlockName- lock name- Throws:
IOException- if an error occurs while creating the ZooKeeper connection
-
-
Method Detail
-
lock
public void lock() throws IOExceptionDescription copied from interface:LockerWait the token and then lock the resource.- Specified by:
lockin interfaceLocker- Throws:
IOException- if an error occurs while locking the resource
-
unlock
public void unlock() throws IOExceptionDescription copied from interface:LockerUnlock the resource.- Specified by:
unlockin interfaceLocker- Throws:
IOException- if an error occurs while unlocking the resource
-
process
public void process(org.apache.zookeeper.WatchedEvent event)
- Specified by:
processin interfaceorg.apache.zookeeper.Watcher
-
-