org.eclipse.emf.transaction.util
Class EmptyLock

java.lang.Object
  extended by org.eclipse.emf.transaction.util.EmptyLock
All Implemented Interfaces:
ITransactionLock

public final class EmptyLock
extends Object
implements ITransactionLock

A lock which does not provide any mutual exclusion. This implementation is needed for rudimentary standalone scenario support.

Since:
1.4

Constructor Summary
EmptyLock()
           
 
Method Summary
 void acquire(boolean exclusive)
          Acquires me, waiting as long as necessary or until I am interrupted.
 boolean acquire(long timeout, boolean exclusive)
          Attempts to acquire me, timing out after the specified number of millis.
 void checkedTransfer(Thread thread)
           
 int getDepth()
          Queries the depth to which I am acquired by the calling thread.
 Thread getOwner()
          Queries the current owner of the lock.
 void release()
          Releases me.
 void uiSafeAcquire(boolean exclusive)
          Attempts to acquire me (without a timeout) in a manner that is safe to execute on the UI thread.
 boolean yield()
          Temporarily yields the lock to another thread that does not require exclusive access, if any such thread exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmptyLock

public EmptyLock()
Method Detail

acquire

public void acquire(boolean exclusive)
             throws InterruptedException
Description copied from interface: ITransactionLock
Acquires me, waiting as long as necessary or until I am interrupted. if I already own this lock, then its lock depth is increased. That means one more call to ITransactionLock.release() for me to make.

Note: The current thread must not own my monitor when it calls this method, otherwise it will cause deadlock. Deadlock would be guaranteed because every thread waits on a different object that is not me, so my monitor is not released when the calling thread blocks.

Specified by:
acquire in interface ITransactionLock
Parameters:
exclusive - true if the current thread needs exclusive access (i.e., no other threads may currently be yielding me); false, otherwise
Throws:
InterruptedException - on interruption of the calling thread

acquire

public boolean acquire(long timeout,
                       boolean exclusive)
                throws InterruptedException
Description copied from interface: ITransactionLock
Attempts to acquire me, timing out after the specified number of millis.

Note: The current thread must not own my monitor when it calls this method, otherwise it will cause deadlock. Deadlock would be guaranteed because every thread waits on a different object that is not me, so my monitor is not released when the calling thread blocks.

Specified by:
acquire in interface ITransactionLock
Parameters:
timeout - the number of milliseconds to wait before giving up on the lock, or 0 to wait as long as necessary
exclusive - true if the current thread needs exclusive access (i.e., no other threads may currently be yielding me); false, otherwise
Returns:
true if the caller successfully acquired me; false if it did not within the timeout
Throws:
InterruptedException - on interruption of the calling thread

checkedTransfer

public void checkedTransfer(Thread thread)
Specified by:
checkedTransfer in interface ITransactionLock

getDepth

public int getDepth()
Description copied from interface: ITransactionLock
Queries the depth to which I am acquired by the calling thread. This is the number of times the calling thread has acquired me and not yet released. Note that if the calling thread does not own me, I appear to have a depth of zero. Acquiring in this case will wait for the owning thread to finish releasing.

Specified by:
getDepth in interface ITransactionLock
Returns:
my depth

getOwner

public Thread getOwner()
Description copied from interface: ITransactionLock
Queries the current owner of the lock.

Specified by:
getOwner in interface ITransactionLock
Returns:
the thread that owns me, or null if I am available

release

public void release()
Description copied from interface: ITransactionLock
Releases me. Note that my depth may still be positive, in which case I would need to be released again (recursively).

Specified by:
release in interface ITransactionLock

uiSafeAcquire

public void uiSafeAcquire(boolean exclusive)
                   throws InterruptedException
Description copied from interface: ITransactionLock
Attempts to acquire me (without a timeout) in a manner that is safe to execute on the UI thread. This ensures that, in an Eclipse UI environment, if the UI thread is blocked waiting for me, the Job Manager will show the block dialog to inform the user of what is happening.

If this method is called from a thread that is running as a Job, then it behaves identically to ITransactionLock.acquire(boolean).

Note: The current thread must not own my monitor when it calls this method, otherwise it will cause deadlock. Deadlock would be guaranteed because every thread waits on a different object that is not me, so my monitor is not released when the calling thread blocks.

Specified by:
uiSafeAcquire in interface ITransactionLock
Parameters:
exclusive - true if the current thread needs exclusive access (i.e., no other threads may currently be yielding me); false, otherwise
Throws:
InterruptedException - in case of interrupt while waiting or if the user cancels the lock-acquisition job that is blocking the UI thread

yield

public boolean yield()
Description copied from interface: ITransactionLock
Temporarily yields the lock to another thread that does not require exclusive access, if any such thread exists. Note that, if this method returns true, then the caller must actually release me before another thread can take me. It then resumes by acquiring me again, layer.

Specified by:
yield in interface ITransactionLock
Returns:
true if the lock was successfully yielded to another thread; false, otherwise

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.