Class SimpleSemaphore

  • All Implemented Interfaces:
    Semaphore

    public class SimpleSemaphore
    extends java.lang.Object
    implements Semaphore
    Internal in-memory lock handler for providing thread/resource locking in order to protect resources from being altered by multiple threads at the same time.
    Author:
    jhouse
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleSemaphore()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.slf4j.Logger getLog()  
      boolean isLockOwner​(java.lang.String lockName)
      Determine whether the calling thread owns a lock on the identified resource.
      boolean obtainLock​(java.sql.Connection conn, java.lang.String lockName)
      Grants a lock on the identified resource to the calling thread (blocking until it is available).
      void releaseLock​(java.lang.String lockName)
      Release the lock on the identified resource if it is held by the calling thread.
      boolean requiresConnection()
      This Semaphore implementation does not use the database.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleSemaphore

        public SimpleSemaphore()
    • Method Detail

      • getLog

        protected org.slf4j.Logger getLog()
      • obtainLock

        public boolean obtainLock​(java.sql.Connection conn,
                                  java.lang.String lockName)
        Grants a lock on the identified resource to the calling thread (blocking until it is available).
        Specified by:
        obtainLock in interface Semaphore
        Parameters:
        conn - Database connection used to establish lock. Can be null if Semaphore.requiresConnection() returns false.
        Returns:
        true if the lock was obtained.
      • releaseLock

        public void releaseLock​(java.lang.String lockName)
        Release the lock on the identified resource if it is held by the calling thread.
        Specified by:
        releaseLock in interface Semaphore
      • isLockOwner

        public boolean isLockOwner​(java.lang.String lockName)
        Determine whether the calling thread owns a lock on the identified resource.