com.sleepycat.je.txn
Class LockImpl

java.lang.Object
  extended by com.sleepycat.je.txn.LockImpl
All Implemented Interfaces:
Lock

public class LockImpl
extends Object
implements Lock

A Lock embodies the lock state of a NodeId. It includes a set of owners and a list of waiters.


Constructor Summary
LockImpl()
          Create a Lock.
LockImpl(LockInfo firstOwner)
           
 
Method Summary
 void demote(Locker locker)
          Downgrade a write lock to a read lock.
 void flushWaiter(Locker locker, MemoryBudget mb, int lockTableIndex)
          Remove this locker from the waiter list.
 Set<LockInfo> getOwnersClone()
          Get a new Set of the owners.
 List<LockInfo> getWaitersListClone()
          Get a list of waiters for debugging and error messages.
 Locker getWriteOwnerLocker()
          Return the locker that has a write ownership on this lock.
 boolean isOwnedWriteLock(Locker locker)
          Return true if locker is an owner of this Lock and this is a write lock.
 boolean isOwner(Locker locker, LockType lockType)
          Return true if locker is an owner of this Lock for lockType, false otherwise.
 boolean isThin()
           
 boolean isWaiter(Locker locker)
          Return true if locker is a waiter on this Lock.
 LockAttemptResult lock(LockType requestType, Locker locker, boolean nonBlockingRequest, MemoryBudget mb, int lockTableIndex)
          Attempts to acquire the lock and returns the LockGrantType.
 int nOwners()
           
 int nWaiters()
           
 Set<Locker> release(Locker locker, MemoryBudget mb, int lockTableIndex)
          Releases a lock and moves the next waiter(s) to the owners.
 void stealLock(Locker locker, MemoryBudget mb, int lockTableIndex)
          Removes all owners except for the given owner, and sets the Preempted property on the removed owners.
 String toString()
          Debug dumper.
 Lock transfer(Long nodeId, Locker currentLocker, Locker destLocker, MemoryBudget mb, int lockTableIndex)
          Transfer a lock from one transaction to another.
 Lock transferMultiple(Long nodeId, Locker currentLocker, Locker[] destLockers, MemoryBudget mb, int lockTableIndex)
          Transfer a lock from one transaction to many others.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LockImpl

public LockImpl()
Create a Lock.


LockImpl

LockImpl(LockInfo firstOwner)
Method Detail

getWaitersListClone

public List<LockInfo> getWaitersListClone()
Get a list of waiters for debugging and error messages.

Specified by:
getWaitersListClone in interface Lock

flushWaiter

public void flushWaiter(Locker locker,
                        MemoryBudget mb,
                        int lockTableIndex)
Remove this locker from the waiter list.

Specified by:
flushWaiter in interface Lock

getOwnersClone

public Set<LockInfo> getOwnersClone()
Get a new Set of the owners.

Specified by:
getOwnersClone in interface Lock

isOwner

public boolean isOwner(Locker locker,
                       LockType lockType)
Return true if locker is an owner of this Lock for lockType, false otherwise. This method is only used by unit tests.

Specified by:
isOwner in interface Lock

isOwnedWriteLock

public boolean isOwnedWriteLock(Locker locker)
Return true if locker is an owner of this Lock and this is a write lock.

Specified by:
isOwnedWriteLock in interface Lock

isWaiter

public boolean isWaiter(Locker locker)
Return true if locker is a waiter on this Lock. This method is only used by unit tests.

Specified by:
isWaiter in interface Lock

nWaiters

public int nWaiters()
Specified by:
nWaiters in interface Lock

nOwners

public int nOwners()
Specified by:
nOwners in interface Lock

lock

public LockAttemptResult lock(LockType requestType,
                              Locker locker,
                              boolean nonBlockingRequest,
                              MemoryBudget mb,
                              int lockTableIndex)
Attempts to acquire the lock and returns the LockGrantType. Assumes we hold the lockTableLatch when entering this method.

Specified by:
lock in interface Lock

release

public Set<Locker> release(Locker locker,
                           MemoryBudget mb,
                           int lockTableIndex)
Releases a lock and moves the next waiter(s) to the owners.

Specified by:
release in interface Lock
Returns:
null if we were not the owner, a non-empty set if owners should be notified after releasing, an empty set if no notification is required.

stealLock

public void stealLock(Locker locker,
                      MemoryBudget mb,
                      int lockTableIndex)
Description copied from interface: Lock
Removes all owners except for the given owner, and sets the Preempted property on the removed owners.

Specified by:
stealLock in interface Lock

demote

public void demote(Locker locker)
Downgrade a write lock to a read lock.

Specified by:
demote in interface Lock

transfer

public Lock transfer(Long nodeId,
                     Locker currentLocker,
                     Locker destLocker,
                     MemoryBudget mb,
                     int lockTableIndex)
              throws DatabaseException
Transfer a lock from one transaction to another. Make sure that this destination locker is only present as a single reader or writer.

Specified by:
transfer in interface Lock
Throws:
DatabaseException

transferMultiple

public Lock transferMultiple(Long nodeId,
                             Locker currentLocker,
                             Locker[] destLockers,
                             MemoryBudget mb,
                             int lockTableIndex)
                      throws DatabaseException
Transfer a lock from one transaction to many others. Only really needed for case where a write handle lock is being transferred to multiple read handles.

Specified by:
transferMultiple in interface Lock
Throws:
DatabaseException

getWriteOwnerLocker

public Locker getWriteOwnerLocker()
Return the locker that has a write ownership on this lock. If no write owner exists, return null.

Specified by:
getWriteOwnerLocker in interface Lock

isThin

public boolean isThin()
Specified by:
isThin in interface Lock

toString

public String toString()
Debug dumper.

Specified by:
toString in interface Lock
Overrides:
toString in class Object


Copyright (c) 2004-2010 Oracle. All rights reserved.