com.sun.sgs.impl.util.lock
Class TxnLockManager<K>

java.lang.Object
  extended by com.sun.sgs.impl.util.lock.LockManager<K>
      extended by com.sun.sgs.impl.util.lock.TxnLockManager<K>
Type Parameters:
K - the type of key

public final class TxnLockManager<K>
extends LockManager<K>

A class for managing lock conflicts of a transaction. Calls on behalf of a locker should only be made from a single thread at a time. All Locker objects supplied to this class should be instances of TxnLocker.

This implementation checks for deadlock whenever a lock request is blocked due to a conflict. It selects as the deadlock victim the locker with the latest requested start time. The implementation does not deny requests that would not result in deadlock. When requests block, it services the requests in the order that they arrive.

This class and its superclass use the Logger named com.sun.sgs.impl.util.lock to log information at the following logging levels:


Field Summary
 
Fields inherited from class com.sun.sgs.impl.util.lock.LockManager
currentKeySync, currentLockerSync, logger
 
Constructor Summary
TxnLockManager(long lockTimeout, int numKeyMaps)
          Creates an instance of this class.
 
Method Summary
 LockConflict<K> lock(Locker<K> locker, K key, boolean forWrite)
          Attempts to acquire a lock, waiting if needed.
 LockConflict<K> lockNoWait(Locker<K> locker, K key, boolean forWrite)
          Attempts to acquire a lock, returning immediately.
(package private)  LockConflict<K> lockNoWaitInternal(Locker<K> locker, K key, boolean forWrite)
          Attempts to acquire a lock, returning immediately.
 LockConflict<K> waitForLock(Locker<K> locker)
          Waits for a previous attempt to obtain a lock that blocked.
 
Methods inherited from class com.sun.sgs.impl.util.lock.LockManager
getKeyMap, getLock, getOwners, getWaiters, releaseLock, releaseLockInternal, waitForLockInternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TxnLockManager

public TxnLockManager(long lockTimeout,
                      int numKeyMaps)
Creates an instance of this class.

Parameters:
lockTimeout - the maximum number of milliseconds to acquire a lock
numKeyMaps - the number of separate maps to use for storing keys
Throws:
IllegalArgumentException - if lockTimeout or numKeyMaps is less than 1
Method Detail

lock

public LockConflict<K> lock(Locker<K> locker,
                            K key,
                            boolean forWrite)
Attempts to acquire a lock, waiting if needed. Returns information about conflicts that occurred while attempting to acquire the lock that prevented the lock from being acquired, or else null if the lock was acquired. If the type field of the return value is DEADLOCK, then the caller should abort the transaction, and any subsequent lock or wait requests will throw IllegalStateException. Otherwise, the caller can repeat this call, and any conflicts from earlier calls will be ignored.

Overrides:
lock in class LockManager<K>
Parameters:
locker - the locker requesting the lock
key - the key identifying the lock
forWrite - whether to request a write lock
Returns:
lock conflict information, or null if there was no conflict
Throws:
IllegalArgumentException - if locker has a different lock manager, or if locker is not an instance of TxnLocker

lockNoWait

public LockConflict<K> lockNoWait(Locker<K> locker,
                                  K key,
                                  boolean forWrite)
Attempts to acquire a lock, returning immediately. Returns information about any conflict that occurred while attempting to acquire the lock, or else null if the lock was acquired. If the attempt to acquire the lock was blocked, returns a value with a type field of BLOCKED rather than waiting. If the type field of the return value is DEADLOCK, then the caller should abort the transaction, and any subsequent lock or wait requests will throw IllegalStateException. Otherwise, the caller can repeat this call, and any conflicts from earlier calls will be ignored.

Overrides:
lockNoWait in class LockManager<K>
Parameters:
locker - the locker requesting the lock
key - the key identifying the lock
forWrite - whether to request a write lock
Returns:
lock conflict information, or null if there was no conflict
Throws:
IllegalArgumentException - if locker has a different lock manager, or if locker is not an instance of TxnLocker

waitForLock

public LockConflict<K> waitForLock(Locker<K> locker)
Waits for a previous attempt to obtain a lock that blocked. Returns information about any conflict that occurred while attempting to acquire the lock, or else null if the lock was acquired or the transaction was not waiting. If the type field of the return value is DEADLOCK, then the caller should abort the transaction, and any subsequent lock or wait requests will throw IllegalStateException.

Overrides:
waitForLock in class LockManager<K>
Parameters:
locker - the locker requesting the lock
Returns:
lock conflict information, or null if there was no conflict
Throws:
IllegalArgumentException - if locker has a different lock manager, or if locker is not an instance of TxnLocker

lockNoWaitInternal

LockConflict<K> lockNoWaitInternal(Locker<K> locker,
                                   K key,
                                   boolean forWrite)
Attempts to acquire a lock, returning immediately. Like LockManager.lockNoWait(com.sun.sgs.impl.util.lock.Locker, K, boolean), but does not check that the correct lock manager was supplied.

This implementation calls the deadlock checker if the request blocks.

Overrides:
lockNoWaitInternal in class LockManager<K>
Parameters:
locker - the locker requesting the lock
key - the key identifying the lock
forWrite - whether to request a write lock
Returns:
lock conflict information, or null if there was no conflict
Throws:
IllegalStateException - if an earlier lock attempt for this transaction produced a deadlock, or if still waiting for an earlier attempt to complete

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved