Class ZooKeeperLocker

java.lang.Object
fr.ens.biologie.genomique.eoulsan.util.locker.ZooKeeperLocker
All Implemented Interfaces:
Locker, org.apache.zookeeper.Watcher

public class ZooKeeperLocker extends Object implements Locker, org.apache.zookeeper.Watcher
This class implements a locker using Zookeeper. See @see blog post.
Since:
2.0
Author:
Laurent Jourdren
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher

    org.apache.zookeeper.Watcher.Event
  • Constructor Summary

    Constructors
    Constructor
    Description
    ZooKeeperLocker(String connectString, int sessionTimeout, String lockBasePath, String lockName)
    Public constructor.
    ZooKeeperLocker(String connectString, int sessionTimeout, String lockBasePath, String lockName, boolean sequentialLockName)
    Public constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Wait the token and then lock the resource.
    void
    process(org.apache.zookeeper.WatchedEvent event)
     
    void
    Unlock the resource.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ZooKeeperLocker

      public ZooKeeperLocker(String connectString, int sessionTimeout, String lockBasePath, String lockName) throws IOException
      Public constructor.
      Parameters:
      connectString - Zookeeper connection string
      sessionTimeout - session time out
      lockBasePath - lock base path
      lockName - lock name
      Throws:
      IOException - if an error occurs while creating the ZooKeeper connection
    • ZooKeeperLocker

      public ZooKeeperLocker(String connectString, int sessionTimeout, String lockBasePath, String lockName, boolean sequentialLockName) throws IOException
      Public constructor.
      Parameters:
      connectString - Zookeeper connection string
      sessionTimeout - session time out
      lockBasePath - lock base path
      lockName - lock name
      sequentialLockName - sequential lock
      Throws:
      IOException - if an error occurs while creating the ZooKeeper connection
  • Method Details

    • lock

      public void lock() throws IOException
      Description copied from interface: Locker
      Wait the token and then lock the resource.
      Specified by:
      lock in interface Locker
      Throws:
      IOException - if an error occurs while locking the resource
    • unlock

      public void unlock() throws IOException
      Description copied from interface: Locker
      Unlock the resource.
      Specified by:
      unlock in interface Locker
      Throws:
      IOException - if an error occurs while unlocking the resource
    • process

      public void process(org.apache.zookeeper.WatchedEvent event)
      Specified by:
      process in interface org.apache.zookeeper.Watcher