org.gcube.common.core.state
Class GCUBEReadWriteLock

java.lang.Object
  extended by java.util.concurrent.locks.ReentrantReadWriteLock
      extended by org.gcube.common.core.state.GCUBEReadWriteLock
All Implemented Interfaces:
Serializable, ReadWriteLock

public class GCUBEReadWriteLock
extends ReentrantReadWriteLock

An extension of ReentrantReadWriteLock that allows preemptive acquisition of write locks.

A thread acquires the write lock preemptively (cf. GCUBEReadWriteLock.GCUBEWriteLock.lockPreemptively()) if its actions preempt those of other threads that synchronise with it (e.g. removal of guarded state). When the preemptive thread releases the write lock, threads that were waiting for it or will request it in the future are immediately interrupted, unless the preemptive thread declares its own failure (cf. GCUBEReadWriteLock.GCUBEWriteLock.cancelPreemptive()).

The possibility of lock preemption implies that all locking operations are interruptible in principle. Accordingly, GCUBEReadWriteLock.GCUBEWriteLock.lock() and GCUBEReadWriteLock.GCUBEReadLock.lock() are deprecated in favour of GCUBEReadWriteLock.GCUBEWriteLock.lockInterruptibly() and GCUBEReadWriteLock.GCUBEReadLock.lockInterruptibly(). If used, they may throw a LockPreemptedException.

Author:
Fabio Simeoni (University of Strathclyde)
See Also:
Serialized Form

Nested Class Summary
static class GCUBEReadWriteLock.GCUBEReadLock
          An extension of ReentrantReadWriteLock.WriteLock that supports preemptive requests and acquisitions.
static class GCUBEReadWriteLock.GCUBEWriteLock
          An extension of ReentrantReadWriteLock.WriteLock that supports preemptive requests and acquisitions.
 
Nested classes/interfaces inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock
 
Field Summary
protected  GCUBELog logger
          Class logger.
protected  boolean preempted
          Indicates completion of preemptive task.
protected  Thread preemptingThread
          The thread that performs the preemptive task.
 
Constructor Summary
GCUBEReadWriteLock()
          Creates an instance.
GCUBEReadWriteLock(boolean fair)
          Creates an instance with a given fairness policy.
 
Method Summary
protected  boolean isPreempted()
          Used internally to check whether the lock has been requested preemptively by a thread other than the current one.
 GCUBEReadWriteLock.GCUBEReadLock readLock()
          
 void setLogger(GCUBELog logger)
          Sets the resource's logger.
 GCUBEReadWriteLock.GCUBEWriteLock writeLock()
          
 
Methods inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
getOwner, getQueuedReaderThreads, getQueuedThreads, getQueuedWriterThreads, getQueueLength, getReadHoldCount, getReadLockCount, getWaitingThreads, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected GCUBELog logger
Class logger.


preemptingThread

protected volatile Thread preemptingThread
The thread that performs the preemptive task.


preempted

protected volatile boolean preempted
Indicates completion of preemptive task.

Constructor Detail

GCUBEReadWriteLock

public GCUBEReadWriteLock()
Creates an instance.


GCUBEReadWriteLock

public GCUBEReadWriteLock(boolean fair)
Creates an instance with a given fairness policy.

Parameters:
fair - true if this lock should use a fair ordering policy
Method Detail

setLogger

public void setLogger(GCUBELog logger)
Sets the resource's logger.

Parameters:
logger - the logger.

writeLock

public GCUBEReadWriteLock.GCUBEWriteLock writeLock()

Specified by:
writeLock in interface ReadWriteLock
Overrides:
writeLock in class ReentrantReadWriteLock

readLock

public GCUBEReadWriteLock.GCUBEReadLock readLock()

Specified by:
readLock in interface ReadWriteLock
Overrides:
readLock in class ReentrantReadWriteLock

isPreempted

protected boolean isPreempted()
Used internally to check whether the lock has been requested preemptively by a thread other than the current one.

Throws:
LockPreemptedException - if the lock has been requested preemptively by a thread other than the current one.


Copyright © 2013. All Rights Reserved.