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

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

final class Lock<K>
extends Object

A class used to represent locks.

Callers should only call non-Object methods on instances of this class if they hold the lock on the key map associated with the instance.

See Also:
LockManager

Field Summary
(package private)  K key
          The key that identifies this lock.
 
Constructor Summary
Lock(K key)
          Creates a lock.
 
Method Summary
(package private) static
<K> boolean
checkNoSync(LockManager<K> lockManager)
          Checks that the current thread is not synchronized on the map associated with a key, throwing AssertionError if it is, and otherwise returning true.
(package private)  boolean checkSync(LockManager<K> lockManager)
          Checks that the current thread is synchronized on the map associated with this lock, throwing AssertionError if it is not, and otherwise returning true.
(package private)  List<LockRequest<K>> copyOwners(LockManager<K> lockManager)
          Returns a possibly read-only copy of the lock requests for the owners.
(package private)  List<LockRequest<K>> copyWaiters(LockManager<K> lockManager)
          Returns a possibly read-only copy of the lock requests for the waiters.
(package private)  void flushWaiter(Locker<K> locker)
          Removes a locker from the list of waiters for this lock.
(package private)  boolean inUse(LockManager<K> lockManager)
          Returns whether this lock is currently in use, or whether it is not in use and can be removed from the lock table.
(package private)  boolean isOwner(LockRequest<K> request)
          Checks if the lock is already owned in a way the satisfies the specified request.
(package private)  LockAttemptResult<K> lock(Locker<K> locker, boolean forWrite, boolean waiting)
          Attempts to obtain this lock.
(package private) static
<K> boolean
noteSync(LockManager<K> lockManager, K key)
          Notes the start of synchronization on the map associated with key.
(package private) static
<K> boolean
noteUnsync(LockManager<K> lockManager, K key)
          Notes the end of synchronization on the map associated with key.
(package private)  List<Locker<K>> release(Locker<K> locker, boolean downgrade)
          Releases the ownership of this lock by the locker.
 String toString()
          Print fields, for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

key

final K key
The key that identifies this lock.

Constructor Detail

Lock

Lock(K key)
Creates a lock.

Parameters:
key - the key that identifies this lock
Method Detail

lock

LockAttemptResult<K> lock(Locker<K> locker,
                          boolean forWrite,
                          boolean waiting)
Attempts to obtain this lock. If waiting is true, the locker is known to be waiting for the lock, although it may also be waiting otherwise. Adds the locker as an owner of the lock if the lock was obtained, and removes the locker from the waiters list if it was waiting. Returns null if the locker already owned this lock. Otherwise, adds the locker to the waiters list, and returns a LockAttemptResult containing the LockRequest, with its conflict field set to null if the lock was acquired or a conflicting transaction if the lock could not be obtained.

Parameters:
locker - the locker requesting the lock
forWrite - whether a write lock is requested
waiting - whether the locker is known to be a waiter
Returns:
a LockAttemptResult or null

release

List<Locker<K>> release(Locker<K> locker,
                        boolean downgrade)
Releases the ownership of this lock by the locker. Attempts to acquire locks for current waiters, removing the ones that acquire the lock from the waiters list, adding them to the owners, and returning them.

Parameters:
locker - the locker whose ownership will be released
downgrade - whether to downgrade ownership from write to read rather than releasing all ownership
Returns:
the newly added owners

inUse

boolean inUse(LockManager<K> lockManager)
Returns whether this lock is currently in use, or whether it is not in use and can be removed from the lock table. Locks are in use if they have any owners or waiters.


copyOwners

List<LockRequest<K>> copyOwners(LockManager<K> lockManager)
Returns a possibly read-only copy of the lock requests for the owners.


copyWaiters

List<LockRequest<K>> copyWaiters(LockManager<K> lockManager)
Returns a possibly read-only copy of the lock requests for the waiters.


flushWaiter

void flushWaiter(Locker<K> locker)
Removes a locker from the list of waiters for this lock. The locker must be present in the list.


isOwner

boolean isOwner(LockRequest<K> request)
Checks if the lock is already owned in a way the satisfies the specified request.


noteSync

static <K> boolean noteSync(LockManager<K> lockManager,
                            K key)
Notes the start of synchronization on the map associated with key. Throws AssertionError if already synchronized on a key, otherwise returns true.


noteUnsync

static <K> boolean noteUnsync(LockManager<K> lockManager,
                              K key)
Notes the end of synchronization on the map associated with key. Throws AssertionError if not already synchronized on key, otherwise returns true.


checkNoSync

static <K> boolean checkNoSync(LockManager<K> lockManager)
Checks that the current thread is not synchronized on the map associated with a key, throwing AssertionError if it is, and otherwise returning true.


checkSync

boolean checkSync(LockManager<K> lockManager)
Checks that the current thread is synchronized on the map associated with this lock, throwing AssertionError if it is not, and otherwise returning true.


toString

public String toString()
Print fields, for debugging.

Overrides:
toString in class Object

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