org.objectweb.cjdbc.controller.scheduler.schema
Class TransactionExclusiveLock

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.scheduler.schema.TransactionExclusiveLock

public class TransactionExclusiveLock
extends java.lang.Object

A TransactionExclusiveLock is an exclusive lock that let the owner of the lock acquire several times the lock (but it needs to be released only once). Acquire supports timeout and graceful withdrawal of timed out requests.

Version:
1.0
Author:
Emmanuel Cecchet

Nested Class Summary
private  class TransactionExclusiveLock.WaitingListElement
          The element stored in the waiting list is the waiting thread and the transaction id of the request waiting.
 
Field Summary
private  boolean isLocked
           
private  long locker
          Transaction id of the lock holder.
private  java.util.ArrayList waitingList
          ArrayList of WaitingListElement.
 
Constructor Summary
TransactionExclusiveLock()
           
 
Method Summary
 boolean acquire(AbstractRequest request)
          Acquires an exclusive lock on this table.
 long getLocker()
          Returns the transaction id of the lock owner.
 java.util.ArrayList getWaitingList()
          Returns the waitingList.
 boolean isLocked()
          Returns true if the lock is owned by someone.
 boolean isWaiting(long transactionId)
          Returns true if the given transaction id is contained in this lock waiting queue.
 void release()
          Releases the lock on this table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isLocked

private boolean isLocked

locker

private long locker
Transaction id of the lock holder.


waitingList

private java.util.ArrayList waitingList
ArrayList of WaitingListElement.

Constructor Detail

TransactionExclusiveLock

public TransactionExclusiveLock()
Method Detail

acquire

public boolean acquire(AbstractRequest request)
Acquires an exclusive lock on this table. If the lock is already held by the same transaction as the given request, this method is non-blocking else the caller is blocked until the transaction holding the lock releases it at commit/rollback time.

Parameters:
request - request asking for the lock (timeout field is used and updated upon waiting)
Returns:
boolean true is the lock has been successfully acquired, false on timeout or error
See Also:
release()

release

public void release()
Releases the lock on this table.

See Also:
acquire(AbstractRequest)

isLocked

public boolean isLocked()
Returns true if the lock is owned by someone.

Returns:
boolean value

getLocker

public long getLocker()
Returns the transaction id of the lock owner. The return value is undefined if the lock is not owned (usually it is the last owner).

Returns:
int the transaction id.

getWaitingList

public java.util.ArrayList getWaitingList()
Returns the waitingList.

Returns:
an ArrayList of WaitingListElement

isWaiting

public boolean isWaiting(long transactionId)
Returns true if the given transaction id is contained in this lock waiting queue.

Parameters:
transactionId - a transaction id
Returns:
a boolean value


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.