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

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

public class TxnLocker<K>
extends BasicLocker<K>

Records information about an entity that requests locks from a TxnLockManager as part of a transaction.


Field Summary
protected  long requestedStartTime
          The time in milliseconds when the associated transaction was originally requested to start.
protected  Transaction txn
          The associated transaction.
 
Fields inherited from class com.sun.sgs.impl.util.lock.Locker
lockManager
 
Constructor Summary
TxnLocker(TxnLockManager<K> lockManager, Transaction txn, long requestedStartTime)
          Creates an instance of this class.
 
Method Summary
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.
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.
 long getRequestedStartTime()
          Returns the time in milliseconds that the transaction associated with this locker was originally requested to start, as specified in the constructor.
 Transaction getTransaction()
          Returns the transaction associated with this locker.
protected  void setConflict(LockConflict<K> conflict)
          Specifies a conflict that should cause this locker's current request to be denied, and notifies waiters.
 
Methods inherited from class com.sun.sgs.impl.util.lock.BasicLocker
getWaitingFor, setWaitingFor
 
Methods inherited from class com.sun.sgs.impl.util.lock.Locker
checkAllowSync, getLockManager, newLockRequest, noteSync, noteUnsync
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

txn

protected final Transaction txn
The associated transaction.


requestedStartTime

protected final long requestedStartTime
The time in milliseconds when the associated transaction was originally requested to start.

Constructor Detail

TxnLocker

public TxnLocker(TxnLockManager<K> lockManager,
                 Transaction txn,
                 long requestedStartTime)
Creates an instance of this class.

Parameters:
lockManager - the lock manager for this locker
txn - the associated transaction
requestedStartTime - the time in milliseconds that the task associated with the transaction was originally requested to start
Throws:
IllegalArgumentException - if requestedStartTime is less than 0
Method Detail

getTransaction

public Transaction getTransaction()
Returns the transaction associated with this locker.

Returns:
the transaction associated with this locker

getRequestedStartTime

public long getRequestedStartTime()
Returns the time in milliseconds that the transaction associated with this locker was originally requested to start, as specified in the constructor.

Returns:
the requested start time in milliseconds

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.

This implementation stops the lock attempt when the transaction ends.

Overrides:
getLockTimeoutTime in class Locker<K>
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

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.

This implementation returns the conflict recorded for this locker.

Overrides:
getConflict in class Locker<K>
Returns:
the conflicting request or null
Throws:
IllegalStateException

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.

This implementation checks for deadlocks and notifies waiters.

Overrides:
clearConflict in class Locker<K>
Throws:
IllegalStateException - if the conflict is a deadlock

setConflict

protected void setConflict(LockConflict<K> conflict)
Specifies a conflict that should cause this locker's current request to be denied, and notifies waiters.

Parameters:
conflict - the conflicting request
Throws:
IllegalStateException - if a conflicting request has already been specified

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