Class InterProcessSemaphoreMutex

  • All Implemented Interfaces:

    public class InterProcessSemaphoreMutex
    extends Object
    implements InterProcessLock
    A NON re-entrant mutex that works across JVMs. Uses Zookeeper to hold the lock. All processes in all JVMs that use the same lock path will achieve an inter-process critical section.
    • Constructor Detail

      • InterProcessSemaphoreMutex

        public InterProcessSemaphoreMutex​(CuratorFramework client,
                                          String path)
        client - the client
        path - path for the lock
    • Method Detail

      • acquire

        public boolean acquire​(long time,
                               TimeUnit unit)
                        throws Exception
        Description copied from interface: InterProcessLock
        Acquire the mutex - blocks until it's available or the given time expires. Each call to acquire that returns true must be balanced by a call to InterProcessLock.release()
        Specified by:
        acquire in interface InterProcessLock
        time - time to wait
        unit - time unit
        true if the mutex was acquired, false if not
        Exception - ZK errors, connection interruptions
      • release

        public void release()
                     throws Exception
        Perform one release of the mutex.

        NOTE: Unlike other implementations of InterProcessLock.release(), this method will NOT throw an exception if it is called on a different thread than the one which acquired the lock.

        Specified by:
        release in interface InterProcessLock
        Exception - ZK errors, interruptions