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

java.lang.Object
  extended by com.sun.sgs.impl.util.lock.Locker<K>
Type Parameters:
K - the type of key
Direct Known Subclasses:
BasicLocker, MultiLocker

public abstract class Locker<K>
extends Object

Records information about an entity that requests locks from a LockManager.


Field Summary
(package private)  LockManager<K> lockManager
          The lock manager for this locker.
 
Constructor Summary
protected Locker(LockManager<K> lockManager)
          Creates an instance of this class.
 
Method Summary
(package private)  boolean checkAllowSync()
          Checks that the current thread is permitted to synchronize on this locker.
protected  void clearConflict()
          Clears the conflict that should cause this locker's current request to be denied.
protected  LockConflict<K> getConflict()
          Checks if there is a conflict that should cause this locker's current request to be denied.
 LockManager<K> getLockManager()
          Returns the lock manager for this locker.
protected  long getLockTimeoutTime(long now, long lockTimeout)
          Returns the time when a lock attempt should stop, given the current time and the lock timeout supplied by the caller.
(package private) abstract  LockAttemptResult<K> getWaitingFor()
          Checks if this locker is waiting for a lock.
protected  LockRequest<K> newLockRequest(K key, boolean forWrite, boolean upgrade)
          Creates a new lock request.
(package private)  boolean noteSync()
          Notes the start of synchronization on this locker.
(package private)  boolean noteUnsync()
          Notes the end of synchronization on this locker.
(package private) abstract  void setWaitingFor(LockAttemptResult<K> waitingFor)
          Records that this locker is waiting for a lock, or marks that it is not waiting if the argument is null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lockManager

final LockManager<K> lockManager
The lock manager for this locker.

Constructor Detail

Locker

protected Locker(LockManager<K> lockManager)
Creates an instance of this class.

Parameters:
lockManager - the lock manager for this locker
Method Detail

getLockManager

public LockManager<K> getLockManager()
Returns the lock manager for this locker.

Returns:
the lock manager for this locker.

getLockTimeoutTime

protected long getLockTimeoutTime(long now,
                                  long lockTimeout)
Returns the time when a lock attempt should stop, given the current time and the lock timeout supplied by the caller. Subclasses can override this method, for example to enforce a transaction timeout.

Parameters:
now - the current time in milliseconds
lockTimeout - the amount of time in milliseconds to wait for a lock
Returns:
the time in milliseconds when the lock attempt should timeout

newLockRequest

protected LockRequest<K> newLockRequest(K key,
                                        boolean forWrite,
                                        boolean upgrade)
Creates a new lock request.

The default implementation creates and returns an instance of LockRequest.

Parameters:
key - the key that identifies the lock
forWrite - whether the request is for write
upgrade - whether the request is for an upgrade
Returns:
the lock request

getConflict

protected LockConflict<K> getConflict()
Checks if there is a conflict that should cause this locker's current request to be denied. Returns null if there was no conflict.

The default implementation of this method always returns null.

Returns:
the conflicting request or null

clearConflict

protected void clearConflict()
Clears the conflict that should cause this locker's current request to be denied. If there is no conflict, then this method has no effect. If the conflict is a deadlock, represented by a non-null return value from getConflict with a type field equal to DEADLOCK, then the conflict cannot be cleared and IllegalStateException will be thrown.

The default implementation of this method does nothing.

Throws:
IllegalStateException - if the conflict is a deadlock

getWaitingFor

abstract LockAttemptResult<K> getWaitingFor()
Checks if this locker is waiting for a lock.

Returns:
the result of the attempt to request a lock that this locker is waiting for, or null if it is not waiting

setWaitingFor

abstract void setWaitingFor(LockAttemptResult<K> waitingFor)
Records that this locker is waiting for a lock, or marks that it is not waiting if the argument is null. If waitingFor is not null, then it should represent a conflict, and it's conflict field must not be null.

Parameters:
waitingFor - the lock or null
Throws:
IllegalArgumentException - if waitingFor is not null and its conflict field is null

checkAllowSync

boolean checkAllowSync()
Checks that the current thread is permitted to synchronize on this locker. Throws an AssertionError if already synchronized on a locker other than this one or any lock, otherwise returns true.


noteSync

boolean noteSync()
Notes the start of synchronization on this locker. Throws AssertionError if already synchronized on any locker or lock, otherwise returns true.


noteUnsync

boolean noteUnsync()
Notes the end of synchronization on this locker. Throws AssertionError if not already synchronized on this locker, otherwise returns true.


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