Class LockService.LockImpl

java.lang.Object
org.jgroups.blocks.locking.LockService.LockImpl
All Implemented Interfaces:
Lock
Enclosing class:
LockService

protected class LockService.LockImpl extends Object implements Lock
Implementation of Lock. This is a client stub communicates with a server equivalent. The semantics are more or less those of Lock, but may differ slightly.

There is no reference counting of lock owners, so acquisition of a lock already held by a thread is a no-op. Also, releasing the lock after it was already released is a no-op as well.

An exact description is provided below.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final AtomicReference<Thread>
     
    protected final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Blocks until the lock has been acquired.
    void
    If the thread is interrupted at entry, the call will throw an InterruptedException immediately and the lock won't be acquired.
    This condition object is only allowed to work 1 for each lock.
     
    boolean
    If the thread is interrupted at entry or during the call, no InterruptedException will be thrown, but the thread's status will be set to interrupted upon return.
    boolean
    tryLock(long time, TimeUnit unit)
    * If the thread is interrupted at entry, the call will throw an InterruptedException immediately and the lock won't be acquired.
    void
    Releases a lock.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • LockImpl

      public LockImpl(String name)
  • Method Details

    • lock

      public void lock()
      Blocks until the lock has been acquired. Masks interrupts; if an interrupt was received on entry or while waiting for the lock acquisition, it won't cause the call to return. However, the thread's status will be set to interrupted when the call returns.
      Specified by:
      lock in interface Lock
    • lockInterruptibly

      public void lockInterruptibly() throws InterruptedException
      If the thread is interrupted at entry, the call will throw an InterruptedException immediately and the lock won't be acquired. If the thread is interrupted while waiting for the lock acquition, an InterruptedException will also be thrown immediately. The thread's interrupt status will not be set after the call returns.
      Specified by:
      lockInterruptibly in interface Lock
      Throws:
      InterruptedException
    • tryLock

      public boolean tryLock()
      If the thread is interrupted at entry or during the call, no InterruptedException will be thrown, but the thread's status will be set to interrupted upon return. An interrupt has therefore no impact on the return value (success or failure).
      Specified by:
      tryLock in interface Lock
    • tryLock

      public boolean tryLock(long time, TimeUnit unit) throws InterruptedException
      * If the thread is interrupted at entry, the call will throw an InterruptedException immediately and the lock won't be acquired. If the thread is interrupted while waiting for the lock acquition, an InterruptedException will also be thrown immediately. The thread's interrupt status will not be set after the call returns.
      Specified by:
      tryLock in interface Lock
      Parameters:
      time -
      unit -
      Returns:
      Throws:
      InterruptedException
    • unlock

      public void unlock()
      Releases a lock. Contrary to the parent's implementation, this method can be called more than once: the release of a lock that has already been released, or is not owned by this thread is a no-op.
      Specified by:
      unlock in interface Lock
    • newCondition

      public Condition newCondition()
      This condition object is only allowed to work 1 for each lock. If more than 1 condition is created for this lock, they both will be awaiting/signalling on the same lock
      Specified by:
      newCondition in interface Lock
    • toString

      public String toString()
      Overrides:
      toString in class Object